scripts/deploy: add a --reboot option

This commit is contained in:
Colin 2024-06-19 20:31:43 +00:00
parent 4f4c05a922
commit 8ca357ea7f

View File

@ -10,8 +10,9 @@ usage() {
echo "options:"
echo "- --action copy|switch|test (default: 'switch')"
echo "- --dry-run: show what would be done without actually doing it"
echo "- --variant light|min|''|all (default: '')"
echo "- --pre: alias for --action copy --variant all all"
echo "- --reboot: reboot the target machine after deploying (whether deployment was 'successful' or not)"
echo "- --variant light|min|''|all (default: '')"
echo ""
echo "common idioms:"
echo "- deploy all: deploy all hosts, sequentially"
@ -31,6 +32,7 @@ defaultHost="$SELF"
variants=()
defaultVariant=
nixArgs=()
doReboot=
dryRun=
addHost() {
if [ "$1" = all ]; then
@ -59,9 +61,20 @@ parseArgs() {
action=$1
shift
;;
(--dry-run)
dryRun=1
;;
(--help)
usage
;;
(--pre)
action=copy
defaultVariant=all
defaultHost=all
;;
(--reboot)
doReboot=1
;;
(--variant)
addVariant "$1"
shift
@ -69,14 +82,6 @@ parseArgs() {
(all|crappy|desko|lappy|moby|servo)
addHost "$arg"
;;
(--pre)
action=copy
defaultVariant=all
defaultHost=all
;;
(--dry-run)
dryRun=1
;;
(*)
nixArgs+=("$arg")
;;
@ -100,13 +105,14 @@ destructive() {
}
runOnTarget() {
local host="$1"
# run the command ($@) on the machine we're deploying to.
# if that's a remote machine, then do it via ssh, else local shell.
if [ -n "$host" ] && [ "$host" != "$SELF" ]; then
info "running on remote:" "$@"
info "running on remote ($host):" "$@"
ssh "$host" "$@"
else
info "running locally:" "$@"
info "running locally ($SELF):" "$@"
"$@"
fi
}
@ -145,8 +151,12 @@ deployOneHost() {
if [ -n "$action" ] && [ "$action" != "copy" ]; then
info "activating profile... "
destructive runOnTarget sudo nix-env -p /nix/var/nix/profiles/system --set "$storePath" || return 1
destructive runOnTarget sudo "$storePath/bin/switch-to-configuration" "$action" || return 1
destructive runOnTarget "$host" sudo nix-env -p /nix/var/nix/profiles/system --set "$storePath" || return 1
destructive runOnTarget "$host" sudo "$storePath/bin/switch-to-configuration" "$action" || return 1
if [ -n "$doReboot" ]; then
info "rebooting $host"
destructive runOnTarget "$host" sane-reboot
fi
fi
}