titan-iac/scripts/cluster_power_console.sh

79 lines
1.9 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
usage() {
cat <<USAGE
Usage:
scripts/cluster_power_console.sh [--repo-dir <path>] [--delegate-host <host>] [--allow-local] <prepare|status|shutdown|startup> [recovery-script-options...]
Purpose:
Friendly manual entrypoint for running Hecate from a remote console.
The canonical control host is titan-db by default so bundle/state handling stays in one place.
Defaults:
--repo-dir \$HOME/Development/titan-iac
--delegate-host titan-db
Examples:
scripts/cluster_power_console.sh status
scripts/cluster_power_console.sh prepare --execute
scripts/cluster_power_console.sh shutdown --execute
scripts/cluster_power_console.sh startup --execute --force-flux-branch main
USAGE
}
REPO_DIR="${HOME}/Development/titan-iac"
DELEGATE_HOST="titan-db"
ALLOW_LOCAL=0
REMOTE_REPO_DIR="${HECATE_REMOTE_REPO_DIR:-}"
while [[ $# -gt 0 ]]; do
case "$1" in
--repo-dir)
REPO_DIR="${2:-}"
shift 2
;;
--delegate-host)
DELEGATE_HOST="${2:-}"
shift 2
;;
--allow-local)
ALLOW_LOCAL=1
shift
;;
-h|--help)
usage
exit 0
;;
*)
break
;;
esac
done
if [[ $# -lt 1 ]]; then
usage
exit 1
fi
LOCAL_SCRIPT="${REPO_DIR}/scripts/cluster_power_recovery.sh"
CURRENT_HOST="$(hostname -s 2>/dev/null || hostname)"
if [[ -x "${LOCAL_SCRIPT}" ]] && command -v kubectl >/dev/null 2>&1; then
if [[ "${ALLOW_LOCAL}" -eq 1 || "${CURRENT_HOST}" == "${DELEGATE_HOST}" ]]; then
exec "${LOCAL_SCRIPT}" "$@"
fi
fi
if [[ -z "${DELEGATE_HOST}" ]]; then
echo "cluster-power-console: no delegate host configured" >&2
exit 1
fi
quoted_args="$(printf '%q ' "$@")"
remote_prefix=""
if [[ -n "${REMOTE_REPO_DIR}" ]]; then
remote_prefix="HECATE_REPO_DIR=$(printf '%q' "${REMOTE_REPO_DIR}") "
fi
exec ssh -o BatchMode=yes -o ConnectTimeout=8 "${DELEGATE_HOST}" "${remote_prefix}~/hecate-tools/cluster_power_recovery.sh ${quoted_args}"