From 48d3e3f76195001495bf5d8086ebefe0da05bd94 Mon Sep 17 00:00:00 2001 From: defiQUG Date: Tue, 28 Apr 2026 05:21:33 -0700 Subject: [PATCH] Backfill Phoenix deploy API env on install --- phoenix-deploy-api/scripts/install-systemd.sh | 65 ++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/phoenix-deploy-api/scripts/install-systemd.sh b/phoenix-deploy-api/scripts/install-systemd.sh index 6d06cf94..27e817d9 100644 --- a/phoenix-deploy-api/scripts/install-systemd.sh +++ b/phoenix-deploy-api/scripts/install-systemd.sh @@ -25,7 +25,70 @@ if [[ -f "$REPO_ROOT/config/public-sector-program-manifest.json" ]]; then else echo "WARN: $REPO_ROOT/config/public-sector-program-manifest.json missing — set PUBLIC_SECTOR_MANIFEST_PATH in .env" fi -[ -f "$APP_DIR/.env" ] && cp "$APP_DIR/.env" "$TARGET/.env" || [ -f "$APP_DIR/.env.example" ] && cp "$APP_DIR/.env.example" "$TARGET/.env" || true +if [[ -f "$TARGET/.env" ]]; then + echo "Preserving existing $TARGET/.env" +elif [[ -f "$APP_DIR/.env" ]]; then + cp "$APP_DIR/.env" "$TARGET/.env" +elif [[ -f "$APP_DIR/.env.example" ]]; then + cp "$APP_DIR/.env.example" "$TARGET/.env" +fi + +ensure_env_value() { + local key="$1" + local value="$2" + local file="$TARGET/.env" + [[ -n "$value" && -f "$file" ]] || return 0 + + local current="" + if grep -qE "^${key}=" "$file"; then + current="$(grep -E "^${key}=" "$file" | tail -n 1 | cut -d= -f2-)" + fi + [[ -z "$current" ]] || return 0 + + local tmp + tmp="$(mktemp)" + awk -v key="$key" -v value="$value" ' + BEGIN { found = 0 } + $0 ~ "^" key "=" { + print key "=" value + found = 1 + next + } + { print } + END { + if (!found) print key "=" value + } + ' "$file" > "$tmp" + cat "$tmp" > "$file" + rm -f "$tmp" +} + +repo_env_value() { + local key="$1" + local file="$REPO_ROOT/.env" + [[ -f "$file" ]] || return 0 + grep -E "^${key}=" "$file" | tail -n 1 | cut -d= -f2- +} + +if [[ -f "$TARGET/.env" ]]; then + ensure_env_value PHOENIX_REPO_ROOT "$REPO_ROOT" + for key in \ + GITEA_TOKEN \ + PHOENIX_DEPLOY_SECRET \ + PROXMOX_HOST \ + PROXMOX_PORT \ + PROXMOX_USER \ + PROXMOX_TOKEN_NAME \ + PROXMOX_TOKEN_VALUE \ + PROXMOX_TLS_VERIFY \ + PUBLIC_IP \ + CLOUDFLARE_API_TOKEN \ + CLOUDFLARE_GITEA_SYNC_ZONE \ + PHOENIX_CLOUDFLARE_SYNC + do + ensure_env_value "$key" "$(repo_env_value "$key")" + done +fi chown -R root:root "$TARGET" cd "$TARGET" && npm install --omit=dev cp "$APP_DIR/phoenix-deploy-api.service" /etc/systemd/system/