2021-12-04 20:02:42 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2022-02-09 11:09:49 +00:00
|
|
|
# Get cluster subdirectory name
|
|
|
|
|
2021-12-04 20:02:42 +00:00
|
|
|
cd $(dirname $0)
|
|
|
|
|
2022-02-09 11:09:49 +00:00
|
|
|
CLUSTER="$1"
|
|
|
|
if [ -z "$CLUSTER" ] || [ ! -d "cluster/$CLUSTER" ]; then
|
|
|
|
echo "Usage: $0 <cluster name>"
|
|
|
|
echo "The cluster name must be the name of a subdirectory of cluster/"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
shift 1
|
|
|
|
|
|
|
|
# Do actual stuff
|
|
|
|
|
2021-12-04 20:02:42 +00:00
|
|
|
if [ -z "$@" ]; then
|
2022-02-09 11:09:49 +00:00
|
|
|
NIXHOSTLIST=$(ls cluster/$CLUSTER/node | grep -v '\.site\.')
|
2021-12-04 20:02:42 +00:00
|
|
|
else
|
|
|
|
NIXHOSTLIST="$@"
|
|
|
|
fi
|
|
|
|
|
2021-12-30 17:09:20 +00:00
|
|
|
TMP_SCRIPT=/tmp/tmp-upgrade-$(date +%s).sh
|
2022-02-09 11:09:49 +00:00
|
|
|
SSH_CONFIG=cluster/$CLUSTER/ssh_config
|
2021-12-30 17:09:20 +00:00
|
|
|
|
2021-12-04 20:02:42 +00:00
|
|
|
for NIXHOST in $NIXHOSTLIST; do
|
|
|
|
NIXHOST=${NIXHOST%.*}
|
|
|
|
|
|
|
|
if [ -z "$SSH_USER" ]; then
|
|
|
|
SSH_DEST=$NIXHOST
|
|
|
|
else
|
|
|
|
SSH_DEST=$SSH_USER@$NIXHOST
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "==== DOING $NIXHOST ===="
|
|
|
|
|
2022-02-09 11:09:49 +00:00
|
|
|
ssh -F $SSH_CONFIG $SSH_DEST tee $TMP_SCRIPT > /dev/null <<EOF
|
2021-12-30 17:09:20 +00:00
|
|
|
set -ex
|
|
|
|
|
|
|
|
nix-channel --add https://nixos.org/channels/nixos-21.11 nixos
|
|
|
|
nix-channel --update
|
|
|
|
nixos-rebuild boot
|
|
|
|
EOF
|
|
|
|
|
|
|
|
read -p "Press Enter to continue (run upgrade on $NIXHOST)..."
|
2022-02-09 11:09:49 +00:00
|
|
|
ssh -t -F $SSH_CONFIG $SSH_DEST sudo sh $TMP_SCRIPT
|
|
|
|
ssh -F $SSH_CONFIG $SSH_DEST rm -v $TMP_SCRIPT
|
2021-12-26 12:23:01 +00:00
|
|
|
|
2021-12-30 17:09:20 +00:00
|
|
|
read -p "Press Enter to continue (reboot $NIXHOST)..."
|
2022-02-09 11:09:49 +00:00
|
|
|
ssh -t -F $SSH_CONFIG $SSH_DEST sudo reboot
|
2021-12-04 20:02:42 +00:00
|
|
|
done
|