aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/update_hosts.sh
blob: cc459edfa5f1f9597a23b5db10220ef647a9531c (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
#! /usr/bin/env sh
set -e

base_dir="$(git rev-parse --show-toplevel)"

user="${1-$USER}"
hosts="${2-server2 server3}"
branch="${3-main}"

for host in $hosts; do
    echo "Updating '$user@$host.vhack.eu' ..."

    printf "Copying closure ..\n"
    nix copy --substitute-on-destination --to "ssh://$user@$host.vhack.eu" ".#nixosConfigurations.$host.config.system.build.toplevel"

    printf "Deploying remote side script ..\n"
    scp "$base_dir/scripts/update_hosts.remote" "$user@$host.vhack.eu:update_host.remote"

    printf "Executing remote side script ..\n"
    ssh -t "$user@$host.vhack.eu" "chmod +x update_host.remote; ./update_host.remote '$branch'"
done

# Give the servers some time to reboot
sleep 5
ping_hosts.sh

# vim: ft=sh