nomadro/apps/ebook/dymini/deploy/issue-certs.sh
eric d93a355fd5 Migrate navmini/ebook/nomadweb into apps/ as same-origin portal subpaths.
Shield external portal jumps (keep EXTERNAL_* for later), serve /nav from static build, and proxy /book + /community to vertical Next apps with Caddy notes.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-28 03:30:34 -05:00

73 lines
2.0 KiB
Bash

#!/usr/bin/env bash
# SSL for dyapi + dyadmin only (dy.nomadro.cn is used by another service)
set -euo pipefail
sed -i 's/\r$//' /opt/dymini/deploy/*.sh 2>/dev/null || true
DOMAINS=(dyapi.nomadro.cn dyadmin.nomadro.cn)
PANEL=/www/server/panel/vhost/nginx
REMOTE=/opt/dymini
ensure_http_bootstrap() {
local domain="$1"
local root="/www/wwwroot/${domain}"
local conf="${PANEL}/${domain}.conf"
sudo mkdir -p "$root/.well-known/acme-challenge"
if ! sudo test -f "/etc/letsencrypt/live/${domain}/fullchain.pem"; then
sudo tee "$conf" >/dev/null <<EOF
server {
listen 80;
server_name ${domain};
root ${root};
location ~ ^/\.well-known/ { allow all; }
location / { try_files \$uri \$uri/ =404; }
}
EOF
fi
}
for d in "${DOMAINS[@]}"; do
ensure_http_bootstrap "$d"
done
sudo nginx -t
sudo /etc/init.d/nginx reload 2>/dev/null || sudo nginx -s reload
for d in "${DOMAINS[@]}"; do
if sudo test -f "/etc/letsencrypt/live/${d}/fullchain.pem"; then
echo "cert exists: $d"
continue
fi
echo "issuing cert: $d"
sudo certbot certonly --webroot \
-w "/www/wwwroot/${d}" \
-d "$d" \
--non-interactive --agree-tos \
-m admin@nomadro.cn \
|| echo "WARN: certbot failed for $d"
done
for f in dyapi.nomadro.cn.conf dyadmin.nomadro.cn.conf; do
domain="${f%.conf}"
if ! sudo test -f "/etc/letsencrypt/live/${domain}/fullchain.pem"; then
echo "skip SSL restore for $domain (no cert)"
continue
fi
echo "install SSL nginx conf: $f"
sudo cp "$REMOTE/deploy/$f" "$PANEL/$f"
done
sudo rsync -a --delete /opt/dymini/admin/dist/ /www/wwwroot/dyadmin.nomadro.cn/
if id www >/dev/null 2>&1; then
sudo chown -R www:www /www/wwwroot/dyadmin.nomadro.cn || true
fi
sudo nginx -t
sudo /etc/init.d/nginx reload 2>/dev/null || sudo nginx -s reload
echo "--- verify ---"
curl -sk https://127.0.0.1/health -H 'Host: dyapi.nomadro.cn' || true
echo
curl -sI https://dyapi.nomadro.cn/health | head -n 5 || true
curl -sI https://dyadmin.nomadro.cn/ | head -n 5 || true
echo "issue-certs done"