From e0e16b1e0d7ac45fdded132ce7c3844c8535dcfc Mon Sep 17 00:00:00 2001 From: Soispha Peetz Date: Thu, 29 Oct 2026 21:26:50 +0100 Subject: scripts/update_hosts.sh: Update to use `deploy-rs` --- scripts/update_hosts.remote | 48 ------------------------- scripts/update_hosts.sh | 87 ++++++++------------------------------------- 2 files changed, 15 insertions(+), 120 deletions(-) delete mode 100644 scripts/update_hosts.remote (limited to 'scripts') diff --git a/scripts/update_hosts.remote b/scripts/update_hosts.remote deleted file mode 100644 index 7385129..0000000 --- a/scripts/update_hosts.remote +++ /dev/null @@ -1,48 +0,0 @@ -#! /usr/bin/env sh - -# This is the remote side of `update_hosts.sh`, it will be copied to the remote host -# and is responsible for performing the update. - -set -e - -PATH_add() { - nix_expr="$1" - what="$(nix build "nixpkgs#$nix_expr.out" --print-out-paths --no-link)" - - printf "Adding '%s' (%s/bin) to PATH..\n" "$nix_expr" "$what" - - PATH="$what/bin:$PATH" - export PATH -} - -branch="$1" -flake_path="${2-""}" - -# We don't have access to git by default, so evaluate it here -PATH_add git - -# By-default these systems use cppnix, which can't build our config. So let's switch to -# lix. -PATH_add lixPackageSets.latest.lix - -# We might or might not have python, and we need it, because we use the unwrapped -# `nixos-update`. -PATH_add python3 -PATH_add nixos-rebuild - -if [ -z "$flake_path" ]; then - set -x - cd /etc/nixos - - sudo git fetch --all --prune - sudo git switch "$branch" - sudo git pull --rebase - - flake_path="git+file:/etc/nixos/" -fi - -# we use the unwrapped one, to make sure that we are really using lix (otherwise it might -# be wrapped with cppnix). -PYTHONNOUSERSITE='true' sudo --preserve-env=PATH --preserve-env=PYTHONNOUSERSITE ".nixos-rebuild-wrapped" --flake "$flake_path" --no-reexec boot - -sudo reboot diff --git a/scripts/update_hosts.sh b/scripts/update_hosts.sh index 5b84254..7d0d019 100755 --- a/scripts/update_hosts.sh +++ b/scripts/update_hosts.sh @@ -1,86 +1,29 @@ #! /usr/bin/env sh set -e -base_dir="$(git rev-parse --show-toplevel)" - -user="$USER" -set_hosts="" -branch="main" -direct=false - -while [ "$#" -ne 0 ]; do - case "$1" in - --user) - shift 1 - user="$1" - ;; - --host) - shift 1 - set_hosts="$set_hosts $1" - ;; - --hosts) - shift 1 - if [ -n "$set_hosts" ]; then - echo "Warning: --hosts overrides --host" - fi - set_hosts="$1" - ;; - --branch) - shift 1 - branch="$1" - ;; - --direct) - direct=true - ;; - *) - echo "Arg '$1' not known." - exit 2 - ;; - esac +check=true +if [ "$1" = "--no-check" ]; then + check=false shift 1 -done - -hosts="${set_hosts-"server2 server3"}" - -echo "update_hosts.sh --user '$user' --hosts '$hosts' --branch '$branch' --direct '$direct'" +fi -for host in $hosts; do - echo "Updating '$user@$host.vhack.eu' ..." +if [ "$#" -eq 0 ]; then + set -- server2 server3 +fi - printf "Deploying remote side script ..\n" - scp "$base_dir/scripts/update_hosts.remote" "$user@$host.vhack.eu:update_host.remote" +set -x - flake_path="" - if [ "$direct" = true ]; then - printf "Deploying git config ..\n" +[ "$check" = true ] && check.sh - flake_path="path:$(git archive --format=tar.gz HEAD | - ssh "$user@$host.vhack.eu" \ - 'flake_path=$(mktemp -d -t update_hosts_XXXXX); cd $flake_path && tar -xz; echo $flake_path')" - - fi - - tmp="$(mktemp -d -t "server_build_script_XXXXX")" - trap 'rm -rf "$tmp"' EXIT - if [ "$direct" = true ]; then - git archive --format=tar.gz HEAD | { - cd "$tmp" - tar -xz - } - else - git clone "$(git remote get-url origin)" --branch="$branch" "$tmp" - fi - cd "$tmp" - - printf "Copying closure ..\n" - nix copy --substitute-on-destination --to "ssh://$user@$host.vhack.eu" ".#nixosConfigurations.$host.config.system.build.toplevel" - - printf "Executing remote side script ..\n" - ssh -t "$user@$host.vhack.eu" "chmod +x update_host.remote; ./update_host.remote '$branch' '$flake_path'" +deploy --skip-checks --boot +for host in "$@"; do + ssh -t "$USER@$host" 'set -x; sudo reboot' done +set +x + # Give the servers some time to reboot sleep 5 -ping_hosts.sh "$user" "$hosts" +ping_hosts.sh "$USER" "$@" # vim: ft=sh -- cgit v1.3.1