diff --git a/scripts/deploy/deploy-node.sh b/scripts/deploy/deploy-node.sh index da9baf7..f2c5c21 100755 --- a/scripts/deploy/deploy-node.sh +++ b/scripts/deploy/deploy-node.sh @@ -8,7 +8,7 @@ set -e REPO_PATH="${HOME}/homelab-codex-ws" RUNTIME_PATH="/opt/homelab" HOSTNAME=$(hostname | tr '[:lower:]' '[:upper:]') -HOST_DIR="${REPO_PATH}/hosts/$(hostname | tr '[:upper:]' '[:lower:]')" +CURRENT_OS_HOST=$(hostname) echo "--- Starting Deployment on ${HOSTNAME} ---" @@ -22,6 +22,38 @@ cd "$REPO_PATH" echo "Pulling latest changes..." git pull +# Resolve host directory: search hosts/*/host.yaml for os_hostname == $(hostname) +HOST_LOGICAL=$(python3 -c " +import yaml, os, sys +current = '${CURRENT_OS_HOST}' +hosts_dir = os.path.join('${REPO_PATH}', 'hosts') +for entry in sorted(os.listdir(hosts_dir)): + host_yaml = os.path.join(hosts_dir, entry, 'host.yaml') + if not os.path.isfile(host_yaml): + continue + try: + with open(host_yaml) as f: + data = yaml.safe_load(f) + if data and data.get('os_hostname') == current: + print(entry) + sys.exit(0) + except Exception: + pass +") + +if [ -n "$HOST_LOGICAL" ]; then + HOST_DIR="${REPO_PATH}/hosts/${HOST_LOGICAL}" +else + HOST_LOGICAL_FB="$(echo "$CURRENT_OS_HOST" | tr '[:upper:]' '[:lower:]')" + echo "WARN: no os_hostname match for ${CURRENT_OS_HOST}, falling back to lowercase hostname dir" >&2 + HOST_DIR="${REPO_PATH}/hosts/${HOST_LOGICAL_FB}" +fi + +if [ ! -d "$HOST_DIR" ]; then + echo "Error: No host directory found for ${CURRENT_OS_HOST} (tried ${HOST_DIR})" >&2 + exit 1 +fi + # 2. Identify Services SERVICES=() if [ -f "${HOST_DIR}/services.txt" ]; then