#!/bin/bash
SERVER_IP="45.61.60.10"
SERVER_USER="root"
SERVER_PASS="UQb9TgSwC@vwhEM"

/usr/bin/expect <<EOF
set timeout 30
spawn ssh -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP
expect {
    "password:" { send "$SERVER_PASS\r" }
    "yes/no" { send "yes\r"; exp_continue }
}
expect "#"

# 确保配置已移动
send "if test -f /tmp/ccdw_full.conf && test -f /etc/letsencrypt/live/ccdw.xyz/fullchain.pem; then mv /tmp/ccdw_full.conf /etc/nginx/sites-available/ccdw.xyz.conf && ln -sf /etc/nginx/sites-available/ccdw.xyz.conf /etc/nginx/sites-enabled/ccdw.xyz.conf; fi\r"

# 强制重启 Nginx
send "systemctl restart nginx\r"

# 验证
send "echo '--- VALIDATION ---'\r"
send "curl -I https://ccdw.xyz\r"
send "curl -I http://ccdw.xyz\r"

send "exit\r"
expect eof
EOF
