Refactor deploy script

This commit is contained in:
Tim Schubert 2021-01-16 19:03:27 +01:00
parent 9a5f573be1
commit 439e5c6953
Signed by: dadada
GPG key ID: EEB8D1CE62C4DFEA
2 changed files with 21 additions and 12 deletions

14
utils/deploy Executable file
View file

@ -0,0 +1,14 @@
#!/usr/bin/env bash
set -e
set -o pipefail
if [ -z "$1" ]
then
echo "usage: deploy <hostname>"
exit 1
fi
git push
gen-config $1 | ssh "${host}".dadada.li 'sudo cat - > /etc/nixos/configuration.nix && (nixos-rebuild test && nixos-rebuild switch) || (nixos-rebuild switch --rollback && exit 1)'

View file

@ -1,16 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -e
set -o pipefail
if [ -z "$1" ]
then
echo "usage: deploy <hostname>"
exit 1
fi
git push
function hash { function hash {
archive="$(mktemp /tmp/nix-config.XXX.tar.gz)" archive="$(mktemp /tmp/nix-config.XXX.tar.gz)"
git archive "$1" | gzip > "$archive" git archive "$1" | gzip > "$archive"
@ -18,11 +7,17 @@ function hash {
rm "$archive" rm "$archive"
} }
if [ -z "$1" ]
then
echo "usage: deploy <hostname>"
exit 1
fi
host="${1}" host="${1}"
rev="$(git rev-parse HEAD)" rev="$(git rev-parse HEAD)"
sha256=$(hash "$rev") sha256=$(hash "$rev")
cat <<EOF | ssh "${host}".dadada.li 'sudo cat - > /etc/nixos/configuration.nix && (nixos-rebuild test && nixos-rebuild switch) || (nixos-rebuild switch --rollback && exit 1)' cat <<EOF
{ config, pkgs, ... }: { config, pkgs, ... }:
let let
host = "$host"; host = "$host";