-
Notifications
You must be signed in to change notification settings - Fork 539
/
Xray-TLS+Web-setup.sh
2142 lines (2073 loc) · 77.6 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
#安装选项
nginx_version="nginx-1.19.5"
openssl_version="openssl-openssl-3.0.0-alpha8"
xray_config="/usr/local/etc/xray/config.json"
nginx_prefix="/etc/nginx"
nginx_config="${nginx_prefix}/conf.d/xray.conf"
nginx_service="/etc/systemd/system/nginx.service"
temp_dir="/temp_install_update_xray_tls_web"
xray_is_installed=""
nginx_is_installed=""
is_installed=""
update=""
#配置信息
unset domain_list
unset domainconfig_list
unset pretend_list
#Xray-TCP-TLS使用的协议,0代表禁用,1代表VLESS
protocol_1=""
#Xray-WS-TLS使用的协议,0代表禁用,1代表VLESS,2代表VMess
protocol_2=""
path=""
xid_1=""
xid_2=""
#系统信息
release=""
systemVersion=""
redhat_package_manager=""
redhat_version=""
mem_ok=""
#定义几个颜色
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"
}
if [ "$EUID" != "0" ]; then
red "请用root用户运行此脚本!!"
exit 1
fi
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 [ "$(cat /proc/meminfo |grep 'MemTotal' |awk '{print $3}' | tr [A-Z] [a-z])" == "kb" ]; then
if [ "$(cat /proc/meminfo |grep 'MemTotal' |awk '{print $2}')" -le 400000 ]; then
mem_ok=0
else
mem_ok=1
fi
else
mem_ok=2
fi
if [ -e /usr/local/bin/xray ]; then
xray_is_installed=1
else
xray_is_installed=0
fi
if [ -e $nginx_config ] || [ -e /etc/nginx/conf.d/v2ray.conf ]; then
nginx_is_installed=1
else
nginx_is_installed=0
fi
if [ $xray_is_installed -eq 1 ] && [ $nginx_is_installed -eq 1 ]; then
is_installed=1
else
is_installed=0
fi
check_important_dependence_installed()
{
if [ $release == "ubuntu" ] || [ $release == "other-debian" ]; then
if ! dpkg -s $1 2>&1 >/dev/null; then
if ! apt -y --no-install-recommends install $1; then
apt update
if ! apt -y --no-install-recommends install $1; then
yellow "重要组件安装失败!!"
red "不支持的系统!!"
exit 1
fi
fi
fi
else
if ! rpm -q $2 2>&1 >/dev/null; then
if ! $redhat_package_manager -y install $2; then
yellow "重要组件安装失败!!"
red "不支持的系统!!"
exit 1
fi
fi
fi
}
version_ge()
{
test "$(echo "$@" | tr " " "\n" | sort -rV | head -n 1)" == "$1"
}
#获取系统信息
get_system_info()
{
if [[ "$(type -P apt)" ]]; then
if [[ "$(type -P dnf)" ]] || [[ "$(type -P yum)" ]]; then
red "同时存在apt和yum/dnf"
red "不支持的系统!"
exit 1
fi
release="other-debian"
redhat_package_manager="true"
elif [[ "$(type -P dnf)" ]]; then
release="other-redhat"
redhat_package_manager="dnf"
elif [[ "$(type -P yum)" ]]; then
release="other-redhat"
redhat_package_manager="yum"
else
red "不支持的系统或apt/yum/dnf缺失"
exit 1
fi
check_important_dependence_installed lsb-release redhat-lsb-core
if lsb_release -a 2>/dev/null | grep -qi "ubuntu"; then
release="ubuntu"
elif lsb_release -a 2>/dev/null | grep -qi "centos"; then
release="centos"
elif lsb_release -a 2>/dev/null | grep -qi "fedora"; then
release="fedora"
fi
systemVersion=`lsb_release -r -s`
if [ $release == "fedora" ]; then
if version_ge $systemVersion 28; then
redhat_version=8
elif version_ge $systemVersion 19; then
redhat_version=7
elif version_ge $systemVersion 12; then
redhat_version=6
else
redhat_version=5
fi
else
redhat_version=$systemVersion
fi
}
#检查SELinux
check_SELinux()
{
turn_off_selinux()
{
check_important_dependence_installed selinux-utils libselinux-utils
setenforce 0
sed -i 's/^[ \t]*SELINUX[ \t]*=[ \t]*enforcing[ \t]*$/SELINUX=disabled/g' /etc/sysconfig/selinux
$redhat_package_manager -y remove libselinux-utils
apt -y purge selinux-utils
}
if getenforce 2>/dev/null | grep -wqi Enforcing || grep -Eq '^[ '$'\t]*SELINUX[ '$'\t]*=[ '$'\t]*enforcing[ '$'\t]*$' /etc/sysconfig/selinux 2>/dev/null; then
yellow "检测到SELinux开启,脚本可能无法正常运行"
choice=""
while [[ "$choice" != "y" && "$choice" != "n" ]]
do
tyblue "尝试关闭SELinux?(y/n)"
read choice
done
if [ $choice == y ]; then
turn_off_selinux
else
exit 0
fi
fi
}
#将域名列表转化为一个数组
get_all_domains()
{
unset all_domains
for ((i=0;i<${#domain_list[@]};i++))
do
if [ ${domainconfig_list[i]} -eq 1 ]; then
all_domains+=("www.${domain_list[i]}")
all_domains+=("${domain_list[i]}")
else
all_domains+=("${domain_list[i]}")
fi
done
}
#配置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 " 安装可能需要比较长的时间(5-40分钟)"
tyblue " 如果中途断开连接将会很麻烦"
tyblue " 设置ssh连接超时时间将有效降低断连可能性"
tyblue "------------------------------------------"
choice=""
while [ "$choice" != "y" -a "$choice" != "n" ]
do
tyblue "是否设置ssh连接超时时间?(y/n)"
read choice
done
if [ $choice == y ]; then
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
service sshd restart
green "----------------------配置完成----------------------"
tyblue " 请重新进行ssh连接(即重新登陆服务器),并再次运行此脚本"
yellow " 按回车键退出。。。。"
read -s
exit 0
fi
}
#删除防火墙和阿里云盾
uninstall_firewall()
{
green "正在删除防火墙。。。"
ufw disable
apt -y purge firewalld
apt -y purge ufw
systemctl stop firewalld
systemctl disable firewalld
$redhat_package_manager -y remove firewalld
green "正在删除阿里云盾和腾讯云盾 (仅对阿里云和腾讯云服务器有效)。。。"
#阿里云盾
if [ $release == "ubuntu" ] || [ $release == "other-debian" ]; then
systemctl stop CmsGoAgent
systemctl disable CmsGoAgent
rm -rf /usr/local/cloudmonitor
rm -rf /etc/systemd/system/CmsGoAgent.service
systemctl daemon-reload
else
systemctl stop cloudmonitor
/etc/rc.d/init.d/cloudmonitor remove
rm -rf /usr/local/cloudmonitor
systemctl daemon-reload
fi
systemctl stop aliyun
systemctl disable aliyun
rm -rf /etc/systemd/system/aliyun.service
systemctl daemon-reload
apt -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
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
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 YDService
pkill -9 YDLive
pkill -9 sgagent
pkill -9 /usr/local/qcloud
pkill -9 barad_agent
rm -rf /usr/local/qcloud
rm -rf /usr/local/yd.socket.client
rm -rf /usr/local/yd.socket.server
mkdir /usr/local/qcloud
mkdir /usr/local/qcloud/action
mkdir /usr/local/qcloud/action/login_banner.sh
mkdir /usr/local/qcloud/action/action.sh
}
#升级系统组件
doupdate()
{
updateSystem()
{
if ! [[ "$(type -P do-release-upgrade)" ]]; then
if ! apt -y --no-install-recommends install ubuntu-release-upgrader-core; then
apt update
if ! apt -y --no-install-recommends install ubuntu-release-upgrader-core; then
red "脚本出错!"
yellow "按回车键继续或者Ctrl+c退出"
read -s
fi
fi
fi
echo -e "\n\n\n"
tyblue "------------------请选择升级系统版本--------------------"
tyblue " 1.最新beta版(现在是21.04)(2020.11)"
tyblue " 2.最新发行版(现在是20.10)(2020.11)"
tyblue " 3.最新LTS版(现在是20.04)(2020.11)"
tyblue "-------------------------版本说明-------------------------"
tyblue " beta版:即测试版"
tyblue " 发行版:即稳定版"
tyblue " LTS版:长期支持版本,可以理解为超级稳定版"
tyblue "-------------------------注意事项-------------------------"
yellow " 1.升级过程中遇到问话/对话框,如果不明白,选择yes/y/第一个选项"
yellow " 2.升级系统完成后将会重启,重启后,请再次运行此脚本完成剩余安装"
yellow " 3.升级系统可能需要15分钟或更久"
yellow " 4.有的时候不能一次性更新到所选择的版本,可能要更新多次"
yellow " 5.升级系统后以下配置可能会恢复系统默认配置:"
yellow " ssh端口 ssh超时时间 bbr加速(恢复到关闭状态)"
tyblue "----------------------------------------------------------"
green " 您现在的系统版本是$systemVersion"
tyblue "----------------------------------------------------------"
echo
choice=""
while [ "$choice" != "1" -a "$choice" != "2" -a "$choice" != "3" ]
do
read -p "您的选择是:" choice
done
if ! [[ "$(cat /etc/ssh/sshd_config | grep -i "^[ \t]*port " | awk '{print $2}')" =~ ^("22"|"")$ ]]; then
red "检测到ssh端口号被修改"
red "升级系统后ssh端口号可能恢复默认值(22)"
yellow "按回车键继续。。。"
read -s
fi
local i
for ((i=0;i<2;i++))
do
sed -i '/^[ \t]*Prompt[ \t]*=/d' /etc/update-manager/release-upgrades
echo 'Prompt=normal' >> /etc/update-manager/release-upgrades
case "$choice" in
1)
do-release-upgrade -d
do-release-upgrade -d
sed -i 's/Prompt=normal/Prompt=lts/' /etc/update-manager/release-upgrades
do-release-upgrade -d
do-release-upgrade -d
sed -i 's/Prompt=lts/Prompt=normal/' /etc/update-manager/release-upgrades
do-release-upgrade
do-release-upgrade
sed -i 's/Prompt=normal/Prompt=lts/' /etc/update-manager/release-upgrades
do-release-upgrade
do-release-upgrade
;;
2)
do-release-upgrade
do-release-upgrade
;;
3)
sed -i 's/Prompt=normal/Prompt=lts/' /etc/update-manager/release-upgrades
do-release-upgrade
do-release-upgrade
;;
esac
if ! version_ge $systemVersion 20.04; then
sed -i 's/Prompt=lts/Prompt=normal/' /etc/update-manager/release-upgrades
do-release-upgrade
do-release-upgrade
fi
apt update
apt -y --auto-remove --purge full-upgrade
done
}
echo -e "\n\n\n"
tyblue "-----------------------是否更新系统组件?-----------------------"
if [ "$release" == "ubuntu" ]; then
green " 1. 更新已安装软件,并升级系统(仅对ubuntu有效)"
green " 2. 仅更新已安装软件"
red " 3. 不更新"
if [ $mem_ok == 2 ]; then
echo
yellow "如果要升级系统,请确保服务器的内存>=512MB"
yellow "否则可能无法开机"
elif [ $mem_ok == 0 ]; then
echo
red "检测到内存过小,升级系统可能导致无法开机,请谨慎选择"
fi
echo
choice=""
while [ "$choice" != "1" -a "$choice" != "2" -a "$choice" != "3" ]
do
read -p "您的选择是:" choice
done
else
green " 1. 仅更新已安装软件"
red " 2. 不更新"
echo
choice=""
while [ "$choice" != "1" -a "$choice" != "2" ]
do
read -p "您的选择是:" choice
done
fi
if [[ "$release" == "ubuntu" && "$choice" == "1" ]]; then
updateSystem
apt -y --purge autoremove
apt clean
elif [[ $release == "ubuntu" && $choice -eq 2 || $choice -eq 1 ]]; then
tyblue "-----------------------即将开始更新-----------------------"
yellow " 更新过程中若有问话/对话框,优先选择yes/y/第一个选项"
yellow " 按回车键继续。。。"
read -s
$redhat_package_manager -y autoremove
$redhat_package_manager -y update
apt update
apt -y --auto-remove --purge full-upgrade
apt -y --purge autoremove
apt clean
$redhat_package_manager -y autoremove
$redhat_package_manager clean all
fi
}
#进入工作目录
enter_temp_dir()
{
rm -rf "$temp_dir"
mkdir "$temp_dir"
cd "$temp_dir"
}
#安装bbr
install_bbr()
{
#输出:latest_kernel_version 和 your_kernel_version
get_kernel_info()
{
green "正在获取最新版本内核版本号。。。。(60内秒未获取成功自动跳过)"
local kernel_list
local kernel_list_temp=($(timeout 60 wget -qO- https://kernel.ubuntu.com/~kernel-ppa/mainline/ | awk -F'\"v' '/v[0-9]/{print $2}' | cut -d '"' -f1 | cut -d '/' -f1 | sort -rV))
if [ ${#kernel_list_temp[@]} -le 1 ]; then
latest_kernel_version="error"
your_kernel_version=`uname -r | cut -d - -f 1`
return 1
fi
local i=0
local i2=0
local i3=0
local kernel_rc=""
local kernel_list_temp2
while ((i2<${#kernel_list_temp[@]}))
do
if [[ "${kernel_list_temp[i2]}" =~ "rc" ]] && [ "$kernel_rc" == "" ]; then
kernel_list_temp2[i3]="${kernel_list_temp[i2]}"
kernel_rc="${kernel_list_temp[i2]%%-*}"
((i3++))
((i2++))
elif [[ "${kernel_list_temp[i2]}" =~ "rc" ]] && [ "${kernel_list_temp[i2]%%-*}" == "$kernel_rc" ]; then
kernel_list_temp2[i3]=${kernel_list_temp[i2]}
((i3++))
((i2++))
elif [[ "${kernel_list_temp[i2]}" =~ "rc" ]] && [ "${kernel_list_temp[i2]%%-*}" != "$kernel_rc" ]; then
for((i3=0;i3<${#kernel_list_temp2[@]};i3++))
do
kernel_list[i]=${kernel_list_temp2[i3]}
((i++))
done
kernel_rc=""
i3=0
unset kernel_list_temp2
elif version_ge "$kernel_rc" "${kernel_list_temp[i2]}"; then
if [ "$kernel_rc" == "${kernel_list_temp[i2]}" ]; then
kernel_list[i]=${kernel_list_temp[i2]}
((i++))
((i2++))
fi
for((i3=0;i3<${#kernel_list_temp2[@]};i3++))
do
kernel_list[i]=${kernel_list_temp2[i3]}
((i++))
done
kernel_rc=""
i3=0
unset kernel_list_temp2
else
kernel_list[i]=${kernel_list_temp[i2]}
((i++))
((i2++))
fi
done
if [ "$kernel_rc" != "" ]; then
for((i3=0;i3<${#kernel_list_temp2[@]};i3++))
do
kernel_list[i]=${kernel_list_temp2[i3]}
((i++))
done
fi
latest_kernel_version=${kernel_list[0]}
your_kernel_version=`uname -r | cut -d - -f 1`
check_fake_version()
{
local temp=${1##*.}
if [ ${temp} -eq 0 ]; then
return 0
else
return 1
fi
}
while check_fake_version ${your_kernel_version}
do
your_kernel_version=${your_kernel_version%.*}
done
if [ $release == "ubuntu" ] || [ $release == "other-debian" ]; then
local rc_version=`uname -r | cut -d - -f 2`
if [[ $rc_version =~ "rc" ]]; then
rc_version=${rc_version##*'rc'}
your_kernel_version=${your_kernel_version}-rc${rc_version}
fi
else
latest_kernel_version=${latest_kernel_version%%-*}
fi
}
#卸载多余内核
remove_other_kernel()
{
if [ $release == "ubuntu" ] || [ $release == "other-debian" ]; then
local kernel_list_image=($(dpkg --list | grep 'linux-image' | awk '{print $2}'))
local kernel_list_modules=($(dpkg --list | grep 'linux-modules' | awk '{print $2}'))
local kernel_now=`uname -r`
local ok_install=0
for ((i=${#kernel_list_image[@]}-1;i>=0;i--))
do
if [[ "${kernel_list_image[$i]}" =~ "$kernel_now" ]]; then
unset kernel_list_image[$i]
((ok_install++))
fi
done
if [ $ok_install -lt 1 ]; then
red "未发现正在使用的内核,可能已经被卸载"
yellow "按回车键继续。。。"
read -s
return 1
fi
ok_install=0
for ((i=${#kernel_list_modules[@]}-1;i>=0;i--))
do
if [[ "${kernel_list_modules[$i]}" =~ "$kernel_now" ]]; then
unset kernel_list_modules[$i]
((ok_install++))
fi
done
if [ $ok_install -lt 1 ]; then
red "未发现正在使用的内核,可能已经被卸载"
yellow "按回车键继续。。。"
read -s
return 1
fi
if [ ${#kernel_list_modules[@]} -eq 0 ] && [ ${#kernel_list_image[@]} -eq 0 ]; then
yellow "没有内核可卸载"
return 0
fi
apt -y purge ${kernel_list_image[@]} ${kernel_list_modules[@]}
else
local kernel_list=($(rpm -qa |grep '^kernel-[0-9]\|^kernel-ml-[0-9]'))
local kernel_list_devel=($(rpm -qa | grep '^kernel-devel\|^kernel-ml-devel'))
if version_ge $redhat_version 8; then
local kernel_list_modules=($(rpm -qa |grep '^kernel-modules\|^kernel-ml-modules'))
local kernel_list_core=($(rpm -qa | grep '^kernel-core\|^kernel-ml-core'))
fi
local kernel_now=`uname -r`
local ok_install=0
for ((i=${#kernel_list[@]}-1;i>=0;i--))
do
if [[ "${kernel_list[$i]}" =~ "$kernel_now" ]]; then
unset kernel_list[$i]
((ok_install++))
fi
done
if [ $ok_install -lt 1 ]; then
red "未发现正在使用的内核,可能已经被卸载"
yellow "按回车键继续。。。"
read -s
return 1
fi
for ((i=${#kernel_list_devel[@]}-1;i>=0;i--))
do
if [[ "${kernel_list_devel[$i]}" =~ "$kernel_now" ]]; then
unset kernel_list_devel[$i]
fi
done
if version_ge $redhat_version 8; then
ok_install=0
for ((i=${#kernel_list_modules[@]}-1;i>=0;i--))
do
if [[ "${kernel_list_modules[$i]}" =~ "$kernel_now" ]]; then
unset kernel_list_modules[$i]
((ok_install++))
fi
done
if [ $ok_install -lt 1 ]; then
red "未发现正在使用的内核,可能已经被卸载"
yellow "按回车键继续。。。"
read -s
return 1
fi
ok_install=0
for ((i=${#kernel_list_core[@]}-1;i>=0;i--))
do
if [[ "${kernel_list_core[$i]}" =~ "$kernel_now" ]]; then
unset kernel_list_core[$i]
((ok_install++))
fi
done
if [ $ok_install -lt 1 ]; then
red "未发现正在使用的内核,可能已经被卸载"
yellow "按回车键继续。。。"
read -s
return 1
fi
fi
if ([ ${#kernel_list[@]} -eq 0 ] && [ ${#kernel_list_devel[@]} -eq 0 ]) && (! version_ge $redhat_version 8 || ([ ${#kernel_list_modules[@]} -eq 0 ] && [ ${#kernel_list_core[@]} -eq 0 ])); then
yellow "没有内核可卸载"
return 0
fi
if version_ge $redhat_version 8; then
$redhat_package_manager -y remove ${kernel_list[@]} ${kernel_list_modules[@]} ${kernel_list_core[@]} ${kernel_list_devel[@]}
else
$redhat_package_manager -y remove ${kernel_list[@]} ${kernel_list_devel[@]}
fi
fi
green "-------------------卸载完成-------------------"
}
local your_kernel_version
local latest_kernel_version
if ! grep -q "#This file has been edited by Xray-TLS-Web-setup-script" /etc/sysctl.conf; then
echo >> /etc/sysctl.conf
echo "#This file has been edited by Xray-TLS-Web-setup-script" >> /etc/sysctl.conf
fi
if [ "$latest_kernel_version" == "" ]; then
get_kernel_info
else
sleep 3s
fi
echo -e "\n\n\n"
tyblue "------------------请选择要使用的bbr版本------------------"
green " 1. 升级最新版内核并启用bbr(推荐)"
if version_ge $your_kernel_version 4.9; then
tyblue " 2. 启用bbr"
else
tyblue " 2. 升级内核启用bbr"
fi
tyblue " 3. 启用bbr2(需更换第三方内核)"
tyblue " 4. 启用bbrplus/bbr魔改版/暴力bbr魔改版/锐速(需更换第三方内核)"
tyblue " 5. 卸载多余内核"
tyblue " 6. 退出bbr安装"
tyblue "------------------关于安装bbr加速的说明------------------"
green " bbr加速可以大幅提升网络速度,建议安装"
yellow " 更换第三方内核可能造成系统不稳定,甚至无法开机"
yellow " 更换/升级内核需重启,重启后,请再次运行此脚本完成剩余安装"
tyblue "---------------------------------------------------------"
tyblue " 当前内核版本:${your_kernel_version}"
tyblue " 最新内核版本:${latest_kernel_version}"
tyblue " 当前内核是否支持bbr:"
if version_ge $your_kernel_version 4.9; then
green " 是"
else
red " 否,需升级内核"
fi
tyblue " bbr启用状态:"
if sysctl net.ipv4.tcp_congestion_control | grep -Eq "bbr|nanqinlang|tsunami"; then
local bbr_info=`sysctl net.ipv4.tcp_congestion_control`
bbr_info=${bbr_info#*=}
if [ $bbr_info == nanqinlang ]; then
bbr_info="暴力bbr魔改版"
elif [ $bbr_info == tsunami ]; then
bbr_info="bbr魔改版"
fi
green " 正在使用:${bbr_info}"
else
red " bbr未启用"
fi
echo
choice=""
while [ "$choice" != "1" -a "$choice" != "2" -a "$choice" != "3" -a "$choice" != "4" -a "$choice" != "5" -a "$choice" != "6" ]
do
read -p "您的选择是:" choice
done
case "$choice" in
1)
sed -i '/^[ \t]*net.core.default_qdisc[ \t]*=/d' /etc/sysctl.conf
sed -i '/^[ \t]*net.ipv4.tcp_congestion_control[ \t]*=/d' /etc/sysctl.conf
echo 'net.core.default_qdisc = fq' >> /etc/sysctl.conf
echo 'net.ipv4.tcp_congestion_control = bbr' >> /etc/sysctl.conf
sysctl -p
if ! wget -O update-kernel.sh https://github.com/kirin10000/update-kernel/raw/master/update-kernel.sh; then
red "获取内核升级脚本失败"
yellow "按回车键继续或者按ctrl+c终止"
read -s
fi
chmod +x update-kernel.sh
./update-kernel.sh
if ! sysctl net.ipv4.tcp_congestion_control | grep -q "bbr"; then
red "开启bbr失败"
red "如果刚安装完内核,请先重启"
red "如果重启仍然无效,请尝试选择2选项"
else
green "--------------------bbr已安装--------------------"
fi
install_bbr
;;
2)
sed -i '/^[ \t]*net.core.default_qdisc[ \t]*=/d' /etc/sysctl.conf
sed -i '/^[ \t]*net.ipv4.tcp_congestion_control[ \t]*=/d' /etc/sysctl.conf
echo 'net.core.default_qdisc = fq' >> /etc/sysctl.conf
echo 'net.ipv4.tcp_congestion_control = bbr' >> /etc/sysctl.conf
sysctl -p
sleep 1s
if ! sysctl net.ipv4.tcp_congestion_control | grep -q "bbr"; then
if ! wget -O bbr.sh https://github.com/teddysun/across/raw/master/bbr.sh; then
red "获取bbr脚本失败"
yellow "按回车键继续或者按ctrl+c终止"
read -s
fi
chmod +x bbr.sh
./bbr.sh
else
green "--------------------bbr已安装--------------------"
fi
install_bbr
;;
3)
tyblue "--------------------即将安装bbr2加速,安装完成后服务器将会重启--------------------"
tyblue " 重启后,请再次选择这个选项完成bbr2剩余部分安装(开启bbr和ECN)"
yellow " 按回车键以继续。。。。"
read -s
if [ $release == "ubuntu" ] || [ $release == "other-debian" ]; then
if ! wget -O bbr2.sh https://github.com/yeyingorg/bbr2.sh/raw/master/bbr2.sh; then
red "获取bbr2脚本失败"
yellow "按回车键继续或者按ctrl+c终止"
read -s
fi
else
if ! wget -O bbr2.sh https://github.com/jackjieYYY/bbr2/raw/master/bbr2.sh; then
red "获取bbr2脚本失败"
yellow "按回车键继续或者按ctrl+c终止"
read -s
fi
fi
chmod +x bbr2.sh
./bbr2.sh
install_bbr
;;
4)
if ! wget -O tcp.sh "https://raw.githubusercontent.com/chiakge/Linux-NetSpeed/master/tcp.sh"; then
red "获取脚本失败"
yellow "按回车键继续或者按ctrl+c终止"
read -s
fi
chmod +x tcp.sh
./tcp.sh
install_bbr
;;
5)
tyblue " 该操作将会卸载除现在正在使用的内核外的其余内核"
tyblue " 您正在使用的内核是:$(uname -r)"
choice=""
while [[ "$choice" != "y" && "$choice" != "n" ]]
do
read -p "是否继续?(y/n)" choice
done
if [ $choice == y ]; then
remove_other_kernel
fi
install_bbr
;;
esac
}
#读取域名
readDomain()
{
check_domain()
{
local temp=${1%%.*}
if [ "$temp" == "www" ]; then
red "域名前面不要带www!"
return 0
elif [ "$1" == "" ]; then
return 0
else
return 1
fi
}
local domain=""
local domainconfig=""
local pretend=""
echo -e "\n\n\n"
tyblue "--------------------请选择域名解析情况--------------------"
tyblue " 1. 一级域名 和 www.一级域名 都解析到此服务器上"
green " 如:123.com 和 www.123.com 都解析到此服务器上"
tyblue " 2. 仅某个域名解析到此服务器上"
green " 如:123.com 或 www.123.com 或 xxx.123.com 中的某一个解析到此服务器上"
echo
while [ "$domainconfig" != "1" -a "$domainconfig" != "2" ]
do
read -p "您的选择是:" domainconfig
done
case "$domainconfig" in
1)
echo
tyblue "--------------------请输入一级域名(不带www.,http,:,/)--------------------"
read -p "请输入域名:" domain
while check_domain $domain
do
read -p "请输入域名:" domain
done
;;
2)
echo
tyblue "----------------请输入解析到此服务器的域名(不带http,:,/)----------------"
read -p "请输入域名:" domain
;;
esac
echo -e "\n\n\n"
tyblue "------------------------------请选择要伪装的网站页面------------------------------"
tyblue " 1. 403页面 (模拟网站后台)"
green " 说明:大型网站几乎都有使用网站后台,比如bilibili的每个视频都是由"
green " 另外一个域名提供的,直接访问那个域名的根目录将返回403或其他错误页面"
tyblue " 2. 镜像腾讯视频网站"
green " 说明:是真镜像站,非链接跳转,默认为腾讯视频,搭建完成后可以自己修改,可能构成侵权"
tyblue " 3. nextcloud登陆页面"
green " 说明:nextclound是开源的私人网盘服务,假装你搭建了一个私人网盘(可以换成别的自定义网站)"
echo
while [[ x"$pretend" != x"1" && x"$pretend" != x"2" && x"$pretend" != x"3" ]]
do
read -p "您的选择是:" pretend
done
domain_list+=("$domain")
domainconfig_list+=("$domainconfig")
pretend_list+=("$pretend")
}
#读取xray_protocol配置
readProtocolConfig()
{
echo -e "\n\n\n"
tyblue "---------------------请选择Xray要使用协议---------------------"
tyblue " 1. (VLESS-TCP+XTLS) + (VMess-WebSocket+TLS) + Web"
green " 适合有时使用CDN,且CDN不可信任(如国内CDN)"
tyblue " 2. (VLESS-TCP+XTLS) + (VLESS-WebSocket+TLS) + Web"
green " 适合有时使用CDN,且CDN可信任"
tyblue " 3. VLESS-TCP+XTLS+Web"
green " 适合完全不用CDN"
tyblue " 4. VMess-WebSocket+TLS+Web"
green " 适合一直使用CDN,且CDN不可信任(如国内CDN)"
tyblue " 5. VLESS-WebSocket+TLS+Web"
green " 适合一直使用CDN,且CDN可信任"
echo
yellow " 注:"
yellow " 1.各协议理论速度对比:https://github.com/badO1a5A90/v2ray-doc/blob/main/performance_test/Xray/speed_test_20201124.md"
yellow " 2.XTLS完全兼容TLS"
yellow " 3.WebSocket协议支持CDN,TCP不支持"
yellow " 4.VLESS协议用于CDN,CDN可以看见传输的明文"
yellow " 5.若不知CDN为何物,请选3"
echo
local mode=""
while [[ "$mode" != "1" && "$mode" != "2" && "$mode" != "3" && "$mode" != "4" && "$mode" != "5" ]]
do
read -p "您的选择是:" mode
done
if [ $mode -eq 1 ]; then
protocol_1=1
protocol_2=2
elif [ $mode -eq 2 ]; then
protocol_1=1
protocol_2=1
elif [ $mode -eq 3 ]; then
protocol_1=1
protocol_2=0
elif [ $mode -eq 4 ]; then
protocol_1=0
protocol_2=2
elif [ $mode -eq 5 ]; then
protocol_1=0
protocol_2=1
fi
}
#备份域名伪装网站
backup_domains_web()
{
local i
mkdir "${temp_dir}/domain_backup"
for i in ${!domain_list[@]}
do
if [ "$1" == "cp" ]; then
cp -rf ${nginx_prefix}/html/${domain_list[i]} "${temp_dir}/domain_backup" 2>/dev/null
else
mv ${nginx_prefix}/html/${domain_list[i]} "${temp_dir}/domain_backup" 2>/dev/null
fi
done
}
#卸载xray和nginx
remove_xray()
{
systemctl stop xray
systemctl disable xray
bash <(curl -L https://raw.githubusercontent.com/XTLS/Xray-install/main/install-release.sh) --remove
rm -rf /usr/local/bin/xray
rm -rf /usr/local/etc/xray
rm -rf /etc/systemd/system/xray.service
rm -rf /etc/systemd/system/xray@.service
systemctl daemon-reload
}
remove_nginx()
{
systemctl stop nginx
${nginx_prefix}/sbin/nginx -s stop
pkill -9 nginx
systemctl disable nginx
rm -rf $nginx_service
systemctl daemon-reload
rm -rf ${nginx_prefix}
}
#安装nignx
install_nginx()
{
green "正在编译和安装nginx。。。。"
if ! wget -O ${nginx_version}.tar.gz https://nginx.org/download/${nginx_version}.tar.gz; then
red "获取nginx失败"
yellow "按回车键继续或者按ctrl+c终止"
read -s
fi
tar -zxf ${nginx_version}.tar.gz
if ! wget -O ${openssl_version}.tar.gz https://github.com/openssl/openssl/archive/${openssl_version#*-}.tar.gz; then
red "获取openssl失败"
yellow "按回车键继续或者按ctrl+c终止"
read -s
fi
tar -zxf ${openssl_version}.tar.gz
cd ${nginx_version}
sed -i "s/OPTIMIZE[ \t]*=>[ \t]*'-O'/OPTIMIZE => '-O3'/g" src/http/modules/perl/Makefile.PL
./configure --prefix=${nginx_prefix} --with-openssl=../$openssl_version --with-openssl-opt="enable-ec_nistp_64_gcc_128 shared threads zlib-dynamic sctp" --with-mail=dynamic --with-mail_ssl_module --with-stream=dynamic --with-stream_ssl_module --with-stream_realip_module --with-stream_geoip_module=dynamic --with-stream_ssl_preread_module --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-pcre --with-libatomic --with-compat --with-cpp_test_module --with-google_perftools_module --with-file-aio --with-threads --with-poll_module --with-select_module --with-cc-opt="-Wno-error -g0 -O3"
if ! make; then
red "nginx编译失败!"
yellow "请尝试更换系统,建议使用Ubuntu最新版系统"
green "欢迎进行Bug report(https://github.com/kirin10000/Xray-TLS-Web-setup-script/issues),感谢您的支持"
exit 1
fi
if [ $update == 1 ]; then
backup_domains_web
fi
remove_nginx
make install
cd ..
}
#安装/更新Xray
install_update_xray()
{
green "正在安装/更新Xray。。。。"
if ! bash <(curl -L https://raw.githubusercontent.com/XTLS/Xray-install/main/install-release.sh) && ! bash <(curl -L https://raw.githubusercontent.com/XTLS/Xray-install/main/install-release.sh); then
red "安装/更新Xray失败"
yellow "按回车键继续或者按ctrl+c终止"
read -s
return 1
fi