Files
gsfdc/deploy/render-nginx.sh
T
wuzilongandCursor 9c7c80e194 feat: 把估价智能体和部署配置提交到主分支
门户估价对话、会员与智能体账号,以及生产 Docker 部署一直停在工作区,远端主分支还没有这些改动。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-23 09:42:44 +08:00

53 lines
1.6 KiB
Bash
Executable File

#!/bin/bash
set -euo pipefail
cd "$(dirname "$0")"
if [[ ! -f .env ]]; then
echo "缺少 .env,先执行 ./init-env.sh"
exit 1
fi
set -a
# shellcheck disable=SC1091
source .env
set +a
python3 - <<'PY'
import os
from pathlib import Path
root = Path(".")
site = os.environ["SITE_DOMAIN"].strip()
files = os.environ["FILES_DOMAIN"].strip()
names = os.environ.get("SITE_NAMES", site).strip()
flat = root / "certs" / "fullchain.pem"
flat_key = root / "certs" / "privkey.pem"
live = root / "certs" / "live" / site / "fullchain.pem"
live_key = root / "certs" / "live" / site / "privkey.pem"
https = (flat.is_file() and flat_key.is_file()) or (live.is_file() and live_key.is_file())
if flat.is_file() and flat_key.is_file():
cert_full = "/etc/nginx/certs/fullchain.pem"
cert_key = "/etc/nginx/certs/privkey.pem"
elif live.is_file() and live_key.is_file():
cert_full = f"/etc/nginx/certs/live/{site}/fullchain.pem"
cert_key = f"/etc/nginx/certs/live/{site}/privkey.pem"
else:
cert_full = ""
cert_key = ""
src = root / "nginx" / ("https.conf.template" if https else "http.conf.template")
text = src.read_text(encoding="utf-8")
values = {
"SITE_NAMES": names,
"FILES_DOMAIN": files,
"CERT_FULL": cert_full,
"CERT_KEY": cert_key,
}
for key, value in values.items():
text = text.replace("${" + key + "}", value)
if "${" in text:
raise SystemExit("nginx 模板仍有未替换的占位符")
out = root / "nginx" / "active.conf"
out.write_text(text, encoding="utf-8")
print(("https" if https else "http") + " 配置已写入 nginx/active.conf")
PY