2022-08-31 14:12:09 -06:00
|
|
|
NIX_SSHOPTS="-i /run/secrets/manager_pubkey -oIdentitiesOnly=yes -oControlPath=/tmp/manager-ssh-%r@%h:%p -F/dev/null"
|
2022-08-25 12:21:35 -06:00
|
|
|
SSH="ssh ${NIX_SSHOPTS}"
|
|
|
|
CurrentVersion="$(git rev-parse HEAD)"
|
|
|
|
AgentKeys="$(ssh-add -L | awk '{print $2}')"
|
|
|
|
RunHost="$(uname -n)"
|
|
|
|
|
|
|
|
msg() {
|
2022-08-28 09:17:55 -06:00
|
|
|
echo -e "===> $@"
|
2022-08-25 12:21:35 -06:00
|
|
|
}
|
|
|
|
|
2022-10-05 07:33:13 -06:00
|
|
|
listNixOSHosts() {
|
|
|
|
for i in $(nix eval .#nixosConfigurations --apply builtins.attrNames --json | jq -r '.[]'); do
|
|
|
|
if [ -d hosts/${i} ]; then
|
|
|
|
echo $i
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2022-08-25 12:21:35 -06:00
|
|
|
resolveAlias() {
|
|
|
|
host="${1}"
|
|
|
|
if [ -f hosts/${host}/alias ]; then
|
|
|
|
cat "hosts/${host}/alias"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
echo "$host"
|
|
|
|
}
|
|
|
|
|
|
|
|
agentHasKey() {
|
|
|
|
checkKey="$(echo $1 | awk '{print $NF}')"
|
|
|
|
for i in $AgentKeys; do
|
|
|
|
if [[ "$i" == $checkKey ]]; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
isRunHost() {
|
|
|
|
if [ "$1" = "$RunHost" ]; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
tsAlive() {
|
|
|
|
ping -c 1 -w 2 $1 >/dev/null 2>&1 && return 0
|
|
|
|
tailscale ping --timeout 2s --c 1 --until-direct=false $1 >/dev/null 2>&1 && return 0
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
error() {
|
|
|
|
msg "Something went wrong!"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
start() {
|
2022-10-10 06:49:27 -06:00
|
|
|
agentHasKey "$(cat /run/secrets/manager_pubkey | awk '{print $2}')" ||
|
2022-08-25 12:21:35 -06:00
|
|
|
ssh-add /run/secrets/manager_key
|
|
|
|
}
|
|
|
|
|
|
|
|
finish() {
|
|
|
|
ssh-add -d /run/secrets/manager_key
|
|
|
|
exit 0
|
|
|
|
}
|