add reboot, switch on boot and domain options
This commit is contained in:
12
README.md
12
README.md
@@ -8,6 +8,18 @@ To change the resulting system, edit the *configuration.nix* and re-run the scri
|
|||||||
|
|
||||||
### Usage
|
### Usage
|
||||||
```
|
```
|
||||||
|
Usage:
|
||||||
|
ec2-build-container-host [OPTION...]
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-h Print this help
|
||||||
|
-i Path to SSH identity file
|
||||||
|
-d Domain or IP to EC2 instance
|
||||||
|
-r Reboot after building the system
|
||||||
|
-b Switch to new system on next boot
|
||||||
|
|
||||||
|
```
|
||||||
|
```
|
||||||
git clone https://github.com/mrckndt/ec2-build-container-host
|
git clone https://github.com/mrckndt/ec2-build-container-host
|
||||||
cd ec2-build-container-host
|
cd ec2-build-container-host
|
||||||
|
|
||||||
|
|||||||
@@ -133,6 +133,11 @@ in
|
|||||||
enable = true;
|
enable = true;
|
||||||
theme = "gentoo";
|
theme = "gentoo";
|
||||||
};
|
};
|
||||||
|
shellAliases = {
|
||||||
|
":q" = "exit";
|
||||||
|
".." = "cd ..";
|
||||||
|
"grep" = "grep --color=auto";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -8,15 +8,38 @@ Usage:
|
|||||||
Options:
|
Options:
|
||||||
-h Print this help
|
-h Print this help
|
||||||
-i Path to SSH identity file
|
-i Path to SSH identity file
|
||||||
|
-d Domain or IP to EC2 instance
|
||||||
|
-r Reboot after building the system
|
||||||
|
-b Switch to new system on next boot
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
while getopts i:h opt; do
|
dialog() {
|
||||||
|
echo "Please open $(tput bold)https://nixos.org/download#nixos-amazon$(tput sgr0) and follow the
|
||||||
|
instructions to launch an EC2 instance.
|
||||||
|
|
||||||
|
$(tput bold)Note: it's recommended to use a disk size of >=20GB.$(tput sgr0)"
|
||||||
|
echo
|
||||||
|
|
||||||
|
read -r -p "Domain or IP of launched EC2 instance: " host
|
||||||
|
echo
|
||||||
|
}
|
||||||
|
|
||||||
|
while getopts d:i:hrb opt; do
|
||||||
case "$opt" in
|
case "$opt" in
|
||||||
i)
|
i)
|
||||||
identityFile="${OPTARG}"
|
identityFile="${OPTARG}"
|
||||||
;;
|
;;
|
||||||
|
d)
|
||||||
|
domain="${OPTARG}"
|
||||||
|
;;
|
||||||
|
r)
|
||||||
|
reboot=true
|
||||||
|
;;
|
||||||
|
b)
|
||||||
|
boot=true
|
||||||
|
;;
|
||||||
h)
|
h)
|
||||||
usage
|
usage
|
||||||
exit 0
|
exit 0
|
||||||
@@ -30,28 +53,34 @@ done
|
|||||||
|
|
||||||
shift $((OPTIND - 1))
|
shift $((OPTIND - 1))
|
||||||
|
|
||||||
if [ -z ${identityFile} ]; then
|
if [ -z "${identityFile}" ]; then
|
||||||
echo "missing option: -i is required" >&2
|
echo "missing option: -i is required" >&2
|
||||||
usage >&2
|
usage >&2
|
||||||
exit 64
|
exit 64
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z $(type -P "scp") ] || [ -z $(type -P "ssh") ]; then
|
if [ -z "$(type -P 'scp')" ] || [ -z "$(type -P 'ssh')" ]; then
|
||||||
echo "SSH needs to be installed" >&2
|
echo "missing dependency: scp or ssh not found in \$PATH" >&2
|
||||||
exit 64
|
exit 64
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Please open $(tput bold)https://nixos.org/download#nixos-amazon$(tput sgr0) and follow the
|
if [ -z "${domain}" ]; then
|
||||||
instructions to launch an EC2 instance.
|
dialog
|
||||||
|
else
|
||||||
|
host="${domain}"
|
||||||
|
fi
|
||||||
|
|
||||||
$(tput bold)Note: it's recommended to use a disk size of >=20GB.$(tput sgr0)"
|
|
||||||
echo
|
|
||||||
|
|
||||||
read -p "Domain or IP of launched EC2 instance: " host
|
|
||||||
|
|
||||||
echo
|
|
||||||
echo "$(tput bold)Copying configuration to ${host}...$(tput sgr0)"
|
echo "$(tput bold)Copying configuration to ${host}...$(tput sgr0)"
|
||||||
scp -i "${identityFile}" ./configuration.nix root@"${host}":/etc/nixos/configuration.nix
|
scp -i "${identityFile}" ./configuration.nix root@"${host}":/etc/nixos/configuration.nix
|
||||||
|
|
||||||
echo "$(tput bold)Building system...$(tput sgr0)"
|
echo "$(tput bold)Building system...$(tput sgr0)"
|
||||||
|
if [ "${boot}" = true ]; then
|
||||||
|
ssh -i "${identityFile}" root@"${host}" "nixos-rebuild boot --upgrade"
|
||||||
|
else
|
||||||
ssh -i "${identityFile}" root@"${host}" "nixos-rebuild switch --upgrade"
|
ssh -i "${identityFile}" root@"${host}" "nixos-rebuild switch --upgrade"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "${reboot}" = true ]; then
|
||||||
|
echo "$(tput bold)Rebooting system...$(tput sgr0)"
|
||||||
|
ssh -i "${identityFile}" root@"${host}" "systemctl reboot"
|
||||||
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user