#!/bin/bash
# ============================================================
# SSL 인증서 설정 (Let's Encrypt / Certbot)
# 도메인이 있을 경우 실행
# 실행: bash 04_ssl_setup.sh yourdomain.com
# ============================================================

DOMAIN=${1:-"zioinfo.co.kr"}

echo "[1] Certbot 설치"
sudo apt-get install -y certbot python3-certbot-nginx

echo "[2] SSL 인증서 발급 — $DOMAIN"
sudo certbot --nginx -d $DOMAIN -d www.$DOMAIN \
  --non-interactive --agree-tos --email admin@$DOMAIN \
  --redirect

echo "[3] 자동 갱신 확인"
sudo certbot renew --dry-run

echo "[4] Nginx 재시작"
sudo systemctl reload nginx

echo "✅ SSL 설정 완료!"
echo "   https://$DOMAIN 으로 접속하세요"
