-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
690 lines (634 loc) · 21.3 KB
/
install.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
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
#!/bin/bash
red=$(tput setaf 1)
green=$(tput setaf 2)
reset=$(tput sgr0)
configPath='/usr/local/etc/xray/config.json'
nginxPath='/etc/nginx/conf.d/xray.conf'
isRoot() {
if [[ "$EUID" -ne '0' ]]; then
echo "${red}error: You must run this script as root!${reset}"
exit 1
fi
}
isNumber() {
arg="$1"
if [[ "$arg" =~ ^[0-9]+$ ]]; then
return 1
else
return 0
fi
}
identifyOS() {
if [[ "$(uname)" != 'Linux' ]]; then
echo "error: This operating system is not supported."
exit 1
fi
if [[ "$(type -P apt)" ]]; then
PACKAGE_MANAGEMENT_INSTALL='apt -y --no-install-recommends install'
PACKAGE_MANAGEMENT_REMOVE='apt purge -y'
PACKAGE_MANAGEMENT_UPDATE='apt update'
package_provide_tput='ncurses-bin'
elif [[ "$(type -P dnf)" ]]; then
PACKAGE_MANAGEMENT_INSTALL='dnf -y install'
PACKAGE_MANAGEMENT_REMOVE='dnf remove -y'
PACKAGE_MANAGEMENT_UPDATE='dnf update'
package_provide_tput='ncurses'
elif [[ "$(type -P yum)" ]]; then
PACKAGE_MANAGEMENT_INSTALL='yum -y install'
PACKAGE_MANAGEMENT_REMOVE='yum remove -y'
PACKAGE_MANAGEMENT_UPDATE='yum update'
package_provide_tput='ncurses'
${PACKAGE_MANAGEMENT_INSTALL} 'epel-release' &>/dev/null
else
echo "error: The script does not support the package manager in this operating system."
exit 1
fi
}
isCommandExists() {
local command_name="$1"
if command -v "$command_name" &>/dev/null; then
return 0
else
return 1
fi
}
installPackage() {
local package_name="$1"
local required="$2"
if [[ -z $required ]]; then
required=1
fi
if ${PACKAGE_MANAGEMENT_INSTALL} "$package_name" &>/dev/null; then
echo "info: $package_name is installed."
else
echo "${red}error: Installation of $package_name failed, please check your network.${reset}"
if [[ $required -eq 1 ]]; then
exit 1
fi
fi
}
uninstallPackage() {
local package_name="$1"
if ${PACKAGE_MANAGEMENT_REMOVE} "$package_name" &>/dev/null; then
echo "info: $package_name is uninstalled."
else
echo "${red}error: Uninstallation of $package_name failed, please try to uninstall it manually.${reset}"
exit 1
fi
}
configCert() {
systemctl stop nginx
installPackage "socat"
curl https://get.acme.sh | sh -s [email protected]
~/.acme.sh/acme.sh --upgrade --auto-upgrade
if ! ~/.acme.sh/acme.sh --issue --force -d "$userDomain" --standalone; then
echo "${red}error: Failed to issue certificate${reset}"
exit 1
fi
~/.acme.sh/acme.sh --install-cert -d "$userDomain" \
--key-file /etc/nginx/cert/cert.key \
--fullchain-file /etc/nginx/cert/cert.pem
}
installXray() {
echo "info: install Xray."
isCommandExists 'xray' && return
bash -c "$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)" @ install
}
installWarp() {
echo "info: install WARP."
isCommandExists 'warp-cli' && return
if isCommandExists 'apt'; then
curl https://pkg.cloudflareclient.com/pubkey.gpg | gpg --yes --dearmor --output /usr/share/keyrings/cloudflare-warp-archive-keyring.gpg
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/cloudflare-warp-archive-keyring.gpg] https://pkg.cloudflareclient.com/ $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/cloudflare-client.list
elif isCommandExists 'yum'; then
curl -fsSl https://pkg.cloudflareclient.com/cloudflare-warp-ascii.repo | tee /etc/yum.repos.d/cloudflare-warp.repo
else
echo "${red}Your system doesn't support WARP!${reset}"
exit
fi
${PACKAGE_MANAGEMENT_UPDATE}
installPackage "cloudflare-warp"
}
configWarp() {
warp-cli --accept-tos registration new
warp-cli mode proxy
warp-cli connect
sleep 3
curl -x 'socks5://127.0.0.1:40000' 'https://www.cloudflare.com/cdn-cgi/trace/'
}
writeXrayConfig() {
cat >$configPath <<EOF
{
"log": {
"access": "/var/log/xray/access.log",
"error": "/var/log/xray/error.log",
"loglevel": "warning",
"dnsLog": false
},
"inbounds": [
{
"port": $(($1)),
"listen": "127.0.0.1",
"protocol": "vless",
"settings": {
"clients": [
{
"id": "$(cat /proc/sys/kernel/random/uuid)"
}
],
"decryption": "none"
},
"streamSettings": {
"network": "ws",
"security": "none",
"wsSettings": {
"path": "/th1nk"
}
}
}
],
"outbounds": [
{
"tag": "free",
"protocol": "freedom",
"settings": {}
},
{
"tag": "warp",
"protocol": "socks",
"settings": {
"servers": [
{
"address": "127.0.0.1",
"port": 40000
}
]
}
}
],
"routing": {
"domainStrategy": "AsIs",
"rules": [
{
"type": "field",
"domain": [
"domain:openai.com"
],
"outboundTag": "warp"
},
{
"type": "field",
"port": "0-65535",
"outboundTag": "free"
}
]
}
}
EOF
}
getConfigInfo() {
xray_uuid=$(jq -r ".inbounds[0].settings.clients[0].id" $configPath)
xray_addr=$(curl -s 'ip.sb')
xray_streamPath=$(jq -r ".inbounds[0].streamSettings.wsSettings.path" $configPath)
xray_userDomain=$(grep -m 1 -oP "server_name\s+\K\S+" $nginxPath | tr -d ';')
}
writeNginxConfig() {
xrayPort=$(($1))
domain="$2"
proxyUrl="$3"
[ -f '/etc/nginx/sites-enabled/default' ] && rm '/etc/nginx/sites-enabled/default'
setNginxCert
cat >/etc/nginx/nginx.conf <<EOF
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
}
EOF
cat >/etc/nginx/conf.d/default.conf <<EOF
server {
listen 80 default_server;
listen 443 ssl default_server;
ssl_certificate /etc/nginx/cert/default.crt;
ssl_certificate_key /etc/nginx/cert/default.key;
server_name _;
return 444;
}
EOF
cat >$nginxPath <<EOF
server {
listen 443 ssl;
listen [::]:443 ssl;
ssl_certificate /etc/nginx/cert/cert.pem;
ssl_certificate_key /etc/nginx/cert/cert.key;
ssl_session_timeout 1d;
ssl_session_cache shared:MozSSL:10m;
ssl_session_tickets off;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
ssl_prefer_server_ciphers off;
server_name $domain;
location /th1nk {
if (\$http_upgrade != "websocket") {
return 404;
}
proxy_redirect off;
proxy_pass http://127.0.0.1:$xrayPort;
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host \$host;
# Show real IP in xray access.log
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
}
location / {
proxy_ssl_server_name on;
proxy_pass $proxyUrl;
}
}
server{
listen 80;
server_name _;
return 500;
}
# 80 redirect to 443
server {
listen 80;
server_name $domain;
rewrite ^(.*)$ https://\${server_name}\$1 permanent;
}
EOF
}
inputXrayPort() {
read -rp "${green}Please input Xray port(16500 default):${reset}" xrayPort
if [ -z "$xrayPort" ]; then
xrayPort=16500
fi
if ! checkPort; then
inputXrayPort
fi
}
checkPort() {
ss -tuln | grep -q ":$xrayPort\b" && echo "${red}The port $xrayPort has been occupied.${reset}" && return 1
isNumber "$xrayPort"
if [ $? -ne 1 ]; then
echo "${red}the port should be a number.${reset}"
return 1
fi
if [ "$xrayPort" -gt 65535 ] || [ "$xrayPort" -lt 1 ]; then
echo "${red}the port should be 1-65535.${reset}"
return 1
fi
return 0
}
setNginxCert() {
[ ! -d '/etc/nginx/cert' ] && mkdir '/etc/nginx/cert'
cat >/etc/nginx/cert/default.crt <<EOF
-----BEGIN CERTIFICATE-----
MIIDUTCCAjmgAwIBAgIQAK9pm0FrtLk7umWBQEDszzANBgkqhkiG9w0BAQsFADAU
MRIwEAYDVQQDDAlhLmIuYy5jb20wHhcNMjIwOTAzMDI0NTMwWhcNMzIwODMxMDI0
NTMwWjAUMRIwEAYDVQQDDAlhLmIuYy5jb20wggEiMA0GCSqGSIb3DQEBAQUAA4IB
DwAwggEKAoIBAQCQ7jJmeYkk1e+r3/UcEN4VkXH92NyW9Tfp0NA5VJlViCwhmtFo
6vuRVwCXpOUvPUWbpVQZYLyMWBD3xAb2W6LXfKBOR459OGGf4JlExnZWZ+qKoNfQ
T7GZkG9/IQl87A00bOuw34mc0RaStuE7GMR1ZYybphQSkkiFkDP+JSKAnjtNI211
FsFXVy5u6N6avY48QXZnZnKM5WJCxBAI2z5Dg/1uowFWioHJRSxBN5cLXFz2434p
YZFl1Hr/Y4l0Ia1FncATyjKX0H4ycGB/6BYtuHkKNMINwMnecCVtdyYBpHhRN67p
TVtNFEyG9XG40F3ZT3QeBTh3bF5Aqn2yArLHAgMBAAGjgZ4wgZswHQYDVR0OBBYE
FIUhosaI4tZItyUNeb2Ka/UaTSxLMA4GA1UdDwEB/wQEAwIEsDAMBgNVHRMBAf8E
AjAAMDsGA1UdJQQ0MDIGC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F/ZSJuc7+wRS6m+hPH8Y6y5ozMFJ+GJuOUNZ
T6W2nlU9KS6Mpsr8cNJn63g=
-----END PRIVATE KEY-----
EOF
}
inputDomain() {
read -rp "${green}Please input your domain(DO NOT start with 'http/https'):${reset}" userDomain
! checkDomain && inputDomain
}
checkDomain() {
if [[ ! $userDomain =~ ^([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}$ ]]; then
echo "${red}The content you input is not a legal domain!${reset}"
return 1
else
return 0
fi
}
inputProxyUrl() {
read -rp "${green}Please input the proxy url(default https://httpbin.org/):${reset}" proxyUrl
[ -z "$proxyUrl" ] && proxyUrl='https://httpbin.org/'
! checkProxyUrl && inputProxyUrl
}
checkProxyUrl() {
local regex="^https?://[^[:space:]]+$"
if [[ ! $proxyUrl =~ $regex ]]; then
echo "${red}The content you input is not a legal url!${reset}"
return 1
else
return 0
fi
}
getShareUrl() {
getConfigInfo
local shareUrl
shareUrl='vless://'$xray_uuid'@'$xray_addr':443?encryption=none&security=tls&sni='$xray_userDomain'&type=ws&host='$xray_userDomain'&path=%2F'${xray_streamPath:1}'#th1nk-Xray'
echo "$shareUrl"
}
getQrCode() {
isCommandExists 'qrencode'
[ $? -eq 1 ] && installPackage "qrencode"
local url
url=$(getShareUrl)
qrencode -t ANSI "${url}"
echo "${green}$url${reset}"
}
prepareSoftware() {
installPackage "$package_provide_tput"
installPackage "tar"
installPackage "gpg"
installPackage "unzip"
installPackage "nginx"
installPackage "nginx-extras" 0
installPackage "jq"
installXray
installWarp
}
install() {
isRoot
identifyOS
prepareSoftware
if [[ -n $xrayDomain ]];then
inputXrayPort
inputDomain
inputProxyUrl
fi
writeXrayConfig "$xrayPort"
writeNginxConfig "$xrayPort" "$userDomain" "$proxyUrl"
configWarp
configCert
systemctl restart xray nginx
systemctl enable nginx xray
getQrCode
}
modifyXrayUUID() {
jq ".inbounds[0].settings.clients[0].id = \"$(cat /proc/sys/kernel/random/uuid)\"" $configPath >'config.tmp' && mv 'config.tmp' $configPath
echo "${green}$(jq ".inbounds[0].settings.clients[0].id" $configPath)${reset}"
echo 'info: restart Xray.'
systemctl restart xray
}
modifyXrayPort() {
local oldPort
oldPort=$(jq ".inbounds[0].port" $configPath)
echo "info: old port $oldPort"
inputXrayPort
jq ".inbounds[0].port = ${xrayPort}" $configPath >'config.tmp' && mv 'config.tmp' $configPath
sed -i "s/127.0.0.1:${oldPort}/127.0.0.1:${xrayPort}/" $nginxPath
echo "${green}$(jq ".inbounds[0].port" $configPath)${reset}"
echo 'info: restart Xray.'
systemctl restart xray
echo 'info: restart Nginx.'
systemctl restart nginx
}
modifyWsPath() {
local oldPath
oldPath=$(grep -Eo 'location (/[a-zA-Z0-9]+)' $nginxPath | grep -Eo '/[a-zA-Z0-9]+')
echo "info: old websocket path $oldPath"
read -rp "${green}Please input the new websocket path(${red}START WITH /${green}):${reset}" wsPath
[[ ! $wsPath =~ ^/[a-zA-Z0-9]+$ ]] && modifyWsPath
sed -i "s@location /[a-zA-Z0-9]\+@location ${wsPath}@" $nginxPath
jq ".inbounds[0].streamSettings.wsSettings.path = \"$wsPath\"" $configPath >'config.tmp' && mv 'config.tmp' $configPath
echo 'info: restart Xray.'
systemctl restart xray
echo 'info: restart Nginx.'
systemctl restart nginx
}
modifyProxyPassUrl() {
local oldProxyPassUrl
oldProxyPassUrl=$(grep "proxy_pass" $nginxPath | grep -Eo 'https?://[^[:space:]]+' | awk 'NR == 2 {sub(/;$/, "", $0); print}')
echo "info: old proxy pass url $oldProxyPassUrl"
inputProxyUrl
sed -i "s@$oldProxyPassUrl@$proxyUrl@" $nginxPath
echo 'info: restart Nginx.'
systemctl restart nginx
}
addDomainToWarpProxy() {
read -rp "${green}Please input the domain to add to WARP Proxy List(${red}DO NOT START WITH http(s)${green}):${reset}" _proxyUrl
[[ ! $_proxyUrl =~ ^([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}$ ]] && addDomainToWarpProxy
jq ".routing.rules[0].domain += [\"domain:$_proxyUrl\"]" $configPath >'config.tmp' && mv 'config.tmp' $configPath
jq '.routing.rules[0].domain' $configPath
unset _proxyUrl
echo 'info: restart Xray.'
systemctl restart xray
}
deleteDomainFromWarpProxy() {
local _domainList
_domainList=$(jq '.routing.rules[0].domain[]' $configPath)
local _domainListLength
_domainListLength=$(jq '.routing.rules[0].domain | length' $configPath)
[ "$_domainListLength" -eq 0 ] && echo "${red}The WARP Proxy List is empty!${reset}" && return
local i=0
for _domain in $_domainList; do
echo -e "\t[$i]${green}$_domain${reset}"
i=$((i + 1))
done
read -rp "${green}Please input the id of domain you want to delete:${reset}" _domainID
! isNumber _domainID && deleteDomainFromWarpProxy
{ [ "$_domainID" -gt $((_domainListLength - 1)) ] || [ "$_domainID" -lt 0 ]; } && deleteDomainFromWarpProxy
jq "del(.routing.rules[0].domain[$_domainID])" $configPath >'config.tmp' && mv 'config.tmp' $configPath
echo "${red}WARP Proxy List:${reset}"
jq '.routing.rules[0].domain' $configPath
unset _domainID
echo 'info: restart Xray.'
systemctl restart xray
}
menu() {
while getopts ":p:d:P:" opt; do
case $opt in
p)
xrayPort=$OPTARG
if ! checkPort; then
echo "Invalid port: $xrayPort"
exit 1
fi
;;
d)
userDomain=$OPTARG
if ! checkDomain; then
echo "Invalid domain: $userDomain"
exit 1
fi
;;
P)
proxyUrl=$OPTARG
if ! checkProxyUrl; then
echo "Invalid proxy URL: $proxyUrl"
exit 1
fi
;;
\?)
echo "Invalid option: -$OPTARG"
exit 1
;;
esac
done
if [[ -n "$userDomain" ]]; then
if [[ -z "$xrayPort" ]]; then
# default port
xrayPort=16500
if ! checkPort; then
echo "Invalid port: $xrayPort"
exit 1
fi
fi
if [[ -z "$proxyUrl" ]]; then
# default proxy url
proxyUrl="https://httpbin.org"
fi
echo "info: start to install Xray with port $xrayPort, domain $userDomain, proxy pass url $proxyUrl"
install
return
fi
echo -e "\t\t${red}Xray management${reset}"
echo -e "\t\t[[author: th1nk]]"
echo -e "\t—————————————— install ——————————————"
echo -e "\t${green}0.${reset} install Xray(VLESS + WebSocket + TLS + Nginx + WARP)"
echo -e "\t—————————————— modify ——————————————"
echo -e "\t${green}11.${reset} modify Xray UUID"
echo -e "\t${green}12.${reset} modify Xray port"
echo -e "\t${green}13.${reset} modify websocket path"
echo -e "\t${green}14.${reset} modify proxy pass url"
echo -e "\t${green}15.${reset} add domain to WARP proxy"
echo -e "\t${green}16.${reset} remove domain from WARP proxy list"
echo -e "\t—————————————— info ——————————————"
echo -e "\t${green}21.${reset} View Xray access log"
echo -e "\t${green}22.${reset} View Xray error log"
echo -e "\t${green}23.${reset} View nginx access log"
echo -e "\t${green}24.${reset} View nginx error log"
echo -e "\t${green}25.${reset} Generate Xray configuration url and qrcode"
echo -e "\t${green}26.${reset} Show WARP proxy domain list"
echo -e "\t—————————————— other ——————————————"
echo -e "\t${green}31.${reset} update Xray-core"
echo -e "\t${green}32.${reset} uninstall all components"
echo -e "\t${green}33.${reset} restart Xray and nginx"
echo -e "\t—————————————— exit ——————————————"
echo -e "\t${green}100.${reset} exit"
read -rp "Please input number:" num
case $num in
0)
install
;;
11)
modifyXrayUUID
;;
12)
modifyXrayPort
;;
13)
modifyWsPath
;;
14)
modifyProxyPassUrl
;;
15)
addDomainToWarpProxy
;;
16)
deleteDomainFromWarpProxy
;;
21)
tail -f '/var/log/xray/access.log'
;;
22)
tail -f '/var/log/xray/error.log'
;;
23)
tail -f '/var/log/nginx/access.log'
;;
24)
tail -f '/var/log/nginx/error.log'
;;
25)
getQrCode
;;
26)
jq '.routing.rules[0].domain' $configPath
;;
31)
bash -c "$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)" @ install
;;
32)
bash -c "$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)" @ remove
systemctl stop nginx xray
warp-cli disconnect
uninstallPackage 'nginx*'
uninstallPackage 'cloudflare-warp'
;;
33)
echo 'info: restart Xray.'
systemctl restart xray
echo 'info: restart Nginx.'
systemctl restart nginx
;;
100)
exit 0
;;
*)
echo "${red}please input the correct number${reset}"
menu
;;
esac
unset num
}
menu "$@"