Skip to content

Commit

Permalink
deploy.sh: If no host is given, deploy to localhost
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusauler committed Apr 13, 2024
1 parent ba90aad commit c2f4314
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ ADDRESSES=()
while [[ $# -gt 0 ]]; do
case $1 in
-h|--host)
(( $# <= 1 )) && missing_argument $1
(( $# <= 1 )) && missing_argument "$1"
HOSTS+=("${2//,/ }")
shift 2
;;

-a|--addr|--address)
(( $# <= 1 )) && missing_argument $1
(( $# <= 1 )) && missing_argument "$1"
ADDRESSES+=("${2//,/ }")
shift 2
;;
Expand All @@ -51,21 +51,31 @@ while [[ $# -gt 0 ]]; do
esac
done

(( ${#HOSTS[@]} <= 0 )) && error "No hosts were provided"

echo "${EXTRA_ARGS[@]}" | grep -qvwE "boot|switch|test" && error "Missing nixos-rebuild operation (boot, switch or test)"
flake_root=$(realpath "$(dirname "$0")")


function deploy_local
{
sudo nixos-rebuild --flake "$flake_root" "${EXTRA_ARGS[@]}"
}

function match_host_ip {
for host in ${HOSTS[@]}; do
function deploy_remote
{
for host in "${HOSTS[@]}"; do
addr="$host"

if (( $# > 0 )); then
addr="$1"
shift
fi

nixos-rebuild --flake $(realpath $(dirname "$0"))\#"$host" --target-host "$addr" --use-remote-sudo ${EXTRA_ARGS[@]}
nixos-rebuild --flake "$flake_root#$host" --target-host "$addr" --use-remote-sudo "${EXTRA_ARGS[@]}"
done
}

match_host_ip ${ADDRESSES[@]}
if (( ${#HOSTS[@]} <= 0 )); then
deploy_local
else
deploy_remote "${ADDRESSES[@]}"
fi

0 comments on commit c2f4314

Please sign in to comment.