-
Notifications
You must be signed in to change notification settings - Fork 0
/
script_vmess_old.sh
376 lines (371 loc) · 10.4 KB
/
script_vmess_old.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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
#!/bin/bash
#on ubuntu
red='\033[0;31m'
green='\033[0;32m'
yellow='\033[0;33m'
plain='\033[0m'
#Add some basic function here
function LOGD() {
echo -e "${yellow}[DEG] $* ${plain}"
}
function LOGE() {
echo -e "${red}[ERR] $* ${plain}"
}
function LOGI() {
echo -e "${green}[INF] $* ${plain}"
}
[[ $EUID -ne 0 ]] && LOGE "错误: 必须使用root用户运行此脚本!\n" && exit 1
confirm() {
if [[ $# > 1 ]]; then
echo && read -p "$1 [默认$2]: " temp
if [[ x"${temp}" == x"" ]]; then
temp=$2
fi
else
read -p "$1 [y/n]: " temp
fi
if [[ x"${temp}" == x"y" || x"${temp}" == x"Y" ]]; then
return 0
else
return 1
fi
}
get_ip() {
eth=`ifconfig | grep -Eo ".*: " | grep -Eo "\w*" | grep -v lo`
ip=`ifconfig $eth| grep -Eo "inet [0-9]*\.[0-9]*\.[0-9]*\.[0-9]*" | grep -Eo "[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*"`
ethnum=`ifconfig | grep -Eo ".*: " | grep -Eo "\w*" | grep -v -c lo`
ethnum=$((ethnum))
echo $ip
echo $ethnum
echo -e "all_ipaddress:\n"$ip
use_ip=""
if [ $ethnum != 1 ];then
read -p "Input your vps_ip here:" use_ip
else
use_ip=$ip
fi
}
cof_json() {
get_ip
cf_ip=${use_ip}
cf_port=""
cf_name=""
cf_uuid=`xray uuid`
cf_don=${CF_Domain}
cf_cer_pth="$certPath/${CF_Domain}.crt"
cf_key_pth="$certPath/${CF_Domain}.key"
read -p "Set your xy_name:" cf_name
read -p "Input your xy_port:" cf_port
echo -e "This is ur cfg:
name:$cf_name
ip:$cf_ip
port:$cf_port
uuid:$cf_uuid
don:$cf_don
cer_pth:$cf_cer_pth
key_pth:$cf_key_pth
"
confirm "确认配置無誤[y/n]" "y"
if [ $? -eq 0 ]; then
echo "開始寫入config"
else
exit 0
fi
echo "{
\"log\": null,
\"routing\": {
\"domainStrategy\": \"AsIs\",
\"rules\": [
{
\"type\": \"field\",
\"ip\": [
\"geoip:private\"
],
\"outboundTag\": \"block\"
},
{
\"type\": \"field\",
\"protocol\": [
\"bittorrent\"
],
\"outboundTag\": \"block\"
}
]
},
\"dns\": null,
\"inbounds\": [
{
\"listen\": \"$cf_ip\",
\"port\": $cf_port,
\"protocol\": \"vmess\",
\"settings\": {
\"clients\": [
{
\"id\": \"$cf_uuid\",
\"alterId\": 0
}
],
\"disableInsecureEncryption\": false
},
\"streamSettings\": {
\"network\": \"tcp\",
\"security\": \"tls\",
\"tlsSettings\": {
\"serverName\": \"$cf_don\",
\"certificates\": [
{
\"certificateFile\": \"$cf_cer_pth\",
\"keyFile\": \"$cf_key_pth\"
}
]
},
\"tcpSettings\": {
\"header\": {
\"type\": \"none\"
}
}
},
\"tag\": \"inbound-$cf_port\",
\"sniffing\": {
\"enabled\": true,
\"destOverride\": [
\"http\",
\"tls\"
]
}
}
],
\"outbounds\": [
{
\"protocol\": \"freedom\",
\"tag\": \"direct\"
},
{
\"protocol\": \"blackhole\",
\"tag\": \"block\"
}
]
}">/usr/local/etc/xray/config.json
base64_link=`echo -n "{
\"v\": \"2\",
\"ps\": \"$cf_name\",
\"add\": \"$cf_don\",
\"port\": $cf_port,
\"id\": \"$cf_uuid\",
\"aid\": 0,
\"net\": \"tcp\",
\"type\": \"none\",
\"host\": \"\",
\"path\": \"\",
\"tls\": \"tls\"
}" | base64 |tr -d '\n'`
echo -e "vmess://$base64_link\n" > /usr/link.vms
echo -e "----------\nyour_link_pth:/usr/link.vms\n----------"
cat /usr/link.vms
}
install_acme() {
cd ~
LOGI "开始安装acme脚本..."
apt update
apt install cron socat net-tools
curl https://get.acme.sh | sh
if [ $? -ne 0 ]; then
LOGE "acme安装失败"
return 1
else
LOGI "acme安装成功"
fi
return 0
}
ssl_cert_issue_by_cloudflare() {
echo -E ""
LOGD "******使用说明******"
LOGI "该脚本将使用Acme脚本申请证书,使用时需保证:"
LOGI "1.知晓Cloudflare 注册邮箱"
LOGI "2.知晓Cloudflare Global API Key"
LOGI "3.域名已通过Cloudflare进行解析到当前服务器"
LOGI "4.该脚本申请证书默认安装路径为/root/cert目录"
confirm "我已确认以上内容[y/n]" "y"
if [ $? -eq 0 ]; then
install_acme
if [ $? -ne 0 ]; then
LOGE "无法安装acme,请检查错误日志"
exit 1
fi
CF_Domain=""
CF_GlobalKey=""
CF_AccountEmail=""
certPath=/root/cert
if [ ! -d "$certPath" ]; then
mkdir $certPath
fi
LOGD "请设置域名:"
read -p "Input your domain here:" CF_Domain
LOGD "你的域名设置为:${CF_Domain},正在进行域名合法性校验..."
#here we need to judge whether there exists cert already
local currentCert=$(~/.acme.sh/acme.sh --list | grep ${CF_Domain} | wc -l)
if [ ${currentCert} -ne 0 ]; then
local certInfo=$(~/.acme.sh/acme.sh --list)
LOGE "域名合法性校验失败,当前环境已有对应域名证书,不可重复申请,当前证书详情:"
LOGI "$certInfo"
exit 1
else
LOGI "域名合法性校验通过..."
fi
LOGD "请设置API密钥:"
read -p "Input your key here:" CF_GlobalKey
LOGD "你的API密钥为:${CF_GlobalKey}"
LOGD "请设置注册邮箱:"
read -p "Input your email here:" CF_AccountEmail
LOGD "你的注册邮箱为:${CF_AccountEmail}"
~/.acme.sh/acme.sh --set-default-ca --server letsencrypt
if [ $? -ne 0 ]; then
LOGE "修改默认CA为Lets'Encrypt失败,脚本退出"
exit 1
fi
export CF_Key="${CF_GlobalKey}"
export CF_Email=${CF_AccountEmail}
~/.acme.sh/acme.sh --issue --dns dns_cf -d ${CF_Domain} --log
if [ $? -ne 0 ]; then
LOGE "证书签发失败,脚本退出"
rm -rf ~/.acme.sh/${CF_Domain}
exit 1
else
LOGI "证书签发成功,安装中..."
fi
~/.acme.sh/acme.sh --installcert -d ${CF_Domain} --ca-file /root/cert/ca.crt \
--cert-file /root/cert/server.crt --key-file /root/cert/${CF_Domain}.key \
--fullchain-file /root/cert/${CF_Domain}.crt
if [ $? -ne 0 ]; then
LOGE "证书安装失败,脚本退出"
rm -rf ~/.acme.sh/${CF_Domain}
exit 1
else
LOGI "证书安装成功,开启自动更新..."
fi
~/.acme.sh/acme.sh --upgrade --auto-upgrade
if [ $? -ne 0 ]; then
LOGE "自动更新设置失败,脚本退出"
ls -lah cert
chmod 755 $certPath
exit 1
else
LOGI "证书已安装且已开启自动更新,具体信息如下"
ls -lah cert
chmod 755 $certPath
fi
else
exit 0
fi
}
main() {
echo && read -p "
0.exit
1.get_cf_crt
2.install&&upgrade_xy_use_root
3.xy_filepth
4.install_all
5.stop_xy
6.restart_xy
7.start_xy
8.update_geop
9.remove_xy
" num
case "${num}" in
0)
exit
;;
1)
ssl_cert_issue_by_cloudflare
;;
2)
bash -c "$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)" @ install -u root
;;
3)
echo "
install_path
installed: /etc/systemd/system/xray.service
installed: /etc/systemd/system/xray@.service
installed: /usr/local/bin/xray
installed: /usr/local/etc/xray/*.json
installed: /usr/local/share/xray/geoip.dat
installed: /usr/local/share/xray/geosite.dat
installed: /var/log/xray/access.log
installed: /var/log/xray/error.log
link_path:/usr/link.vms
cert_path:/root/cert
xy_command:
xray run -c /usr/local/etc/xray/*.json
systemctl start xray.service
systemctl status xray.service
"
;;
4)
bash -c "$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)" @ install -u root
confirm "确认xray安裝成功,準備申請cloudfare證書[y/n]" "y"
if [ $? -eq 0 ]; then
echo "xray安裝成功,開始申請cloudfare證書"
else
exit
fi
ssl_cert_issue_by_cloudflare
confirm "确认證書安裝成功,準備配置cfg[y/n]" "y"
if [ $? -eq 0 ]; then
echo "證書申請成功,開始配置config"
else
exit
fi
cof_json
confirm "确认配置成功,準備重啓xy" "y"
if [ $? -eq 0 ]; then
echo "重啓xy"
else
exit
fi
systemctl restart xray.service
echo "xy restart"
;;
5)
systemctl stop xray.service
echo "xy stop"
;;
6)
systemctl restart xray.service
echo "xy restart"
;;
7)
systemctl start xray.service
echo "xy start"
;;
8)
bash -c "$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)" @ install-geodata
echo "upgrade_geodat"
;;
9)
echo && read -p "remaind cfg.json and log?
1.remaind
2.don't remaind
" num2
case "${num2}" in
1)
bash -c "$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)" @ remove
echo "only remove x_corn"
;;
2)
bash -c "$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)" @ remove --purge
echo "remove all"
;;
*)
echo "err num"
exit
;;
esac
;;
*)
LOGE "err num"
exit
;;
esac
main
}
main