aboutsummaryrefslogtreecommitdiff
path: root/upgrade.sh
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2022-02-09 12:09:49 +0100
committerAlex Auvolat <alex@adnab.me>2022-02-09 12:09:49 +0100
commitf03cafd49b48eabc4743b3a3791fd22f19cb0de1 (patch)
treee31d1c68502e4ee2f8f4dc67235eac0e220b2fbd /upgrade.sh
parentcce5cd17f5429295eb2165480ca941dd3f49b788 (diff)
downloadnixcfg-f03cafd49b48eabc4743b3a3791fd22f19cb0de1.tar.gz
nixcfg-f03cafd49b48eabc4743b3a3791fd22f19cb0de1.zip
Modularize and prepare to support multiple clusters
Diffstat (limited to 'upgrade.sh')
-rwxr-xr-xupgrade.sh23
1 files changed, 18 insertions, 5 deletions
diff --git a/upgrade.sh b/upgrade.sh
index 8ed2763..cb45924 100755
--- a/upgrade.sh
+++ b/upgrade.sh
@@ -1,14 +1,27 @@
#!/usr/bin/env bash
+# Get cluster subdirectory name
+
cd $(dirname $0)
+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
+
if [ -z "$@" ]; then
- NIXHOSTLIST=$(ls node | grep -v '\.site\.')
+ NIXHOSTLIST=$(ls cluster/$CLUSTER/node | grep -v '\.site\.')
else
NIXHOSTLIST="$@"
fi
TMP_SCRIPT=/tmp/tmp-upgrade-$(date +%s).sh
+SSH_CONFIG=cluster/$CLUSTER/ssh_config
for NIXHOST in $NIXHOSTLIST; do
NIXHOST=${NIXHOST%.*}
@@ -21,7 +34,7 @@ for NIXHOST in $NIXHOSTLIST; do
echo "==== DOING $NIXHOST ===="
- ssh -F ssh_config $SSH_DEST tee $TMP_SCRIPT > /dev/null <<EOF
+ 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
@@ -30,9 +43,9 @@ 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
+ 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
+ ssh -t -F $SSH_CONFIG $SSH_DEST sudo reboot
done