34 lines
600 B
Bash
34 lines
600 B
Bash
|
#!/usr/bin/env bash
|
||
|
|
||
|
# Parameters
|
||
|
ip=$1
|
||
|
host=$2
|
||
|
if [ -z "$ip" ] || [ -z "$host" ]; then
|
||
|
echo "Usage: $0 <ip> <host>"
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
# This script is used to bootstrap nixos machine so I can get their ssh keys
|
||
|
|
||
|
nixos-rebuild boot \
|
||
|
--flake ".#$host" \
|
||
|
--fast \
|
||
|
--target-host krop@$ip \
|
||
|
--build-host krop@$ip \
|
||
|
--use-remote-sudo
|
||
|
|
||
|
ret=$?
|
||
|
if [ $ret -ne 0 ]; then
|
||
|
echo "Failed to install $host"
|
||
|
exit $ret
|
||
|
fi
|
||
|
|
||
|
echo "Successfully installed $host, rebooting"
|
||
|
|
||
|
ssh -t krop@$ip "sudo reboot now"
|
||
|
|
||
|
ret=$?
|
||
|
if [ $ret -ne 0 ]; then
|
||
|
echo "Failed to reboot $host"
|
||
|
exit $ret
|
||
|
fi
|