#!/usr/bin/expect -f

# NAS SSH 自动化部署脚本
# 使用 expect 自动输入密码

set timeout 600
set nas_ip "192.168.2.154"
set nas_user "cfdaily"
set nas_pass "Ccf7561523"

spawn ssh $nas_user@$nas_ip

expect {
    "Password:" {
        send "$nas_pass\r"
    }
    "password:" {
        send "$nas_pass\r"
    }
    "Are you sure you want to continue connecting" {
        send "yes\r"
        exp_continue
    }
    timeout {
        puts "SSH连接超时"
        exit 1
    }
}

expect "$ "

send "cd /volume1/stock/sanguo_vnpy\r"
expect "$ "

send "ls -la\r"
expect "$ "

send "chmod +x start_on_nas.sh\r"
expect "$ "

send "./start_on_nas.sh\r"

expect {
    "✅ sanguo_vnpy 启动成功" {
        puts "\n\n部署成功！"
    }
    timeout {
        puts "\n\n命令执行中，请稍后查看..."
    }
}

interact
