#!/bin/sh set -eu usage() { cat <&2 usage >&2 exit 2 fi FILE="$(find . -name hostname.txt -exec grep -l "^$NAME$" {} \;)" if [ -z "$FILE" ]; then printf 'Unknown hostname "%s"\n' "$NAME" >&2 exit 2 fi DIR="$(dirname "$FILE")" cd "$DIR" . ./tf-env.sh terraform init terraform apply cd - > /dev/null TLD="$(cat "$DIR"/tld.txt)" DIRS='/opt /srv' # shellcheck disable=2029 ssh "$TLD" "\ sudo mkdir -p $DIRS && \ sudo chown $USER:users -R $DIRS && \ chmod -R 755 $DIRS " rsync -avzPL opt "$DIR/opt" "$TLD":/ if [ -f "$DIR"/machines.scm ]; then guix deploy "$DIR"/machines.scm elif [ -f "$DIR"/configuration.nix ]; then scp "$DIR"/configuration.nix "$TLD":/etc/nixos/ ssh "$TLD" sudo nixos-rebuild switch else printf 'Uknown deploy type for "%s"\n' "$NAME" >&2 exit 2 fi