From dba7632ce25f569369da0923c879f923391b6f99 Mon Sep 17 00:00:00 2001 From: justin Date: Sun, 7 Jun 2026 04:51:02 -0500 Subject: [PATCH] fix(deploy): extract TELEGRAM vars from .env without sourcing it `. ./.env` choked on shell-hostile values (SMTP_PASS special chars), aborting before TELEGRAM vars loaded and rendering an empty alertmanager.yml. Extract just the two keys with sed instead, and warn if either is empty. --- deploy.sh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/deploy.sh b/deploy.sh index 1f02876..1cda66f 100755 --- a/deploy.sh +++ b/deploy.sh @@ -36,14 +36,20 @@ python3 scripts/sync_nav.py # / ${TELEGRAM_CHAT_ID}) crash-loops it ("cannot unmarshal !!str `${TELEG...`"). # We substitute the real values here from .env at deploy time. Only those two # vars are expanded so Alertmanager's own {{ }} Go-template message is untouched. +# NB: we extract just these two keys (not `source .env`) because .env holds values +# with shell-hostile chars (e.g. SMTP_PASS) that break `. ./.env`. echo "" echo "=== Rendering monitoring/alertmanager.yml from template ===" if [ -f monitoring/alertmanager.yml.template ]; then - set -a; [ -f .env ] && . ./.env; set +a + get_env() { sed -n "s/^$1=//p" .env | head -n1; } + TELEGRAM_BOT_TOKEN="$(get_env TELEGRAM_BOT_TOKEN)" + TELEGRAM_CHAT_ID="$(get_env TELEGRAM_CHAT_ID)" + export TELEGRAM_BOT_TOKEN TELEGRAM_CHAT_ID envsubst '${TELEGRAM_BOT_TOKEN} ${TELEGRAM_CHAT_ID}' \ < monitoring/alertmanager.yml.template > monitoring/alertmanager.yml - if grep -q '\${TELEGRAM' monitoring/alertmanager.yml; then - echo "WARN: TELEGRAM_BOT_TOKEN/TELEGRAM_CHAT_ID not set in .env; Alertmanager will crash-loop." >&2 + if grep -q '\${TELEGRAM' monitoring/alertmanager.yml \ + || [ -z "$TELEGRAM_BOT_TOKEN" ] || [ -z "$TELEGRAM_CHAT_ID" ]; then + echo "WARN: TELEGRAM_BOT_TOKEN/TELEGRAM_CHAT_ID missing in .env; Alertmanager will crash-loop." >&2 fi fi