-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathinstall_goproxy.sh
More file actions
110 lines (95 loc) · 2.81 KB
/
install_goproxy.sh
File metadata and controls
110 lines (95 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/bin/bash
set -euo pipefail
# 检查是否以root用户运行
if [ "$(id -u)" -ne 0 ]; then
echo "请使用root用户运行此脚本" >&2
exit 1
fi
# 检测CPU架构
detect_architecture() {
local arch
arch=$(uname -m)
case $arch in
x86_64) echo "amd64" ;;
aarch64) echo "arm64-v8" ;;
armv7l) echo "arm" ;;
i386|i686) echo "386" ;;
*)
echo "不支持的架构: $arch" >&2
exit 1
;;
esac
}
ARCH=$(detect_architecture)
echo "检测到CPU架构: $ARCH"
# 提示用户输入 token(使用 read -s 隐藏输入)
read -r -s -p "请输入goproxy的token: " TOKEN
echo
if [ -z "$TOKEN" ]; then
echo "token不能为空" >&2
exit 1
fi
# 创建安装目录
INSTALL_DIR="/root/proxy"
rm -rf "$INSTALL_DIR"
mkdir -p "$INSTALL_DIR"
cd "$INSTALL_DIR"
# 获取最新版本号(增加 pipefail 友好的写法)
echo "正在获取最新版本..."
LAST_VERSION=$(curl --silent --fail --max-time 10 \
"https://api.github.com/repos/snail007/goproxy/releases/latest" \
| grep -Po '"tag_name": *"\K.*?(?=")' || true)
if [ -z "$LAST_VERSION" ]; then
echo "无法获取最新版本号,使用默认版本 v15.1"
LAST_VERSION="v15.1"
else
echo "获取到最新版本: $LAST_VERSION"
fi
# 下载安装包
PACKAGE="proxy-linux-${ARCH}.tar.gz"
DOWNLOAD_URL="https://ghfast.top/https://github.com/snail007/goproxy/releases/download/${LAST_VERSION}/${PACKAGE}"
echo "正在下载 ${DOWNLOAD_URL}..."
wget --show-progress -q "$DOWNLOAD_URL" -O "$PACKAGE"
# 解压安装包
echo "正在解压安装包..."
tar zxf "$PACKAGE"
rm -f "$PACKAGE"
# 创建 systemd 服务文件
SERVICE_FILE="/etc/systemd/system/goproxy.service"
echo "正在创建systemd服务..."
cat > "$SERVICE_FILE" << EOF
[Unit]
Description=GoProxy Client Service
After=network.target
[Service]
Type=simple
WorkingDirectory=/root/proxy
ExecStart=/root/proxy/proxy client -P nps.175419.xyz:30001 -T tcp --k ${TOKEN}
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
EOF
# 限制服务文件权限(含 token,不允许其他用户读取)
chmod 600 "$SERVICE_FILE"
# 启动服务
echo "正在启动goproxy服务..."
systemctl daemon-reload
systemctl enable goproxy
systemctl start goproxy
# 检查服务状态
echo "检查服务状态..."
if systemctl is-active --quiet goproxy; then
echo "✅ goproxy服务已成功启动"
echo ""
echo "可以使用以下命令管理服务:"
echo " 启动: systemctl start goproxy"
echo " 停止: systemctl stop goproxy"
echo " 重启: systemctl restart goproxy"
echo " 查看状态: systemctl status goproxy"
echo " 查看日志: journalctl -u goproxy"
else
echo "❌ goproxy服务启动失败" >&2
echo "请查看日志: journalctl -u goproxy" >&2
exit 1
fi