nixos/scripts/remote_switch.sh

47 lines
1.1 KiB
Bash
Raw Normal View History

2022-01-31 12:42:56 +01:00
#!/usr/bin/env bash
cd /home/andreas/.nixos
hosts=($(echo `nix eval .#nixosConfigurations --apply 'pkgs: builtins.concatStringsSep " " (builtins.attrNames pkgs)'` | xargs ))
skip=(
2022-11-03 11:33:58 +01:00
"desktop-vm"
"gwyn"
"loki-test"
"pihole"
2022-11-03 11:33:41 +01:00
"staubfinger"
2022-01-31 12:42:56 +01:00
)
2022-01-31 15:45:25 +01:00
rsa_key="$HOME/.nixos/secrets/ssh_keys/ansible/ansible.key"
export NIX_SSHOPTS="-t -i $rsa_key"
2022-11-12 15:28:35 +01:00
reboot=0
while getopts ":r" option; do
case $option in
r)
reboot=1
esac
done
2022-01-31 12:42:56 +01:00
2022-01-31 15:45:25 +01:00
for host in "${hosts[@]}"
do
# Check if the host is in the skip list
if [[ " ${skip[*]} " =~ " ${host} " ]];then
continue
fi
2022-01-31 12:42:56 +01:00
fqdn="$host.2li.local"
echo $fqdn
nixos-rebuild switch -j auto --use-remote-sudo --build-host localhost --target-host $fqdn --flake ".#$host" &&
2022-11-12 15:28:35 +01:00
if [ $reboot -eq 1 ]; then
ssh -i $rsa_key $fqdn 'sudo reboot'
fi
2022-05-20 13:29:35 +02:00
echo
echo
done
2022-11-04 16:35:14 +01:00
pihole="pihole.2li.local"
echo $pihole
nixos-rebuild switch -j auto --use-remote-sudo --build-host localhost --target-host $pihole --flake ".#pihole" &&
2022-11-12 15:28:35 +01:00
if [ $reboot -eq 1 ]; then
ssh -i $rsa_key $pihole 'sudo reboot'
fi