aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xscripts/deploy44
1 files changed, 44 insertions, 0 deletions
diff --git a/scripts/deploy b/scripts/deploy
new file mode 100755
index 0000000..f529d03
--- /dev/null
+++ b/scripts/deploy
@@ -0,0 +1,44 @@
+#!/bin/sh
+set -eu
+
+NAME="${1:-}"
+if [ -z "$NAME" ]; then
+ printf 'Missing hostname\n' >&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")"
+
+if [ -f "$DIR"/machines.scm ]; then
+ OS=guix
+elif [ -f "$DIR"/configuration.nix ]; then
+ OS=nix
+else
+ printf 'Uknown OS type of "%s"\n' "$NAME" >&2
+ exit 2
+fi
+
+# FIXME
+# terraform apply "$DIR"
+
+TLD="$(cat "$DIR"/tld.txt)"
+DIRS='/opt /srv'
+ssh "$TLD" "\
+sudo mkdir -p $DIRS && \
+sudo chown $USER:users -R $DIRS && \
+chmod -R 755 $DIRS"
+
+rsync -avzP opt "$TLD":/
+
+if [ "$OS" = 'guix' ]; then
+ guix deploy "$DIR"/machines.scm
+elif [ "$OS" = 'nix' ]; then
+ scp "$DIR"/configuration.nix "$TLD":/etc/nixos/
+ ssh "$TLD" sudo nixos-rebuild switch
+fi