aboutsummaryrefslogtreecommitdiff
path: root/upgrade.sh
blob: 8ed27632ccc0752d05a72e12c3c5e81f26a996b0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env bash

cd $(dirname $0)

if [ -z "$@" ]; then
	NIXHOSTLIST=$(ls node | grep -v '\.site\.')
else
	NIXHOSTLIST="$@"
fi

TMP_SCRIPT=/tmp/tmp-upgrade-$(date +%s).sh

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 ===="

	ssh -F ssh_config $SSH_DEST tee $TMP_SCRIPT > /dev/null <<EOF
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)..."
	ssh -t -F ssh_config $SSH_DEST sudo sh $TMP_SCRIPT
	ssh -F ssh_config $SSH_DEST rm -v $TMP_SCRIPT

	read -p "Press Enter to continue (reboot $NIXHOST)..."
	ssh -t -F ssh_config $SSH_DEST sudo reboot
done