nixos-config/quick-switch.sh

36 lines
775 B
Bash
Raw Normal View History

2023-06-16 23:32:12 +00:00
#!/usr/bin/env bash
2023-06-17 17:51:24 +00:00
set -euo pipefail
2023-06-16 23:32:12 +00:00
2024-07-26 22:29:28 +00:00
# Stolen from https://stackoverflow.com/a/29436423
2024-07-26 22:27:47 +00:00
function yes_or_no {
while true; do
read -p "$* [y/n]: " yn
case $yn in
[Yy]*) return 0 ;;
[Nn]*) echo "Aborted" ; return 1 ;;
esac
done
}
function apply() {
2023-06-16 23:56:23 +00:00
git push --force-with-lease
2023-06-17 17:51:24 +00:00
rev=$(git rev-parse HEAD)
2023-06-17 00:30:33 +00:00
sudo nixos-rebuild switch \
2024-02-04 19:17:33 +00:00
--flake "git+https://git.atauno.com/atau/nixos-config.git?ref=main&rev=$rev"
2024-07-26 22:27:47 +00:00
}
function commit_and_apply() {
read -p "Enter a commit message: " msg
git add .
git commit -m "$(hostname): $msg"
apply
}
if [ -z "$(git status --porcelain)" ]
then
apply
2023-06-16 23:32:12 +00:00
else
2024-07-26 22:27:47 +00:00
yes_or_no "Git working directory is unclean, would you like to commit changes?" && commit_and_apply
2023-06-16 23:32:12 +00:00
fi