#!/usr/bin/env bash set -euo pipefail [[ "$#" -eq 9 ]] || { echo "usage: deploy-toad.sh HOST PORT PUBLIC_PROXY_USER QUADLETS ENROLLMENT GATEWAY_CONFIG INGRESS_ENV THEME_CSS CONTEXT" >&2 exit 2 } host="$1" port="$2" public_proxy_user="$3" quadlets="$4" enrollment="$5" gateway_config="$6" ingress_env="$7" theme_css="$8" context="$9" repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" [[ "${public_proxy_user}" =~ ^[a-z_][a-z0-9_-]*$ ]] || { echo "invalid public proxy user" >&2 exit 2 } [[ -d "${quadlets}" && -f "${enrollment}" && -f "${gateway_config}" && -f "${ingress_env}" && -f "${theme_css}" && -d "${context}" ]] || { echo "invalid toad deployment input" >&2 exit 2 } "${repo_root}/scripts/local/klops.sh" run-remote \ "${host}" "${port}" root "${context}/deploy/setup-user.sh" "${public_proxy_user}" "${repo_root}/scripts/local/build-remote-image.sh" \ "${host}" "${port}" toad localhost/bugabinga-toad:latest "${context}" "${repo_root}/scripts/local/build-remote-image.sh" \ "${host}" "${port}" toad localhost/bugabinga-toad-ingress:latest "${context}/gateway" scp -P "${port}" "${quadlets}"/* "root@${host}:/home/toad/.config/containers/systemd/" sleep 2 scp -P "${port}" "${enrollment}" "root@${host}:/data/toad/enrollment.json" sleep 2 scp -P "${port}" "${gateway_config}" "root@${host}:/data/toad/gateway.Caddyfile" sleep 2 scp -P "${port}" "${ingress_env}" "root@${host}:/data/toad/ingress.env" sleep 2 scp -P "${port}" "${theme_css}" "root@${host}:/data/toad/nugu.css" sleep 2 "${repo_root}/scripts/local/klops.sh" run-remote \ "${host}" "${port}" root "${context}/deploy/start.sh"