aboutsummaryrefslogtreecommitdiff
path: root/scripts/deploy
blob: 1b378883c2693abf19a0359b1f7653ad1090152d (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
28
29
30
31
32
33
34
35
36
37
38
#!/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")"

terraform apply "$DIR"

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 "$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 OS type of "%s"\n' "$NAME" >&2
	exit 2
fi