forked from ak47229527/Xray-TLS-Web-setup-script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathXray-TLS+Web-setup.sh
4096 lines (3996 loc) · 168 KB
/
Xray-TLS+Web-setup.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
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
#系统信息
#指令集
machine=""
#什么系统
release=""
#系统版本号
systemVersion=""
debian_package_manager=""
redhat_package_manager=""
redhat_package_manager_enhanced=""
#CPU线程数
cpu_thread_num=""
#现在有没有通过脚本启动swap
using_swap_now=0
#系统时区
timezone=""
#安装信息
nginx_version="nginx-1.25.2"
openssl_version="openssl-openssl-3.0.8" #use ssl LTS
nginx_prefix="/usr/local/nginx"
nginx_config="${nginx_prefix}/conf.d/xray.conf"
nginx_service="/etc/systemd/system/nginx.service"
nginx_is_installed=""
php_version="php-8.2.5"
php_prefix="/usr/local/php"
php_service="/etc/systemd/system/php-fpm.service"
php_is_installed=""
cloudreve_version="3.8.2"
cloudreve_prefix="/usr/local/cloudreve"
cloudreve_service="/etc/systemd/system/cloudreve.service"
cloudreve_is_installed=""
nextcloud_url="https://download.nextcloud.com/server/releases/latest-master.zip"
xray_config="/usr/local/etc/xray/config.json"
xray_is_installed=""
temp_dir="/temp_install_update_xray_tls_web"
is_installed=""
update=""
in_install_update_xray_tls_web=0
#配置信息
#域名列表 两个列表用来区别 www.主域名
unset domain_list
unset true_domain_list
unset domain_config_list
#域名伪装列表,对应域名列表
unset pretend_list
# TCP使用的会话层协议,0代表禁用,1代表VLESS
protocol_1=""
# grpc使用的会话层协议,0代表禁用,1代表VLESS,2代表VMess
protocol_2=""
# WebSocket使用的会话层协议,0代表禁用,1代表VLESS,2代表VMess
protocol_3=""
serviceName=""
path=""
xid_1=""
xid_2=""
xid_3=""
#功能性函数:
#定义几个颜色
purple() #基佬紫
{
echo -e "\\033[35;1m${*}\\033[0m"
}
tyblue() #天依蓝
{
echo -e "\\033[36;1m${*}\\033[0m"
}
green() #原谅绿
{
echo -e "\\033[32;1m${*}\\033[0m"
}
yellow() #鸭屎黄
{
echo -e "\\033[33;1m${*}\\033[0m"
}
red() #姨妈红
{
echo -e "\\033[31;1m${*}\\033[0m"
}
blue() #蓝色
{
echo -e "\\033[34;1m${*}\\033[0m"
}
#检查基本命令
check_base_command()
{
hash -r
local i
local temp_command_list=('bash' 'sh' 'command' 'type' 'hash' 'install' 'true' 'false' 'exit' 'echo' 'test' 'sort' 'sed' 'awk' 'grep' 'cut' 'cd' 'rm' 'cp' 'mv' 'head' 'tail' 'uname' 'tr' 'md5sum' 'cat' 'find' 'wc' 'ls' 'mktemp' 'swapon' 'swapoff' 'mkswap' 'chmod' 'chown' 'chgrp' 'export' 'tar' 'gzip' 'mkdir' 'arch' 'uniq')
for i in "${temp_command_list[@]}"
do
if ! command -V "${i}" > /dev/null; then
red "命令\"${i}\"未找到"
red "不是标准的Linux系统"
exit 1
fi
done
}
check_sudo()
{
if [ "$SUDO_GID" ] && [ "$SUDO_COMMAND" ] && [ "$SUDO_USER" ] && [ "$SUDO_UID" ]; then
if [ "$SUDO_USER" = "root" ] && [ "$SUDO_UID" = "0" ]; then
#it's root using sudo, no matter it's using sudo or not, just fine
return 0
fi
if [ -n "$SUDO_COMMAND" ]; then
#it's a normal user doing "sudo su", or `sudo -i` or `sudo -s`, or `sudo su acmeuser1`
echo "$SUDO_COMMAND" | grep -- "/bin/su\$" >/dev/null 2>&1 || echo "$SUDO_COMMAND" | grep -- "/bin/su " >/dev/null 2>&1 || grep "^$SUDO_COMMAND\$" /etc/shells >/dev/null 2>&1
return $?
fi
#otherwise
return 1
fi
return 0
}
#版本比较函数
version_ge()
{
test "$(echo -e "$1\\n$2" | sort -rV | head -n 1)" == "$1"
}
#检查脚本更新
check_script_update()
{
[ "$(md5sum "${BASH_SOURCE[0]}" | awk '{print $1}')" == "$(md5sum <(wget -O - "https://github.com/Lostsite/Xray-script/raw/main/Xray-TLS+Web-setup.sh") | awk '{print $1}')" ] && return 1 || return 0
}
#更新脚本
update_script()
{
if wget -O "${BASH_SOURCE[0]}" "https://github.com/Lostsite/Xray-script/raw/main/Xray-TLS+Web-setup.sh" || wget -O "${BASH_SOURCE[0]}" "https://github.com/Lostsite/Xray-script/raw/main/Xray-TLS+Web-setup.sh"; then
green "脚本更新完成,请重新运行脚本!"
exit 0
else
red "更新脚本失败!"
exit 1
fi
}
ask_update_script()
{
if check_script_update; then
green "脚本可升级"
ask_if "是否升级脚本?(y/n)" && update_script
else
green "脚本已经是最新版本"
fi
}
ask_update_script_force()
{
if check_script_update; then
green "脚本可升级"
if ask_if "是否升级脚本?(y/n)"; then
update_script
else
red "请先更新脚本"
exit 0
fi
else
green "脚本已经是最新版本"
fi
}
redhat_install()
{
if $redhat_package_manager_enhanced install "$@"; then
return 0
fi
if $redhat_package_manager --help | grep -q "\\-\\-enablerepo="; then
local enable_repo="--enablerepo="
else
local enable_repo="--enablerepo "
fi
if $redhat_package_manager --help | grep -q "\\-\\-disablerepo="; then
local disable_repo="--disablerepo="
else
local disable_repo="--disablerepo "
fi
if [ $release == centos-stream ]; then
local epel_repo="epel,epel-next"
elif [ $release == oracle ]; then
if version_ge "$systemVersion" 9; then
local epel_repo="ol9_developer_EPEL"
elif version_ge "$systemVersion" 8; then
local epel_repo="ol8_developer_EPEL"
elif version_ge "$systemVersion" 7; then
local epel_repo="ol7_developer_EPEL"
else
local epel_repo="epel"
fi
else
local epel_repo="epel"
fi
if [ $release == fedora ]; then
if $redhat_package_manager_enhanced ${enable_repo}"remi" install "$@"; then
return 0
fi
else
if $redhat_package_manager_enhanced ${enable_repo}"${epel_repo}" install "$@"; then
return 0
fi
if $redhat_package_manager_enhanced ${enable_repo}"${epel_repo},powertools" install "$@" || $redhat_package_manager_enhanced ${enable_repo}"${epel_repo},PowerTools" install "$@"; then
return 0
fi
fi
if $redhat_package_manager_enhanced ${enable_repo}"*" ${disable_repo}"*-debug,*-debuginfo,*-source" install "$@"; then
return 0
fi
if $redhat_package_manager_enhanced ${enable_repo}"*" install "$@"; then
return 0
fi
return 1
}
#安装单个重要依赖
test_important_dependence_installed()
{
local temp_exit_code=1
if [ $release == "ubuntu" ] || [ $release == "debian" ] || [ $release == "deepin" ] || [ $release == "other-debian" ]; then
if LANG="en_US.UTF-8" LANGUAGE="en_US:en" dpkg -s "$1" 2>/dev/null | grep -qi 'status[ '$'\t]*:[ '$'\t]*install[ '$'\t]*ok[ '$'\t]*installed[ '$'\t]*$'; then
if LANG="en_US.UTF-8" LANGUAGE="en_US:en" apt-mark manual "$1" | grep -qi 'set[ '$'\t]*to[ '$'\t]*manually[ '$'\t]*installed'; then
temp_exit_code=0
else
red "安装依赖 \"$1\" 出错!"
green "欢迎进行Bug report(https://github.com/kirin10000/Xray-script/issues),感谢您的支持"
yellow "按回车键继续或者Ctrl+c退出"
read -s
fi
elif $debian_package_manager -y --no-install-recommends install "$1"; then
temp_exit_code=0
else
$debian_package_manager update
$debian_package_manager -y -f install
$debian_package_manager -y --no-install-recommends install "$1" && temp_exit_code=0
fi
else
if rpm -q "$2" > /dev/null 2>&1; then
if [ "$redhat_package_manager" == "dnf" ]; then
dnf mark install "$2" && temp_exit_code=0
else
yumdb set reason user "$2" && temp_exit_code=0
fi
elif redhat_install "$2"; then
temp_exit_code=0
fi
fi
return $temp_exit_code
}
check_important_dependence_installed()
{
if ! test_important_dependence_installed "$@"; then
if [ $release == "ubuntu" ] || [ $release == "debian" ] || [ $release == "deepin" ] || [ $release == "other-debian" ]; then
red "重要组件\"$1\"安装失败!!"
else
red "重要组件\"$2\"安装失败!!"
fi
yellow "按回车键继续或者Ctrl+c退出"
read -s
fi
}
#安装依赖
install_dependence()
{
if [ $release == "ubuntu" ] || [ $release == "debian" ] || [ $release == "deepin" ] || [ $release == "other-debian" ]; then
if ! $debian_package_manager -y --no-install-recommends install "$@"; then
$debian_package_manager update
$debian_package_manager -y -f install
if ! $debian_package_manager -y --no-install-recommends install "$@"; then
yellow "依赖安装失败!!"
green "欢迎进行Bug report(https://github.com/kirin10000/Xray-script/issues),感谢您的支持"
yellow "按回车键继续或者Ctrl+c退出"
read -s
fi
fi
else
if ! redhat_install "$@"; then
yellow "依赖安装失败!!"
green "欢迎进行Bug report(https://github.com/kirin10000/Xray-script/issues),感谢您的支持"
yellow "按回车键继续或者Ctrl+c退出"
read -s
fi
fi
}
#安装epel源
install_epel()
{
if [ $release == "ubuntu" ] || [ $release == "debian" ] || [ $release == "deepin" ] || [ $release == "other-debian" ]; then
return
fi
local ret=0
if [ $release == fedora ]; then
return
elif [ $release == centos-stream ]; then
if version_ge "$systemVersion" 10; then
ret=-1
elif version_ge "$systemVersion" 9; then
check_important_dependence_installed "" dnf-plugins-core
dnf config-manager --set-enabled crb || ret=-1
redhat_install "https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm" "https://dl.fedoraproject.org/pub/epel/epel-next-release-latest-9.noarch.rpm" || ret=-1
elif version_ge "$systemVersion" 8; then
check_important_dependence_installed "" dnf-plugins-core
dnf config-manager --set-enabled powertools || dnf config-manager --set-enabled PowerTools || ret=-1
redhat_install epel-release epel-next-release || ret=-1
else
ret=-1
fi
elif [ $release == centos ]; then
if version_ge "$systemVersion" 9; then
ret=-1
elif version_ge "$systemVersion" 8; then
check_important_dependence_installed "" dnf-plugins-core
dnf config-manager --set-enabled powertools || dnf config-manager --set-enabled PowerTools || ret=-1
redhat_install epel-release || ret=-1
elif version_ge "$systemVersion" 7; then
redhat_install epel-release || ret=-1
elif version_ge "$systemVersion" 6; then
redhat_install epel-release || ret=-1
else
ret=-1
fi
elif [ $release == oracle ]; then
if version_ge "$systemVersion" 9; then
ret=-1
elif version_ge "$systemVersion" 8; then
redhat_install oracle-epel-release-el8 || ret=-1
elif version_ge "$systemVersion" 7; then
redhat_install oracle-epel-release-el7 || ret=-1
else
ret=-1
fi
elif [ $release == rhel ]; then
if version_ge "$systemVersion" 9; then
ret=-1
elif version_ge "$systemVersion" 8; then
subscription-manager repos --enable "codeready-builder-for-rhel-8-$(arch)-rpms" || ret=-1
redhat_install "https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm" || ret=-1
elif version_ge "$systemVersion" 7; then
subscription-manager repos --enable "rhel-*-optional-rpms" --enable "rhel-*-extras-rpms" --enable "rhel-ha-for-rhel-*-server-rpms" || ret=-1
redhat_install "https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm" || ret=-1
else
ret=-1
fi
else
if [ $redhat_package_manager == dnf ]; then
check_important_dependence_installed "" dnf-plugins-core
dnf config-manager --set-enabled powertools || dnf config-manager --set-enabled PowerTools
fi
redhat_install epel-release || ret=-1
fi
if [ $ret -ne 0 ]; then
if [ $release == other-redhat ]; then
if $redhat_package_manager repolist epel | grep -q epel; then
return
fi
yellow "epel源安装失败,这可能导致之后的安装失败,也可能没有影响(取决于你的系统的repo包含软件是否丰富)"
echo
tyblue "除了安装epel源过程出错,也有可能是因为你使用的系统比较冷门导致安装失败"
tyblue "这种情况下可以手动安装epel源,之后重新运行脚本"
else
yellow "epel源安装失败!!"
fi
echo
green "欢迎进行Bug report(https://github.com/kirin10000/Xray-script/issues),感谢您的支持"
yellow "按回车键继续或者Ctrl+c退出"
read -s
fi
}
fedora_install_remi()
{
if [ $release != fedora ]; then
return
fi
if ! redhat_install "https://rpms.remirepo.net/fedora/remi-release-$systemVersion.rpm"; then
yellow "remi源安装失败!!"
green "欢迎进行Bug report(https://github.com/kirin10000/Xray-script/issues),感谢您的支持"
yellow "按回车键继续或者Ctrl+c退出"
read -s
fi
}
#进入工作目录
enter_temp_dir()
{
local temp_exit_code=0
cd / || temp_exit_code=1
rm -rf "$temp_dir" || temp_exit_code=1
mkdir "$temp_dir" || temp_exit_code=1
cd "$temp_dir" || temp_exit_code=1
if [ $temp_exit_code -eq 1 ]; then
yellow "进入临时目录失败"
tyblue "可能是之前运行脚本中断导致,建议先重启系统,再运行脚本"
exit 1
fi
}
#检查是否需要
check_need_php()
{
[ $is_installed -eq 0 ] && return 1
local i
for i in "${pretend_list[@]}"
do
[ "$i" == "2" ] && return 0
done
return 1
}
#检查是否需要cloudreve
check_need_cloudreve()
{
[ $is_installed -eq 0 ] && return 1
local i
for i in "${pretend_list[@]}"
do
[ "$i" == "1" ] && return 0
done
return 1
}
#检查Nginx更新
check_nginx_update()
{
local nginx_version_now
local openssl_version_now
nginx_version_now="nginx-$(${nginx_prefix}/sbin/nginx -V 2>&1 | grep "^nginx version:" | cut -d / -f 2)"
openssl_version_now="openssl-openssl-$(${nginx_prefix}/sbin/nginx -V 2>&1 | grep "^built with OpenSSL" | awk '{print $4}')"
if [ "$nginx_version_now" == "$nginx_version" ] && [ "$openssl_version_now" == "$openssl_version" ]; then
return 1
else
return 0
fi
}
#检查php更新
check_php_update()
{
local php_version_now
php_version_now="php-$(${php_prefix}/bin/php -v | head -n 1 | awk '{print $2}')"
[ "$php_version_now" == "$php_version" ] && return 1
return 0
}
swap_on()
{
if [ $using_swap_now -ne 0 ]; then
red "开启swap错误发生"
green "欢迎进行Bug report(https://github.com/kirin10000/Xray-script/issues),感谢您的支持"
yellow "按回车键继续或者Ctrl+c退出"
read -s
fi
local need_swap_size=$(( $1+$(free -m | sed -n 2p | awk '{print $3}')+$(free -m | sed -n 3p | awk '{print $3}')-$(free -m | sed -n 2p | awk '{print $2}')-$(free -m | sed -n 3p | awk '{print $2}') ))
if [ $need_swap_size -gt 0 ]; then
tyblue "可用内存不足$1M,自动申请swap。。"
if dd if=/dev/zero of=${temp_dir}/swap bs=1M count=$need_swap_size && chmod 0600 ${temp_dir}/swap && mkswap ${temp_dir}/swap && swapon ${temp_dir}/swap; then
using_swap_now=1
else
rm -rf ${temp_dir}/swap
red "开启swap失败!"
yellow "可能是机器内存和硬盘空间都不足"
green "欢迎进行Bug report(https://github.com/kirin10000/Xray-script/issues),感谢您的支持"
yellow "按回车键继续或者Ctrl+c退出"
read -s
fi
fi
}
swap_off()
{
if [ $using_swap_now -eq 1 ]; then
tyblue "正在恢复swap。。。"
if swapoff ${temp_dir}/swap && rm -rf ${temp_dir}/swap; then
using_swap_now=0
else
red "关闭swap失败!"
green "欢迎进行Bug report(https://github.com/kirin10000/Xray-script/issues),感谢您的
支持"
yellow "按回车键继续或者Ctrl+c退出"
read -s
fi
fi
}
#启用/禁用php cloudreve
turn_on_off_php()
{
if check_need_php; then
systemctl start php-fpm
systemctl enable php-fpm
else
systemctl stop php-fpm
systemctl disable php-fpm
fi
}
turn_on_off_cloudreve()
{
if check_need_cloudreve; then
systemctl start cloudreve
systemctl enable cloudreve
else
systemctl stop cloudreve
systemctl disable cloudreve
fi
}
let_change_cloudreve_domain()
{
tyblue "----------- 请打开\"https://${domain_list[$1]}\"修改Cloudreve站点信息 ---------"
tyblue " 1. 登陆帐号"
tyblue " 2. 右上角头像 -> 管理面板"
tyblue " 3. 左侧的参数设置 -> 站点信息"
tyblue " 4. 站点URL改为\"https://${domain_list[$1]}\" -> 往下拉点击保存"
sleep 15s
echo -e "\\n\\n"
tyblue "按两次回车键以继续。。。"
read -s
read -s
}
ask_if()
{
local choice=""
while [ "$choice" != "y" ] && [ "$choice" != "n" ]
do
tyblue "$1"
read choice
done
[ $choice == y ] && return 0
return 1
}
#卸载函数
remove_xray()
{
if ! bash -c "$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)" @ remove --purge; then
systemctl stop xray
systemctl disable xray
rm -rf /usr/local/bin/xray
rm -rf /usr/local/etc/xray
rm -rf /etc/systemd/system/xray.service
rm -rf /etc/systemd/system/[email protected]
rm -rf /var/log/xray
systemctl daemon-reload
fi
xray_is_installed=0
is_installed=0
}
remove_nginx()
{
systemctl stop nginx
systemctl disable nginx
rm -rf $nginx_service
systemctl daemon-reload
rm -rf ${nginx_prefix}
nginx_is_installed=0
is_installed=0
}
remove_php()
{
systemctl stop php-fpm
systemctl disable php-fpm
rm -rf $php_service
systemctl daemon-reload
rm -rf ${php_prefix}
php_is_installed=0
}
remove_cloudreve()
{
systemctl stop cloudreve
systemctl disable cloudreve
rm -rf $cloudreve_service
systemctl daemon-reload
rm -rf ${cloudreve_prefix}
cloudreve_is_installed=0
}
#备份域名伪装网站
backup_domains_web()
{
local i
mkdir "${temp_dir}/domain_backup"
for i in "${true_domain_list[@]}"
do
if [ "$1" == "cp" ]; then
cp -rf "${nginx_prefix}/html/${i}" "${temp_dir}/domain_backup" 2>/dev/null
else
mv "${nginx_prefix}/html/${i}" "${temp_dir}/domain_backup" 2>/dev/null
fi
done
}
#获取配置信息
get_config_info()
{
[ $is_installed -eq 0 ] && return
local temp
if grep -q '"network"[ '$'\t]*:[ '$'\t]*"ws"' $xray_config; then
if [[ "$(grep -E '"protocol"[ '$'\t]*:[ '$'\t]*"(vmess|vless)"' $xray_config | tail -n 1)" =~ \"vmess\" ]]; then
protocol_3=2
else
protocol_3=1
fi
path="$(grep '"path"' $xray_config | tail -n 1 | cut -d : -f 2 | cut -d \" -f 2)"
xid_3="$(grep '"id"' $xray_config | tail -n 1 | cut -d : -f 2 | cut -d \" -f 2)"
else
protocol_3=0
fi
if grep -q '"network"[ '$'\t]*:[ '$'\t]*"grpc"' $xray_config; then
if [ $protocol_3 -ne 0 ]; then
temp=2
else
temp=1
fi
if [[ "$(grep -E '"protocol"[ '$'\t]*:[ '$'\t]*"(vmess|vless)"' $xray_config | tail -n $temp | head -n 1)" =~ \"vmess\" ]]; then
protocol_2=2
else
protocol_2=1
fi
serviceName="$(grep '"serviceName"' $xray_config | cut -d : -f 2 | cut -d \" -f 2)"
xid_2="$(grep '"id"' $xray_config | tail -n $temp | head -n 1 | cut -d : -f 2 | cut -d \" -f 2)"
else
protocol_2=0
fi
temp=1
[ $protocol_2 -ne 0 ] && ((temp++))
[ $protocol_3 -ne 0 ] && ((temp++))
if [ $(grep -c '"clients"' $xray_config) -eq $temp ]; then
protocol_1=1
xid_1="$(grep '"id"' $xray_config | head -n 1 | cut -d : -f 2 | cut -d \" -f 2)"
else
protocol_1=0
fi
unset domain_list
unset true_domain_list
unset domain_config_list
unset pretend_list
domain_list=($(grep "^#domain_list=" $nginx_config | cut -d = -f 2))
true_domain_list=($(grep "^#true_domain_list=" $nginx_config | cut -d = -f 2))
domain_config_list=($(grep "^#domain_config_list=" $nginx_config | cut -d = -f 2))
pretend_list=($(grep "^#pretend_list=" $nginx_config | cut -d = -f 2))
}
gen_cflags()
{
cflags=('-g0' '-O3')
if gcc -v --help 2>&1 | grep -qw "\\-fexceptions"; then
cflags+=('-fno-exceptions')
elif gcc -v --help 2>&1 | grep -qw "\\-fhandle\\-exceptions"; then
cflags+=('-fno-handle-exceptions')
fi
if gcc -v --help 2>&1 | grep -qw "\\-fasynchronous\\-unwind\\-tables"; then
cflags+=('-fno-asynchronous-unwind-tables')
fi
if gcc -v --help 2>&1 | grep -qw "\\-fstack\\-check"; then
cflags+=('-fno-stack-check')
fi
if gcc -v --help 2>&1 | grep -qw "\\-fstack\\-clash\\-protection"; then
cflags+=('-fno-stack-clash-protection')
fi
if gcc -v --help 2>&1 | grep -qw "\\-fstack\\-protector"; then
cflags+=('-fno-stack-protector')
fi
if gcc -v --help 2>&1 | grep -qw "\\-funwind\\-tables"; then
cflags+=('-fno-unwind-tables')
fi
if gcc -v --help 2>&1 | grep -qw "\\-fcf\\-protection="; then
cflags+=('-fcf-protection=none')
fi
if gcc -v --help 2>&1 | grep -qw "\\-fsplit\\-stack"; then
cflags+=('-fno-split-stack')
fi
}
gen_cxxflags()
{
cxxflags=('-g0' '-O3')
if g++ -v --help 2>&1 | grep -qw "\\-fasynchronous\\-unwind\\-tables"; then
cxxflags+=('-fno-asynchronous-unwind-tables')
fi
if g++ -v --help 2>&1 | grep -qw "\\-fstack\\-check"; then
cxxflags+=('-fno-stack-check')
fi
if g++ -v --help 2>&1 | grep -qw "\\-fstack\\-clash\\-protection"; then
cxxflags+=('-fno-stack-clash-protection')
fi
if g++ -v --help 2>&1 | grep -qw "\\-fstack\\-protector"; then
cxxflags+=('-fno-stack-protector')
fi
if g++ -v --help 2>&1 | grep -qw "\\-funwind\\-tables"; then
cxxflags+=('-fno-unwind-tables')
fi
if g++ -v --help 2>&1 | grep -qw "\\-fcf\\-protection="; then
cxxflags+=('-fcf-protection=none')
fi
if g++ -v --help 2>&1 | grep -qw "\\-fsplit\\-stack"; then
cxxflags+=('-fno-split-stack')
fi
}
check_base_command
if [[ ! -f '/etc/os-release' ]]; then
red "系统版本太老,Xray官方脚本不支持"
exit 1
fi
if [[ -f /.dockerenv ]] || grep -q 'docker\|lxc' /proc/1/cgroup && [[ "$(type -P systemctl)" ]]; then
true
elif [[ -d /run/systemd/system ]] || grep -q systemd <(ls -l /sbin/init); then
true
else
red "仅支持使用systemd的系统!"
exit 1
fi
if [[ ! -d /dev/shm ]]; then
red "/dev/shm不存在,不支持的系统"
exit 1
fi
if [[ "$(type -P apt)" ]]; then
if [[ "$(type -P dnf)" ]] || [[ "$(type -P yum)" ]]; then
red "同时存在apt和yum/dnf"
red "不支持的系统!"
exit 1
fi
release="other-debian"
debian_package_manager="apt"
redhat_package_manager="true"
redhat_package_manager_enhanced="true"
elif [[ "$(type -P dnf)" ]]; then
release="other-redhat"
redhat_package_manager="dnf"
debian_package_manager="true"
if $redhat_package_manager --help | grep -q "\\-\\-setopt="; then
redhat_package_manager_enhanced="$redhat_package_manager -y --setopt=install_weak_deps=False"
else
redhat_package_manager_enhanced="$redhat_package_manager -y --setopt install_weak_deps=False"
fi
elif [[ "$(type -P yum)" ]]; then
release="other-redhat"
redhat_package_manager="yum"
debian_package_manager="true"
if $redhat_package_manager --help | grep -q "\\-\\-setopt="; then
redhat_package_manager_enhanced="$redhat_package_manager -y --setopt=install_weak_deps=False"
else
redhat_package_manager_enhanced="$redhat_package_manager -y --setopt install_weak_deps=False"
fi
else
red "apt yum dnf命令均不存在"
red "不支持的系统"
exit 1
fi
if [[ -z "${BASH_SOURCE[0]}" ]]; then
red "请以文件的形式运行脚本,或不支持的bash版本"
exit 1
fi
if [ "$EUID" != "0" ]; then
red "请用root用户运行此脚本!!"
exit 1
fi
if ! check_sudo; then
yellow "检测到正在使用sudo!"
yellow "acme.sh不支持sudo,请使用root用户运行此脚本"
tyblue "详情请见:https://github.com/acmesh-official/acme.sh/wiki/sudo"
exit 1
fi
[ -e $nginx_config ] && nginx_is_installed=1 || nginx_is_installed=0
[ -e ${php_prefix}/php-fpm.service.default ] && php_is_installed=1 || php_is_installed=0
[ -e ${cloudreve_prefix}/cloudreve.db ] && cloudreve_is_installed=1 || cloudreve_is_installed=0
[ -e /usr/local/bin/xray ] && xray_is_installed=1 || xray_is_installed=0
([ $xray_is_installed -eq 1 ] && [ $nginx_is_installed -eq 1 ]) && is_installed=1 || is_installed=0
cpu_thread_num="$(grep '^processor' /proc/cpuinfo | uniq | wc -l)"
if [ -z "$cpu_thread_num" ] || [ $cpu_thread_num -lt 1 ]; then
red "获取CPU线程数失败!"
exit 1
fi
case "$(uname -m)" in
'amd64' | 'x86_64')
machine='amd64'
;;
'armv5tel' | 'armv6l' | 'armv7' | 'armv7l')
machine='arm'
;;
'armv8' | 'aarch64')
machine='arm64'
;;
*)
machine=''
;;
esac
#获取系统版本信息
get_system_info()
{
timezone="$(ls -l /etc/localtime | awk -F zoneinfo/ '{print $NF}')"
if [[ ! -L /etc/localtime ]] || [ "$timezone" == "" ]; then
yellow "获取时区失败!"
green "欢迎进行Bug report(https://github.com/kirin10000/Xray-script/issues),感谢您的支持"
yellow "按回车键继续或者Ctrl+c退出"
read -s
fi
if bash -c "echo $(grep '^[ '$'\t]*ID[ '$'\t]*=' /etc/os-release | cut -d = -f 2-)" | grep -qiw ubuntu; then
release="ubuntu"
elif bash -c "echo $(grep '^[ '$'\t]*ID[ '$'\t]*=' /etc/os-release | cut -d = -f 2-)" | grep -qiw debian; then
release="debian"
elif bash -c "echo $(grep '^[ '$'\t]*ID[ '$'\t]*=' /etc/os-release | cut -d = -f 2-)" | grep -qiw deepin; then
release="deepin"
elif bash -c "echo $(grep '^[ '$'\t]*ID[ '$'\t]*=' /etc/os-release | cut -d = -f 2-)" | grep -qiw centos; then
if bash -c "echo $(grep '^[ '$'\t]*NAME[ '$'\t]*=' /etc/os-release | cut -d = -f 2-)" | grep -qiw stream; then
release="centos-stream"
else
release="centos"
fi
elif bash -c "echo $(grep '^[ '$'\t]*ID[ '$'\t]*=' /etc/os-release | cut -d = -f 2-)" | grep -qiw fedora; then
release="fedora"
elif bash -c "echo $(grep '^[ '$'\t]*NAME[ '$'\t]*=' /etc/os-release | cut -d = -f 2-)" | grep -qiw oracle; then
release="oracle"
elif bash -c "echo $(grep '^[ '$'\t]*ID[ '$'\t]*=' /etc/os-release | cut -d = -f 2-)" | grep -qiw rhel; then
release="rhel"
elif bash -c "echo $(grep '^[ '$'\t]*ID[ '$'\t]*=' /etc/os-release | cut -d = -f 2-)" | grep -qiw redhatenterprise; then
release="rhel"
fi
systemVersion="$(bash -c "echo $(grep '^[ '$'\t]*VERSION_ID[ '$'\t]*=' /etc/os-release | cut -d = -f 2-)")"
if [ "$(bash -c "echo $(grep '^[ '$'\t]*ID[ '$'\t]*=' /etc/os-release | cut -d = -f 2-)")" == "" ] || [ "$systemVersion" == "" ]; then
yellow "获取系统信息失败!"
green "欢迎进行Bug report(https://github.com/kirin10000/Xray-script/issues),感谢您的支持"
yellow "按回车键继续或者Ctrl+c退出"
read -s
fi
}
#检查TCP 80端口和443端口是否被占用
check_port()
{
green "正在检查端口占用。。。"
local xray_status=0
local nginx_status=0
systemctl -q is-active xray && xray_status=1 && systemctl stop xray
systemctl -q is-active nginx && nginx_status=1 && systemctl stop nginx
([ $xray_status -eq 1 ] || [ $nginx_status -eq 1 ]) && sleep 2s
local check_list=('80' '443')
local i
for i in "${check_list[@]}"
do
if ss -natl | awk '{print $4}' | awk -F : '{print $NF}' | grep -E "^[0-9]+$" | grep -wq "${i}"; then
red "TCP:${i}端口被占用!"
yellow "请用 lsof -i:${i} 命令检查"
exit 1
fi
done
[ $xray_status -eq 1 ] && systemctl start xray
[ $nginx_status -eq 1 ] && systemctl start nginx
}
#检查Nginx是否已通过apt/dnf/yum安装
check_nginx_installed_system()
{
if [[ ! -f /usr/lib/systemd/system/nginx.service ]] && [[ ! -f /lib/systemd/system/nginx.service ]]; then
return 0
fi
red "------------检测到Nginx已安装,并且会与此脚本冲突------------"
yellow " 如果您不记得之前有安装过Nginx,那么可能是使用别的一键脚本时安装的"
yellow " 建议使用纯净的系统运行此脚本"
echo
! ask_if "是否尝试卸载?(y/n)" && exit 0
$debian_package_manager -y purge '^nginx' '^libnginx'
$redhat_package_manager -y remove 'nginx*'
if [[ ! -f /usr/lib/systemd/system/nginx.service ]] && [[ ! -f /lib/systemd/system/nginx.service ]]; then
return 0
fi
red "卸载失败!"
yellow "请尝试更换系统,建议使用Ubuntu最新版系统"
green "欢迎进行Bug report(https://github.com/kirin10000/Xray-script/issues),感谢您的支持"
exit 1
}
#检查SELinux
check_SELinux()
{
turn_off_selinux()
{
if command -V setenforce >/dev/null 2>&1; then
local selinux_utils_is_installed=1
else
local selinux_utils_is_installed=0
check_important_dependence_installed selinux-utils libselinux-utils
fi
setenforce 0
sed -i 's/^[ \t]*SELINUX[ \t]*=[ \t]*enforcing[ \t]*$/SELINUX=disabled/g' /etc/sysconfig/selinux
sed -i 's/^[ \t]*SELINUX[ \t]*=[ \t]*enforcing[ \t]*$/SELINUX=disabled/g' /etc/selinux/config
if [ $selinux_utils_is_installed -eq 0 ]; then
$redhat_package_manager -y remove libselinux-utils
$debian_package_manager -y purge selinux-utils
fi
}
if getenforce 2>/dev/null | grep -wqi Enforcing || grep -Eq '^[ '$'\t]*SELINUX[ '$'\t]*=[ '$'\t]*enforcing[ '$'\t]*$' /etc/sysconfig/selinux 2>/dev/null || grep -Eq '^[ '$'\t]*SELINUX[ '$'\t]*=[ '$'\t]*enforcing[ '$'\t]*$' /etc/selinux/config 2>/dev/null; then
yellow "检测到SELinux已开启,脚本可能无法正常运行"
if ask_if "尝试关闭SELinux?(y/n)"; then
turn_off_selinux
else
exit 0
fi
fi
}
#配置sshd
check_ssh_timeout()
{
if grep -q "#This file has been edited by Xray-TLS-Web-setup-script" /etc/ssh/sshd_config; then
return 0
fi
echo -e "\\n\\n\\n"
tyblue "------------------------------------------"
tyblue " 安装可能需要比较长的时间"
tyblue " 如果中途断开连接将会很麻烦"
tyblue " 设置ssh连接超时时间将有效降低断连可能性"
echo
! ask_if "是否设置ssh连接超时时间?(y/n)" && return 0
sed -i '/^[ \t]*ClientAliveInterval[ \t]/d' /etc/ssh/sshd_config
sed -i '/^[ \t]*ClientAliveCountMax[ \t]/d' /etc/ssh/sshd_config
echo >> /etc/ssh/sshd_config
echo "ClientAliveInterval 30" >> /etc/ssh/sshd_config
echo "ClientAliveCountMax 60" >> /etc/ssh/sshd_config
echo "#This file has been edited by Xray-TLS-Web-setup-script" >> /etc/ssh/sshd_config
systemctl restart sshd
green "----------------------配置完成----------------------"
tyblue " 请重新连接服务器以让配置生效"
if [ $in_install_update_xray_tls_web -eq 1 ]; then
yellow " 重新连接服务器后,请再次运行脚本完成剩余部分的安装/升级"
yellow " 再次运行脚本时,重复之前选过的选项即可"
yellow " 按回车键退出。。。。"
read -s
fi
exit 0
}
#删除防火墙和阿里云盾
uninstall_firewall()
{
green "正在删除防火墙。。。"
ufw disable
$debian_package_manager -y purge firewalld
$debian_package_manager -y purge ufw
systemctl stop firewalld
systemctl disable firewalld
$redhat_package_manager -y remove firewalld
green "正在删除阿里云盾和腾讯云盾 (仅对阿里云和腾讯云服务器有效)。。。"
#阿里云盾
pkill -9 assist_daemon
rm -rf /usr/local/share/assist-daemon
systemctl stop CmsGoAgent
systemctl disable CmsGoAgent
systemctl stop cloudmonitor
/etc/rc.d/init.d/cloudmonitor remove
rm -rf /usr/local/cloudmonitor
rm -rf /etc/systemd/system/CmsGoAgent.service
systemctl daemon-reload
#aliyun-assist
systemctl stop AssistDaemon
systemctl disable AssistDaemon
systemctl stop aliyun
systemctl disable aliyun
$debian_package_manager -y purge aliyun-assist
$redhat_package_manager -y remove aliyun_assist
rm -rf /usr/local/share/aliyun-assist
rm -rf /usr/sbin/aliyun_installer
rm -rf /usr/sbin/aliyun-service
rm -rf /usr/sbin/aliyun-service.backup
rm -rf /etc/systemd/system/aliyun.service
rm -rf /etc/systemd/system/AssistDaemon.service
systemctl daemon-reload
#AliYunDun aegis
pkill -9 AliYunDunUpdate
pkill -9 AliYunDun
pkill -9 AliHids
/etc/init.d/aegis uninstall
rm -rf /usr/local/aegis
rm -rf /etc/init.d/aegis
rm -rf /etc/rc2.d/S80aegis
rm -rf /etc/rc3.d/S80aegis
rm -rf /etc/rc4.d/S80aegis
rm -rf /etc/rc5.d/S80aegis
#腾讯云盾
/usr/local/qcloud/stargate/admin/uninstall.sh
/usr/local/qcloud/YunJing/uninst.sh
/usr/local/qcloud/monitor/barad/admin/uninstall.sh
systemctl daemon-reload
systemctl stop YDService
systemctl disable YDService
rm -rf /lib/systemd/system/YDService.service
systemctl daemon-reload
systemctl stop tat_agent
systemctl disable tat_agent
rm -rf /etc/systemd/system/tat_agent.service
systemctl daemon-reload
sed -i 's#/usr/local/qcloud#rcvtevyy4f5d#g' /etc/rc.local
sed -i '/rcvtevyy4f5d/d' /etc/rc.local
rm -rf $(find /etc/udev/rules.d -iname "*qcloud*" 2>/dev/null)
pkill -9 watchdog.sh
pkill -9 secu-tcs-agent
pkill -9 YDService
pkill -9 YDLive