#!/bin/bash usage() { cat <=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 i) identityFile="${OPTARG}" ;; d) domain="${OPTARG}" ;; r) reboot=true ;; b) boot=true ;; h) usage exit 0 ;; \?) usage >&2 exit 64 ;; esac done shift $((OPTIND - 1)) if [ -z "${identityFile}" ]; then echo "missing option: -i is required" >&2 usage >&2 exit 64 fi if [ -z "$(type -P 'scp')" ] || [ -z "$(type -P 'ssh')" ]; then echo "missing dependency: scp or ssh not found in \$PATH" >&2 exit 64 fi if [ -z "${domain}" ]; then dialog else host="${domain}" fi echo "$(tput bold)Copying configuration to ${host}...$(tput sgr0)" scp -i "${identityFile}" ./configuration.nix root@"${host}":/etc/nixos/configuration.nix 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" fi if [ "${reboot}" = true ]; then echo "$(tput bold)Rebooting system...$(tput sgr0)" ssh -i "${identityFile}" root@"${host}" "systemctl reboot" fi