-
Notifications
You must be signed in to change notification settings - Fork 97
/
f.sh
342 lines (266 loc) · 7.73 KB
/
f.sh
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
#!/bin/bash
#====================================================
# System Request: Centos 7+ Debian 8+
# Author: dylanbai8
# * Frps 一键安装脚本,Frpc Windows 便捷脚本!Frp 远程桌面!
# * 开源地址:https://github.com/dylanbai8/frpspro
# Blog: https://oo0.bid
#====================================================
# 获取frps最新版本号
get_version(){
api_url="https://api.github.com/repos/fatedier/frp/releases/latest"
new_ver=`curl ${PROXY} -s ${api_url} --connect-timeout 10| grep 'tag_name' | cut -d\" -f4`
touch ./version.txt
cat <<EOF > ./version.txt
${new_ver}
EOF
sed -i 's/v//g' ./version.txt
get_releases=$(cat ./version.txt)
releases_url=https://github.com/fatedier/frp/releases/download/${new_ver}/frp_${get_releases}_linux_amd64.tar.gz
windows_url=https://github.com/fatedier/frp/releases/download/${new_ver}/frp_${get_releases}_windows_amd64.zip
rm -rf ./version.txt
}
# 安装frps
install_frps(){
wget -N --no-check-certificate ${releases_url}
tar -zxvf frp*.tar.gz
rm -rf /usr/local/frps
mkdir /usr/local/frps
mv ./frp*/frps /usr/local/frps/frps
mv ./frp*/frps_full.ini /usr/local/frps/frps.ini
rm -rf ./frp*
}
# 添加开机自启动
add_auto_run(){
touch /etc/systemd/system/frps.service
cat <<EOF > /etc/systemd/system/frps.service
[Unit]
Description=frps server
After=network.target
Wants=network.target
[Service]
Type=simple
PIDFile=/var/run/frps.pid
ExecStart=/usr/local/frps/frps -c /usr/local/frps/frps.ini
RestartPreventExitStatus=23
Restart=always
User=root
[Install]
WantedBy=multi-user.target
EOF
}
# 启动frps
run_frps(){
systemctl daemon-reload
systemctl enable frps >/dev/null 2>&1
systemctl start frps
systemctl restart frps
}
# 卸载frps
set_uninstall(){
systemctl stop frps
systemctl disable frps
rm -rf /usr/local/frps
rm -rf /etc/systemd/system/frps.service >/dev/null 2>&1
echo -e "卸载成功!"
}
# 展示菜单
load_menu(){
local_ip=`curl -4 ip.sb`
clear
echo ""
echo -e "--------------------安装完成----------------------"
echo -e "管理面板:http://${local_ip}:7500"
echo -e "用户名:admin 密码:admin"
echo -e "默认 bind_port:7000"
echo -e "默认 token:12345678"
echo ""
echo -e "默认 vhost_http_port:80"
echo -e "默认 vhost_https_port:443"
echo ""
echo -e "默认 bind_udp_port:7001"
echo -e "默认 kcp_bind_port:7000"
echo -e "默认 allow_ports:2000-3000,3001,3003,4000-50000"
echo ""
echo -e "Windows 便捷脚本:https://github.com/dylanbai8/frpspro/raw/master/FrpsPro.zip"
echo -e "Windows 最新内核:${windows_url}"
echo -e "--------------------------------------------------"
}
# 各种设置项
# ====================================
set_bind_port(){
get_value=""
echo -e "你正在设置 bind_port "
read -e -p "请输入:" get_value
[[ -z ${get_value} ]] && get_value="none"
if [ "${get_value}" = "none" ];then
set_bind_port
else
echo -e "你设置的值为:${get_value}"
fi
sed -i '/^bind_port/c\bind_port = '"${get_value}"'' /usr/local/frps/frps.ini
systemctl restart frps
echo -e "设置成功!"
}
set_bind_udp_port(){
get_value=""
echo -e "你正在设置 bind_udp_port "
read -e -p "请输入:" get_value
[[ -z ${get_value} ]] && get_value="none"
if [ "${get_value}" = "none" ];then
set_bind_udp_port
else
echo -e "你设置的值为:${get_value}"
fi
sed -i '/^bind_udp_port/c\bind_udp_port = '"${get_value}"'' /usr/local/frps/frps.ini
systemctl restart frps
echo -e "设置成功!"
}
set_kcp_bind_port(){
get_value=""
echo -e "你正在设置 kcp_bind_port "
read -e -p "请输入:" get_value
[[ -z ${get_value} ]] && get_value="none"
if [ "${get_value}" = "none" ];then
set_kcp_bind_port
else
echo -e "你设置的值为:${get_value}"
fi
sed -i '/^kcp_bind_port/c\kcp_bind_port = '"${get_value}"'' /usr/local/frps/frps.ini
systemctl restart frps
echo -e "设置成功!"
}
set_vhost_http_port(){
get_value=""
echo -e "你正在设置 vhost_http_port "
read -e -p "请输入:" get_value
[[ -z ${get_value} ]] && get_value="none"
if [ "${get_value}" = "none" ];then
set_vhost_http_port
else
echo -e "你设置的值为:${get_value}"
fi
sed -i '/^vhost_http_port/c\vhost_http_port = '"${get_value}"'' /usr/local/frps/frps.ini
systemctl restart frps
echo -e "设置成功!"
}
set_vhost_https_port(){
get_value=""
echo -e "你正在设置 vhost_https_port "
read -e -p "请输入:" get_value
[[ -z ${get_value} ]] && get_value="none"
if [ "${get_value}" = "none" ];then
set_vhost_https_port
else
echo -e "你设置的值为:${get_value}"
fi
sed -i '/^vhost_https_port/c\vhost_https_port = '"${get_value}"'' /usr/local/frps/frps.ini
systemctl restart frps
echo -e "设置成功!"
}
set_dashboard_port(){
get_value=""
echo -e "你正在设置 dashboard_port "
read -e -p "请输入:" get_value
[[ -z ${get_value} ]] && get_value="none"
if [ "${get_value}" = "none" ];then
set_dashboard_port
else
echo -e "你设置的值为:${get_value}"
fi
sed -i '/^dashboard_port/c\dashboard_port = '"${get_value}"'' /usr/local/frps/frps.ini
systemctl restart frps
echo -e "设置成功!"
}
set_dashboard_user(){
get_value=""
echo -e "你正在设置 dashboard_user "
read -e -p "请输入:" get_value
[[ -z ${get_value} ]] && get_value="none"
if [ "${get_value}" = "none" ];then
set_dashboard_user
else
echo -e "你设置的值为:${get_value}"
fi
sed -i '/^dashboard_user/c\dashboard_user = '"${get_value}"'' /usr/local/frps/frps.ini
systemctl restart frps
echo -e "设置成功!"
}
set_dashboard_pwd(){
get_value=""
echo -e "你正在设置 dashboard_pwd "
read -e -p "请输入:" get_value
[[ -z ${get_value} ]] && get_value="none"
if [ "${get_value}" = "none" ];then
set_dashboard_pwd
else
echo -e "你设置的值为:${get_value}"
fi
sed -i '/^dashboard_pwd/c\dashboard_pwd = '"${get_value}"'' /usr/local/frps/frps.ini
systemctl restart frps
echo -e "设置成功!"
}
set_token(){
get_value=""
echo -e "你正在设置 token "
read -e -p "请输入:" get_value
[[ -z ${get_value} ]] && get_value="none"
if [ "${get_value}" = "none" ];then
set_token
else
echo -e "你设置的值为:${get_value}"
fi
sed -i '/^token/c\token = '"${get_value}"'' /usr/local/frps/frps.ini
systemctl restart frps
echo -e "设置成功!"
}
set_subdomain_host(){
get_value=""
echo -e "你正在设置 subdomain_host "
read -e -p "请输入:" get_value
[[ -z ${get_value} ]] && get_value="none"
if [ "${get_value}" = "none" ];then
set_subdomain_host
else
echo -e "你设置的值为:${get_value}"
fi
sed -i '/^subdomain_host/c\subdomain_host = '"${get_value}"'' /usr/local/frps/frps.ini
systemctl restart frps
echo -e "设置成功!"
}
# ====================================
# 关闭apache2 释放80端口
set_unapache2(){
systemctl disable httpd >/dev/null 2>&1
systemctl stop httpd >/dev/null 2>&1
killall -9 httpd >/dev/null 2>&1
systemctl disable apache2 >/dev/null 2>&1
systemctl stop apache2 >/dev/null 2>&1
killall -9 apache2 >/dev/null 2>&1
systemctl disable firewalld >/dev/null 2>&1
systemctl stop firewalld >/dev/null 2>&1
killall -9 firewalld >/dev/null 2>&1
systemctl disable iptables >/dev/null 2>&1
systemctl stop iptables >/dev/null 2>&1
killall -9 iptables >/dev/null 2>&1
echo -e "关闭 apache2 成功!"
echo -e "关闭 防火墙 成功!"
}
# 安装流程
set_install(){
get_version
install_frps
add_auto_run
run_frps
load_menu
}
# 脚本菜单
case "$1" in
bind_port|bind_udp_port|kcp_bind_port|vhost_http_port|vhost_https_port|dashboard_port|dashboard_user|dashboard_pwd|token|subdomain_host|install|uninstall|unapache2)
set_$1
;;
*)
echo -e "缺少参数,更多教程请访问:https://github.com/dylanbai8/kmspro"
;;
esac
# 转载请保留版权:https://github.com/dylanbai8/frpspro