From 60e74a31377a5756e247ebdf8ab5198a456e6e60 Mon Sep 17 00:00:00 2001 From: febux Date: Fri, 21 Aug 2026 18:58:40 +0300 Subject: [PATCH] Certbot script with env values comments was fixed. --- .env.example | 2 +- deploy/nginx/certbot-init.sh | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/.env.example b/.env.example index 70437c2..6b8e215 100644 --- a/.env.example +++ b/.env.example @@ -114,7 +114,7 @@ SMTP_FROM=no-reply@contract-check.local SMTP_USE_TLS=true # --- 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) --- BOT_TOKEN= # same value as TELEGRAM_BOT_TOKEN (kept for the bot image) diff --git a/deploy/nginx/certbot-init.sh b/deploy/nginx/certbot-init.sh index 8763e64..fef4889 100755 --- a/deploy/nginx/certbot-init.sh +++ b/deploy/nginx/certbot-init.sh @@ -32,10 +32,20 @@ if [[ -z "$DOMAIN" || -z "$EMAIL" ]]; then exit 1 fi -if [[ -f .env ]] && ! grep -qE "^NGINX_SERVER_NAME=${DOMAIN}\s*$" .env; then - echo "ERROR: NGINX_SERVER_NAME in .env must equal ${DOMAIN}." >&2 +# Resolve NGINX_SERVER_NAME the same way compose does: shell env wins over .env. +# 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:-}')." >&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 fi