xin/bin/deploy

96 lines
2.4 KiB
Plaintext
Raw Permalink Normal View History

2022-08-25 12:21:35 -06:00
#!/usr/bin/env sh
. ./common.sh
trap error INT TERM
2022-09-03 06:35:01 -06:00
start
2022-08-25 12:21:35 -06:00
rebuild() {
host="$(resolveAlias $1)"
skip_check=$2
build_host=${BUILD_HOST:-$host}
2024-10-01 08:00:59 -06:00
msg "Rebuilding: ${host} using ${build_host}"
nixos-rebuild ${TRACE} --flake .#${1} --build-host "root@${build_host}" --target-host "root@${host}" switch 2>&1 | nom
2022-08-25 12:21:35 -06:00
return $?
}
2023-05-23 12:05:33 -06:00
if [ "$1" = "watch" ]; then
2023-06-21 07:01:54 -06:00
if [ "$2" = "status" ]; then
for f in pull_requests/*.json; do
pr=$(basename $f .json)
title="$(jq -r '.title' <$f)"
status="$(jq -r '.status' <$f)"
echo "${pr}|${title}|${status}"
done | column -t -s '|'
exit 0
fi
2023-05-23 12:05:33 -06:00
if [ "$2" = "update" ]; then
msg "updating watches..."
for f in pull_requests/*.json; do
pr=$(basename $f .json)
if [ "$(jq -r '.status' <$f)" = "open" ]; then
2023-09-25 14:36:25 -06:00
curl -s -o - https://pr-status.otter-alligator.ts.net/${pr} | jq -rS 'del(.queryTime)' >pull_requests/${pr}.json
msg "Updated watch for ${pr}: $(jq -r .title <pull_requests/${pr}.json)"
else
msg "$Skipping: ${pr} ($(jq -r .title <pull_requests/${pr}.json)), already complete"
fi
2023-05-23 12:05:33 -06:00
done
else
pr="$2"
2023-09-25 14:36:25 -06:00
curl -s -o - https://pr-status.otter-alligator.ts.net/${pr} | jq -rS 'del(.queryTime)' >pull_requests/${pr}.json
2023-05-23 12:05:33 -06:00
msg "Added watch for ${pr}: $(jq -r .title <pull_requests/${pr}.json)"
git add pull_requests/${pr}.json
2023-05-23 12:05:33 -06:00
fi
exit 0
fi
2022-10-16 07:06:11 -06:00
if [ "$1" = "local" ]; then
sudo nixos-rebuild ${TRACE} --option eval-cache false --flake .#$(uname -n) switch 2>&1 | nom
2022-10-16 07:06:11 -06:00
exit $?
fi
2022-08-25 12:21:35 -06:00
if [ "$1" = "update" ]; then
single="$2"
2022-08-25 12:21:35 -06:00
can_sign=0
for i in $(ssh-add -L | awk '{print $2}'); do
2022-08-25 12:21:35 -06:00
grep -q $i .allowed_signers && can_sign=1
done
2022-10-16 06:31:15 -06:00
# TODO: capture commit message and wrap it with what is being updated.
2024-10-01 08:00:59 -06:00
if [ $can_sign != 1 ]; then
2022-08-25 12:21:35 -06:00
echo "Can't find signing key."
exit 1
fi
2024-10-01 08:00:59 -06:00
if [ "$single" != "" ]; then
nix flake update --commit-lock-file "$single"
else
nix flake update --commit-lock-file
fi
nix flake archive
2024-10-31 08:20:57 -06:00
exit $?
2022-08-25 12:21:35 -06:00
fi
if [ "$1" = "diff" ]; then
host="$(resolveAlias $2)"
mkdir -p .gcroots
out=$(nix build -o .gcroots/${host} --json .#nixosConfigurations.${2}.config.system.build.toplevel | jq -r '.[0].outputs.out')
nix copy -s --to "ssh://root@$host" "$out"
nix copy -s --derivation --to "ssh://root@$host" "$out"
${SSH} "root@$host" "nix-store -qd /run/current-system $out | xargs nix-diff --color=always" | less
exit $?
fi
ret=0
if [ ${#@} = 1 ]; then
rebuild $1 true || ret=1
else
2023-02-02 15:24:22 -07:00
lock
2022-10-05 07:33:13 -06:00
for host in $(listNixOSHosts); do
2022-08-25 12:21:35 -06:00
rebuild $host false || ret=1
done
fi