#!/bin/bash # Preserve existing sites. Prefer a domain certificate; CDN IP origins can use # the server's existing valid IP certificate when HTTP-01 is unavailable. set -euo pipefail root=/opt/kaoyan-studio-deploy/app test -f /etc/nginx/kaoyan-studio.htpasswd python3 - <<'PY' from pathlib import Path root = Path('/opt/kaoyan-studio-deploy/app/deploy') text = (root / 'nginx-http-bootstrap.conf').read_text() + '\n' + (root / 'nginx-https.conf').read_text() cert = Path('/etc/letsencrypt/live/kaoyan.fjayson.com/fullchain.pem') if not cert.exists(): replacement = '/etc/letsencrypt/live/186.241.68.230/' if not Path(replacement, 'fullchain.pem').exists(): raise SystemExit('Install a valid origin certificate before configuring HTTPS') text = text.replace('/etc/letsencrypt/live/kaoyan.fjayson.com/', replacement) Path('/etc/nginx/sites-available/kaoyan-studio').write_text(text) PY ln -sfn /etc/nginx/sites-available/kaoyan-studio /etc/nginx/sites-enabled/kaoyan-studio nginx -t systemctl reload nginx