Certbot script with env values comments was fixed.

This commit is contained in:
febux 2026-08-21 18:58:40 +03:00
parent c70ac6e310
commit 60e74a3137
2 changed files with 14 additions and 4 deletions

View file

@ -114,7 +114,7 @@ SMTP_FROM=no-reply@contract-check.local
SMTP_USE_TLS=true SMTP_USE_TLS=true
# --- Edge proxy (Nginx + certbot) --- # --- Edge proxy (Nginx + certbot) ---
NGINX_SERVER_NAME=contract-check.example.com # public domain for the edge profile NGINX_SERVER_NAME=contract-check.example.com
# --- Telegram bot (adapter, HTTP-only to api) --- # --- Telegram bot (adapter, HTTP-only to api) ---
BOT_TOKEN= # same value as TELEGRAM_BOT_TOKEN (kept for the bot image) BOT_TOKEN= # same value as TELEGRAM_BOT_TOKEN (kept for the bot image)

View file

@ -32,10 +32,20 @@ if [[ -z "$DOMAIN" || -z "$EMAIL" ]]; then
exit 1 exit 1
fi fi
if [[ -f .env ]] && ! grep -qE "^NGINX_SERVER_NAME=${DOMAIN}\s*$" .env; then # Resolve NGINX_SERVER_NAME the same way compose does: shell env wins over .env.
echo "ERROR: NGINX_SERVER_NAME in .env must equal ${DOMAIN}." >&2 # Tolerates quotes, inline comments ("domain # comment"), CRLF and padding —
# a hostname never contains whitespace, so the first token is the value.
configured="${NGINX_SERVER_NAME:-}"
if [[ -z "$configured" && -f .env ]]; then
raw="$(sed -nE 's/^NGINX_SERVER_NAME=//p' .env | tail -n1 | tr -d "\"'\r")"
read -r configured _ <<<"$raw" || true
fi
if [[ "$configured" != "$DOMAIN" ]]; then
echo "ERROR: NGINX_SERVER_NAME must equal ${DOMAIN} (found: '${configured:-<unset>}')." >&2
echo " nginx renders server_name and the certificate path from it." >&2 echo " nginx renders server_name and the certificate path from it." >&2
echo " Add/fix: NGINX_SERVER_NAME=${DOMAIN}" >&2 echo " Fix .env in the project root: NGINX_SERVER_NAME=${DOMAIN}" >&2
echo " (or export NGINX_SERVER_NAME=${DOMAIN} before running this script)" >&2
echo " Run the script from the project root — the dir containing .env." >&2
exit 1 exit 1
fi fi