feat(packages/rebuild): add prompt for commit and reboot, skip generation check option
This commit is contained in:
parent
e0887268bd
commit
8ea093d939
1 changed files with 27 additions and 17 deletions
|
@ -1,13 +1,25 @@
|
||||||
{ pkgs, ... }:
|
{ pkgs, ... }:
|
||||||
pkgs.writeShellScriptBin "rebuild" # sh
|
pkgs.writeShellScriptBin "rebuild" # sh
|
||||||
''
|
''
|
||||||
|
prompt() {
|
||||||
|
local PROMPT="$1"
|
||||||
|
shift
|
||||||
|
read -p "$PROMPT? (y/n) [n]: " -n 1 -r REPLY
|
||||||
|
echo
|
||||||
|
if [[ "$REPLY" =~ ^[Yy]$ ]]; then
|
||||||
|
"$*"
|
||||||
|
else
|
||||||
|
echo "$PROMPT aborted."
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
if [ ! -f "flake.nix" ]; then
|
if [ ! -f "flake.nix" ]; then
|
||||||
echo "Error: flake.nix not found in the current directory. Exiting."
|
echo "Error: flake.nix not found in the current directory. Exiting."
|
||||||
exit 1 # Indicate an error
|
exit 1 # Indicate an error
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#TODO: get hostnames from flake nixosConfigurations
|
#TODO: get hostnames from flake nixosConfigurations
|
||||||
|
|
||||||
|
NO_GENERATION_CHECK=false
|
||||||
TEST_SHELL=false
|
TEST_SHELL=false
|
||||||
REMOTE_HOSTS=()
|
REMOTE_HOSTS=()
|
||||||
ALL_HOSTS=("nemesis" "mellinoe" "apollo")
|
ALL_HOSTS=("nemesis" "mellinoe" "apollo")
|
||||||
|
@ -17,6 +29,10 @@ pkgs.writeShellScriptBin "rebuild" # sh
|
||||||
|
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
|
--no-generation-check | -n)
|
||||||
|
NO_GENERATION_CHECK=true
|
||||||
|
shift
|
||||||
|
;;
|
||||||
--test-shell | -t)
|
--test-shell | -t)
|
||||||
TEST_SHELL=true
|
TEST_SHELL=true
|
||||||
shift
|
shift
|
||||||
|
@ -76,22 +92,16 @@ pkgs.writeShellScriptBin "rebuild" # sh
|
||||||
}
|
}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
NEW_GENERATION=$(readlink /nix/var/nix/profiles/system | cut -d- -f2)
|
if ! "$NO_GENERATION_CHECK"; then
|
||||||
echo "New generation is $NEW_GENERATION. Current is $CURRENT_GENERATION."
|
NEW_GENERATION=$(readlink /nix/var/nix/profiles/system | cut -d- -f2)
|
||||||
if [ ! $NEW_GENERATION -gt $CURRENT_GENERATION ]; then
|
echo "New generation is $NEW_GENERATION. Current is $CURRENT_GENERATION."
|
||||||
echo "ERROR: New config was not added to bootloader. Exiting..."
|
if [ ! $NEW_GENERATION -gt $CURRENT_GENERATION ]; then
|
||||||
exit 1
|
echo "ERROR: New config was not added to bootloader. Exiting..."
|
||||||
else
|
exit 1
|
||||||
git commit
|
|
||||||
|
|
||||||
read -p "Reboot the system now? (y/n) [n]: " -n 1 -r
|
|
||||||
echo # (optional) move to a new line
|
|
||||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
|
||||||
echo "Rebooting the system..."
|
|
||||||
sudo systemctl reboot
|
|
||||||
else
|
|
||||||
echo "Not rebooting."
|
|
||||||
exit 0
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
prompt "Commit changes" commit
|
||||||
|
prompt "Reboot system" sudo systemctl reboot
|
||||||
|
exit 0
|
||||||
''
|
''
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue