68 lines
2.6 KiB
Bash
Executable File
68 lines
2.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Run on the nudentic.ir VPS as dyolink.
|
|
# Uses /opt/dyolink/secrets/arvan-api-key (one line, not in git).
|
|
# Points the existing nudentic.ir certificate at Arvan DNS-01 and reloads
|
|
# Nginx once a day so a renewed file is actually served.
|
|
set -euo pipefail
|
|
|
|
KEY=/opt/dyolink/secrets/arvan-api-key
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
|
if [ ! -s "$KEY" ]; then
|
|
echo "Missing $KEY" >&2
|
|
exit 1
|
|
fi
|
|
|
|
docker cp "$KEY" dyolink_certbot_prod:/etc/letsencrypt/arvan-api-key
|
|
docker cp "$SCRIPT_DIR/arvan_dns.py" dyolink_certbot_prod:/etc/letsencrypt/arvan_dns.py
|
|
docker cp "$SCRIPT_DIR/arvan-dns-auth.py" dyolink_certbot_prod:/etc/letsencrypt/arvan-dns-auth.py
|
|
docker cp "$SCRIPT_DIR/arvan-dns-cleanup.py" dyolink_certbot_prod:/etc/letsencrypt/arvan-dns-cleanup.py
|
|
docker exec dyolink_certbot_prod chmod 600 /etc/letsencrypt/arvan-api-key
|
|
docker exec dyolink_certbot_prod chmod 755 /etc/letsencrypt/arvan_dns.py /etc/letsencrypt/arvan-dns-auth.py /etc/letsencrypt/arvan-dns-cleanup.py
|
|
|
|
docker exec -i dyolink_certbot_prod python3 - <<'PY'
|
|
from pathlib import Path
|
|
path = Path("/etc/letsencrypt/renewal/nudentic.ir.conf")
|
|
text = path.read_text().splitlines()
|
|
kept = []
|
|
for line in text:
|
|
if line.startswith("manual_auth_hook ") or line.startswith("manual_cleanup_hook "):
|
|
continue
|
|
if line.startswith("webroot_path "):
|
|
continue
|
|
if line.startswith("authenticator "):
|
|
kept.append("authenticator = manual")
|
|
elif line.startswith("pref_challs "):
|
|
kept.append("pref_challs = dns-01,")
|
|
else:
|
|
kept.append(line)
|
|
hooks = [
|
|
"manual_auth_hook = /etc/letsencrypt/arvan-dns-auth.py",
|
|
"manual_cleanup_hook = /etc/letsencrypt/arvan-dns-cleanup.py",
|
|
]
|
|
out = []
|
|
inserted = False
|
|
for line in kept:
|
|
if line.startswith("[") and line != "[renewalparams]" and not inserted:
|
|
out.extend(hooks)
|
|
inserted = True
|
|
out.append(line)
|
|
if not inserted:
|
|
out.extend(hooks)
|
|
if not any(line.startswith("pref_challs ") for line in out):
|
|
out.append("pref_challs = dns-01,")
|
|
path.write_text("\n".join(out) + "\n")
|
|
print("renewal config updated")
|
|
PY
|
|
|
|
docker exec dyolink_certbot_prod mkdir -p /etc/letsencrypt/renewal-disabled
|
|
if docker exec dyolink_certbot_prod test -f /etc/letsencrypt/renewal/wixur.ir.conf; then
|
|
docker exec dyolink_certbot_prod mv /etc/letsencrypt/renewal/wixur.ir.conf /etc/letsencrypt/renewal-disabled/wixur.ir.conf
|
|
echo "wixur.ir renewal disabled on this host"
|
|
fi
|
|
|
|
CRON_LINE='15 3 * * * docker exec dyolink_nginx_prod nginx -s reload'
|
|
(crontab -l 2>/dev/null | grep -v 'dyolink_nginx_prod nginx -s reload' || true
|
|
echo "$CRON_LINE") | crontab -
|
|
echo "nginx reload scheduled daily at 03:15"
|