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