#!/bin/bash

# 询问部署端口
read -p "请输入部署端口: " PORT

# 下载并解压 frpc
wget https://update.devlink.cn/frp/frp_0.48.0_linux_amd64.tar.gz -O frp.tar.gz
tar -zxvf frp.tar.gz frp_0.48.0_linux_amd64/frpc
mv frp_0.48.0_linux_amd64/frpc /usr/local/
rm -rf frp_0.48.0_linux_amd64 frp.tar.gz
chmod +x /usr/local/frpc

# 创建 frpc.ini 配置文件
cat > /etc/frpc.ini << EOF
[common]
server_addr = 111.161.65.46
server_port = 7000
token = wavpub2023
authentication_method=token
login_fail_exit=false
pool_count = 20
log_file = /var/log/frpc.log

[proxy-pool-$PORT]
type = tcp
local_ip = 127.0.0.1
local_port = $PORT
remote_port = $PORT
EOF

# 下载并解压 gost
wget https://update.devlink.cn/gost/gost-linux-amd64-2.11.5.gz -O gost.gz
gzip -d gost.gz
mv gost /usr/local/
chmod +x /usr/local/gost

# 创建 frpc.service 文件
cat > /etc/systemd/system/frpc.service << EOF
[Unit]
Description = frpc server
After = network.target syslog.target
Wants = network.target

[Service]
Type = simple
ExecStart = /usr/local/frpc -c /etc/frpc.ini

[Install]
WantedBy = multi-user.target
EOF

# 创建 gost.service 文件
cat > /etc/systemd/system/gost.service << EOF
[Unit]
Description = gost server
After = network.target syslog.target
Wants = network.target

[Service]
Type = simple
ExecStart = /usr/local/gost -L "http://@127.0.0.1:$PORT"

[Install]
WantedBy = multi-user.target
EOF

# 激活服务
systemctl enable frpc.service
systemctl enable gost.service

# 启动服务
service gost start
service frpc start

echo "部署完成！"


