forked from jinwyp/one_click_script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trojan_v2ray_install100.sh
5181 lines (4134 loc) · 186 KB
/
trojan_v2ray_install100.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
export LC_ALL=C
#export LANG=C
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
if [[ $(/usr/bin/id -u) -ne 0 ]]; then
sudoCmd="sudo"
else
sudoCmd=""
fi
uninstall() {
${sudoCmd} $(which rm) -rf $1
printf "File or Folder Deleted: %s\n" $1
}
# fonts color
red(){
echo -e "\033[31m\033[01m$1\033[0m"
}
green(){
echo -e "\033[32m\033[01m$1\033[0m"
}
yellow(){
echo -e "\033[33m\033[01m$1\033[0m"
}
blue(){
echo -e "\033[34m\033[01m$1\033[0m"
}
bold(){
echo -e "\033[1m\033[01m$1\033[0m"
}
osCPU="intel"
osArchitecture="arm"
osInfo=""
osRelease=""
osReleaseVersion=""
osReleaseVersionNo=""
osReleaseVersionCodeName="CodeName"
osSystemPackage=""
osSystemMdPath=""
osSystemShell="bash"
function checkArchitecture(){
# https://stackoverflow.com/questions/48678152/how-to-detect-386-amd64-arm-or-arm64-os-architecture-via-shell-bash
case $(uname -m) in
i386) osArchitecture="386" ;;
i686) osArchitecture="386" ;;
x86_64) osArchitecture="amd64" ;;
arm) dpkg --print-architecture | grep -q "arm64" && osArchitecture="arm64" || osArchitecture="arm" ;;
* ) osArchitecture="arm" ;;
esac
}
function checkCPU(){
osCPUText=$(cat /proc/cpuinfo | grep vendor_id | uniq)
if [[ $osCPUText =~ "GenuineIntel" ]]; then
osCPU="intel"
else
osCPU="amd"
fi
# green " Status 状态显示--当前CPU是: $osCPU"
}
# 检测系统发行版代号
function getLinuxOSRelease(){
if [[ -f /etc/redhat-release ]]; then
osRelease="centos"
osSystemPackage="yum"
osSystemMdPath="/usr/lib/systemd/system/"
osReleaseVersionCodeName=""
elif cat /etc/issue | grep -Eqi "debian|raspbian"; then
osRelease="debian"
osSystemPackage="apt-get"
osSystemMdPath="/lib/systemd/system/"
osReleaseVersionCodeName="buster"
elif cat /etc/issue | grep -Eqi "ubuntu"; then
osRelease="ubuntu"
osSystemPackage="apt-get"
osSystemMdPath="/lib/systemd/system/"
osReleaseVersionCodeName="bionic"
elif cat /etc/issue | grep -Eqi "centos|red hat|redhat"; then
osRelease="centos"
osSystemPackage="yum"
osSystemMdPath="/usr/lib/systemd/system/"
osReleaseVersionCodeName=""
elif cat /proc/version | grep -Eqi "debian|raspbian"; then
osRelease="debian"
osSystemPackage="apt-get"
osSystemMdPath="/lib/systemd/system/"
osReleaseVersionCodeName="buster"
elif cat /proc/version | grep -Eqi "ubuntu"; then
osRelease="ubuntu"
osSystemPackage="apt-get"
osSystemMdPath="/lib/systemd/system/"
osReleaseVersionCodeName="bionic"
elif cat /proc/version | grep -Eqi "centos|red hat|redhat"; then
osRelease="centos"
osSystemPackage="yum"
osSystemMdPath="/usr/lib/systemd/system/"
osReleaseVersionCodeName=""
fi
getLinuxOSVersion
checkArchitecture
checkCPU
[[ -z $(echo $SHELL|grep zsh) ]] && osSystemShell="bash" || osSystemShell="zsh"
green " 系统信息: ${osInfo}, ${osRelease}, ${osReleaseVersion}, ${osReleaseVersionNo}, ${osReleaseVersionCodeName}, ${osCPU} CPU ${osArchitecture}, ${osSystemShell}, ${osSystemPackage}, ${osSystemMdPath}"
}
# 检测系统版本号
getLinuxOSVersion(){
if [[ -s /etc/redhat-release ]]; then
osReleaseVersion=$(grep -oE '[0-9.]+' /etc/redhat-release)
else
osReleaseVersion=$(grep -oE '[0-9.]+' /etc/issue)
fi
# https://unix.stackexchange.com/questions/6345/how-can-i-get-distribution-name-and-version-number-in-a-simple-shell-script
if [ -f /etc/os-release ]; then
# freedesktop.org and systemd
source /etc/os-release
osInfo=$NAME
osReleaseVersionNo=$VERSION_ID
if [ -n $VERSION_CODENAME ]; then
osReleaseVersionCodeName=$VERSION_CODENAME
fi
elif type lsb_release >/dev/null 2>&1; then
# linuxbase.org
osInfo=$(lsb_release -si)
osReleaseVersionNo=$(lsb_release -sr)
elif [ -f /etc/lsb-release ]; then
# For some versions of Debian/Ubuntu without lsb_release command
. /etc/lsb-release
osInfo=$DISTRIB_ID
osReleaseVersionNo=$DISTRIB_RELEASE
elif [ -f /etc/debian_version ]; then
# Older Debian/Ubuntu/etc.
osInfo=Debian
osReleaseVersion=$(cat /etc/debian_version)
osReleaseVersionNo=$(sed 's/\..*//' /etc/debian_version)
elif [ -f /etc/redhat-release ]; then
osReleaseVersion=$(grep -oE '[0-9.]+' /etc/redhat-release)
else
# Fall back to uname, e.g. "Linux <version>", also works for BSD, etc.
osInfo=$(uname -s)
osReleaseVersionNo=$(uname -r)
fi
}
osPort80=""
osPort443=""
osSELINUXCheck=""
osSELINUXCheckIsRebootInput=""
function testLinuxPortUsage(){
$osSystemPackage -y install net-tools socat
osPort80=`netstat -tlpn | awk -F '[: ]+' '$1=="tcp"{print $5}' | grep -w 80`
osPort443=`netstat -tlpn | awk -F '[: ]+' '$1=="tcp"{print $5}' | grep -w 443`
if [ -n "$osPort80" ]; then
process80=`netstat -tlpn | awk -F '[: ]+' '$5=="80"{print $9}'`
red "==========================================================="
red "检测到80端口被占用,占用进程为:${process80},本次安装结束"
red "==========================================================="
exit 1
fi
if [ -n "$osPort443" ]; then
process443=`netstat -tlpn | awk -F '[: ]+' '$5=="443"{print $9}'`
red "============================================================="
red "检测到443端口被占用,占用进程为:${process443},本次安装结束"
red "============================================================="
exit 1
fi
osSELINUXCheck=$(grep SELINUX= /etc/selinux/config | grep -v "#")
if [ "$osSELINUXCheck" == "SELINUX=enforcing" ]; then
red "======================================================================="
red "检测到SELinux为开启强制模式状态,为防止申请证书失败,请先重启VPS后,再执行本脚本"
red "======================================================================="
read -p "是否现在重启? 请输入 [Y/n] :" osSELINUXCheckIsRebootInput
[ -z "${osSELINUXCheckIsRebootInput}" ] && osSELINUXCheckIsRebootInput="y"
if [[ $osSELINUXCheckIsRebootInput == [Yy] ]]; then
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
echo -e "VPS 重启中..."
reboot
fi
exit
fi
if [ "$osSELINUXCheck" == "SELINUX=permissive" ]; then
red "======================================================================="
red "检测到SELinux为宽容模式状态,为防止申请证书失败,请先重启VPS后,再执行本脚本"
red "======================================================================="
read -p "是否现在重启? 请输入 [Y/n] :" osSELINUXCheckIsRebootInput
[ -z "${osSELINUXCheckIsRebootInput}" ] && osSELINUXCheckIsRebootInput="y"
if [[ $osSELINUXCheckIsRebootInput == [Yy] ]]; then
sed -i 's/SELINUX=permissive/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
echo -e "VPS 重启中..."
reboot
fi
exit
fi
if [ "$osRelease" == "centos" ]; then
if [[ ${osReleaseVersionNo} == "6" || ${osReleaseVersionNo} == "5" ]]; then
green " =================================================="
red " 本脚本不支持 Centos 6 或 Centos 6 更早的版本"
green " =================================================="
exit
fi
red " 关闭防火墙 firewalld"
${sudoCmd} systemctl stop firewalld
${sudoCmd} systemctl disable firewalld
elif [ "$osRelease" == "ubuntu" ]; then
if [[ ${osReleaseVersionNo} == "14" || ${osReleaseVersionNo} == "12" ]]; then
green " =================================================="
red " 本脚本不支持 Ubuntu 14 或 Ubuntu 14 更早的版本"
green " =================================================="
exit
fi
red " 关闭防火墙 ufw"
${sudoCmd} systemctl stop ufw
${sudoCmd} systemctl disable ufw
elif [ "$osRelease" == "debian" ]; then
$osSystemPackage update -y
fi
}
# 编辑 SSH 公钥 文件用于 免密码登录
function editLinuxLoginWithPublicKey(){
if [ ! -d "${HOME}/ssh" ]; then
mkdir -p ${HOME}/.ssh
fi
vi ${HOME}/.ssh/authorized_keys
}
# 设置SSH root 登录
function setLinuxRootLogin(){
read -p "是否设置允许root登陆(ssh密钥方式 或 密码方式登陆 )? 请输入[Y/n]:" osIsRootLoginInput
osIsRootLoginInput=${osIsRootLoginInput:-Y}
if [[ $osIsRootLoginInput == [Yy] ]]; then
if [ "$osRelease" == "centos" ] || [ "$osRelease" == "debian" ] ; then
${sudoCmd} sed -i 's/#\?PermitRootLogin \(yes\|no\|Yes\|No\|prohibit-password\)/PermitRootLogin yes/g' /etc/ssh/sshd_config
fi
if [ "$osRelease" == "ubuntu" ]; then
${sudoCmd} sed -i 's/#\?PermitRootLogin prohibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config
fi
green "设置允许root登陆成功!"
fi
read -p "是否设置允许root使用密码登陆(上一步请先设置允许root登陆才可以)? 请输入[Y/n]:" osIsRootLoginWithPasswordInput
osIsRootLoginWithPasswordInput=${osIsRootLoginWithPasswordInput:-Y}
if [[ $osIsRootLoginWithPasswordInput == [Yy] ]]; then
sed -i 's/#\?PasswordAuthentication \(yes\|no\)/PasswordAuthentication yes/g' /etc/ssh/sshd_config
green "设置允许root使用密码登陆成功!"
fi
${sudoCmd} sed -i 's/#\?TCPKeepAlive yes/TCPKeepAlive yes/g' /etc/ssh/sshd_config
${sudoCmd} sed -i 's/#\?ClientAliveCountMax 3/ClientAliveCountMax 30/g' /etc/ssh/sshd_config
${sudoCmd} sed -i 's/#\?ClientAliveInterval [0-9]*/ClientAliveInterval 40/g' /etc/ssh/sshd_config
if [ "$osRelease" == "centos" ] ; then
${sudoCmd} service sshd restart
${sudoCmd} systemctl restart sshd
green "设置成功, 请用shell工具软件登陆vps服务器!"
fi
if [ "$osRelease" == "ubuntu" ] || [ "$osRelease" == "debian" ] ; then
${sudoCmd} service ssh restart
${sudoCmd} systemctl restart ssh
green "设置成功, 请用shell工具软件登陆vps服务器!"
fi
# /etc/init.d/ssh restart
}
# 修改SSH 端口号
function changeLinuxSSHPort(){
green " 修改的SSH登陆的端口号, 不要使用常用的端口号. 例如 20|21|23|25|53|69|80|110|443|123!"
read -p "请输入要修改的端口号(必须是纯数字并且在1024~65535之间或22):" osSSHLoginPortInput
osSSHLoginPortInput=${osSSHLoginPortInput:-0}
if [ $osSSHLoginPortInput -eq 22 -o $osSSHLoginPortInput -gt 1024 -a $osSSHLoginPortInput -lt 65535 ]; then
sed -i "s/#\?Port [0-9]*/Port $osSSHLoginPortInput/g" /etc/ssh/sshd_config
if [ "$osRelease" == "centos" ] ; then
if [[ ${osReleaseVersionNo} == "7" ]]; then
yum -y install policycoreutils-python
elif [[ ${osReleaseVersionNo} == "8" ]]; then
yum -y install policycoreutils-python-utils
fi
# semanage port -l
semanage port -a -t ssh_port_t -p tcp $osSSHLoginPortInput
firewall-cmd --permanent --zone=public --add-port=$osSSHLoginPortInput/tcp
firewall-cmd --reload
${sudoCmd} systemctl restart sshd.service
fi
if [ "$osRelease" == "ubuntu" ] || [ "$osRelease" == "debian" ] ; then
semanage port -a -t ssh_port_t -p tcp $osSSHLoginPortInput
sudo ufw allow $osSSHLoginPortInput/tcp
${sudoCmd} service ssh restart
${sudoCmd} systemctl restart ssh
fi
green "设置成功, 请记住设置的端口号 ${osSSHLoginPortInput}!"
green "登陆服务器命令: ssh -p ${osSSHLoginPortInput} [email protected] ip !"
else
echo "输入的端口号错误! 范围: 22,1025~65534"
fi
}
function setLinuxDateZone(){
tempCurrentDateZone=$(date +'%z')
echo
if [[ ${tempCurrentDateZone} == "+0800" ]]; then
yellow "当前时区已经为北京时间 $tempCurrentDateZone | $(date -R) "
else
green " =================================================="
yellow " 当前时区为: $tempCurrentDateZone | $(date -R) "
yellow " 是否设置时区为北京时间 +0800区, 以便cron定时重启脚本按照北京时间运行."
green " =================================================="
# read 默认值 https://stackoverflow.com/questions/2642585/read-a-variable-in-bash-with-a-default-value
read -p "是否设置为北京时间 +0800 时区? 请输入[Y/n]:" osTimezoneInput
osTimezoneInput=${osTimezoneInput:-Y}
if [[ $osTimezoneInput == [Yy] ]]; then
if [[ -f /etc/localtime ]] && [[ -f /usr/share/zoneinfo/Asia/Shanghai ]]; then
mv /etc/localtime /etc/localtime.bak
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
yellow "设置成功! 当前时区已设置为 $(date -R)"
green " =================================================="
fi
fi
fi
echo
}
# 更新本脚本
function upgradeScript(){
wget -Nq --no-check-certificate -O ./trojan_v2ray_install.sh "https://raw.githubusercontent.com/jinwyp/one_click_script/master/trojan_v2ray_install.sh"
green " 本脚本升级成功! "
chmod +x ./trojan_v2ray_install.sh
sleep 2s
exec "./trojan_v2ray_install.sh"
}
# 软件安装
function installSoftDownload(){
if [[ "${osRelease}" == "debian" || "${osRelease}" == "ubuntu" ]]; then
if ! dpkg -l | grep -qw wget; then
${osSystemPackage} -y install wget git unzip
# https://stackoverflow.com/questions/11116704/check-if-vt-x-is-activated-without-having-to-reboot-in-linux
${osSystemPackage} -y install cpu-checker
fi
if ! dpkg -l | grep -qw curl; then
${osSystemPackage} -y install curl git unzip
${osSystemPackage} -y install cpu-checker
fi
elif [[ "${osRelease}" == "centos" ]]; then
if ! rpm -qa | grep -qw wget; then
${osSystemPackage} -y install wget curl git unzip
elif ! rpm -qa | grep -qw git; then
${osSystemPackage} -y install wget curl git unzip
fi
fi
}
function installPackage(){
echo
green " =================================================="
yellow " 开始安装软件"
green " =================================================="
echo
if [ "$osRelease" == "centos" ]; then
# rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
cat > "/etc/yum.repos.d/nginx.repo" <<-EOF
[nginx]
name=nginx repo
baseurl=https://nginx.org/packages/centos/$osReleaseVersionNo/\$basearch/
gpgcheck=0
enabled=1
EOF
if ! rpm -qa | grep -qw iperf3; then
${sudoCmd} ${osSystemPackage} install -y epel-release
${osSystemPackage} install -y curl wget git unzip zip tar
${osSystemPackage} install -y xz jq redhat-lsb-core
${osSystemPackage} install -y iputils
${osSystemPackage} install -y iperf3
fi
${osSystemPackage} update -y
# https://www.cyberciti.biz/faq/how-to-install-and-use-nginx-on-centos-8/
if [[ ${osReleaseVersionNo} == "8" ]]; then
${sudoCmd} yum module -y reset nginx
${sudoCmd} yum module -y enable nginx:1.18
${sudoCmd} yum module list nginx
fi
elif [ "$osRelease" == "ubuntu" ]; then
# https://joshtronic.com/2018/12/17/how-to-install-the-latest-nginx-on-debian-and-ubuntu/
# https://www.nginx.com/resources/wiki/start/topics/tutorials/install/
$osSystemPackage install -y gnupg2
wget -O - https://nginx.org/keys/nginx_signing.key | ${sudoCmd} apt-key add -
cat > "/etc/apt/sources.list.d/nginx.list" <<-EOF
deb https://nginx.org/packages/ubuntu/ $osReleaseVersionCodeName nginx
deb-src https://nginx.org/packages/ubuntu/ $osReleaseVersionCodeName nginx
EOF
${osSystemPackage} update -y
if ! dpkg -l | grep -qw iperf3; then
${sudoCmd} ${osSystemPackage} install -y software-properties-common
${osSystemPackage} install -y curl wget git unzip zip tar
${osSystemPackage} install -y xz-utils jq lsb-core lsb-release
${osSystemPackage} install -y iputils-ping
${osSystemPackage} install -y iperf3
fi
elif [ "$osRelease" == "debian" ]; then
# ${sudoCmd} add-apt-repository ppa:nginx/stable -y
${osSystemPackage} install -y gnupg2
wget -O - https://nginx.org/keys/nginx_signing.key | ${sudoCmd} apt-key add -
# curl -L https://nginx.org/keys/nginx_signing.key | ${sudoCmd} apt-key add -
cat > "/etc/apt/sources.list.d/nginx.list" <<-EOF
deb http://nginx.org/packages/debian/ $osReleaseVersionCodeName nginx
deb-src http://nginx.org/packages/debian/ $osReleaseVersionCodeName nginx
EOF
${osSystemPackage} update -y
if ! dpkg -l | grep -qw iperf3; then
${osSystemPackage} install -y curl wget git unzip zip tar
${osSystemPackage} install -y xz-utils jq lsb-core lsb-release
${osSystemPackage} install -y iputils-ping
${osSystemPackage} install -y iperf3
fi
fi
}
function installSoftEditor(){
# 安装 micro 编辑器
if [[ ! -f "${HOME}/bin/micro" ]] ; then
mkdir -p ${HOME}/bin
cd ${HOME}/bin
curl https://getmic.ro | bash
cp ${HOME}/bin/micro /usr/local/bin
green " =================================================="
green " micro 编辑器 安装成功!"
green " =================================================="
fi
if [ "$osRelease" == "centos" ]; then
$osSystemPackage install -y xz vim-minimal vim-enhanced vim-common
else
$osSystemPackage install -y vim-gui-common vim-runtime vim
fi
# 设置vim 中文乱码
if [[ ! -d "${HOME}/.vimrc" ]] ; then
cat > "${HOME}/.vimrc" <<-EOF
set fileencodings=utf-8,gb2312,gb18030,gbk,ucs-bom,cp936,latin1
set enc=utf8
set fencs=utf8,gbk,gb2312,gb18030
syntax on
colorscheme elflord
if has('mouse')
se mouse+=a
set number
endif
EOF
fi
}
function installSoftOhMyZsh(){
echo
green " =================================================="
yellow " 开始安装 ZSH"
green " =================================================="
echo
if [ "$osRelease" == "centos" ]; then
${sudoCmd} $osSystemPackage install zsh -y
$osSystemPackage install util-linux-user -y
elif [ "$osRelease" == "ubuntu" ]; then
${sudoCmd} $osSystemPackage install zsh -y
elif [ "$osRelease" == "debian" ]; then
${sudoCmd} $osSystemPackage install zsh -y
fi
green " =================================================="
green " ZSH 安装成功"
green " =================================================="
# 安装 oh-my-zsh
if [[ ! -d "${HOME}/.oh-my-zsh" ]] ; then
green " =================================================="
yellow " 开始安装 oh-my-zsh"
green " =================================================="
curl -Lo ${HOME}/ohmyzsh_install.sh https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh
chmod +x ${HOME}/ohmyzsh_install.sh
sh ${HOME}/ohmyzsh_install.sh --unattended
fi
if [[ ! -d "${HOME}/.oh-my-zsh/custom/plugins/zsh-autosuggestions" ]] ; then
git clone "https://github.com/zsh-users/zsh-autosuggestions" "${HOME}/.oh-my-zsh/custom/plugins/zsh-autosuggestions"
# 配置 zshrc 文件
zshConfig=${HOME}/.zshrc
zshTheme="maran"
sed -i 's/ZSH_THEME=.*/ZSH_THEME="'"${zshTheme}"'"/' $zshConfig
sed -i 's/plugins=(git)/plugins=(git cp history z rsync colorize nvm zsh-autosuggestions)/' $zshConfig
zshAutosuggestionsConfig=${HOME}/.oh-my-zsh/custom/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
sed -i "s/ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=8'/ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=1'/" $zshAutosuggestionsConfig
# Actually change the default shell to zsh
zsh=$(which zsh)
if ! chsh -s "$zsh"; then
red "chsh command unsuccessful. Change your default shell manually."
else
export SHELL="$zsh"
green "===== Shell successfully changed to '$zsh'."
fi
echo 'alias lla="ls -ahl"' >> ${HOME}/.zshrc
echo 'alias mi="micro"' >> ${HOME}/.zshrc
green " =================================================="
yellow " oh-my-zsh 安装成功, 请用exit命令退出服务器后重新登陆即可!"
green " =================================================="
fi
}
# 网络测速
function vps_netflix(){
# bash <(curl -sSL https://raw.githubusercontent.com/Netflixxp/NF/main/nf.sh)
# bash <(curl -sSL "https://github.com/CoiaPrant/Netflix_Unlock_Information/raw/main/netflix.sh")
# bash <(curl -L -s https://raw.githubusercontent.com/lmc999/RegionRestrictionCheck/main/check.sh)
# wget -N --no-check-certificate https://github.com/CoiaPrant/Netflix_Unlock_Information/raw/main/netflix.sh && chmod +x netflix.sh && ./netflix.sh
# wget -N --no-check-certificate -O netflixcheck https://github.com/sjlleo/netflix-verify/releases/download/2.61/nf_2.61_linux_amd64 && chmod +x ./netflixcheck && ./netflixcheck -method full
wget -N --no-check-certificate -O ./netflix.sh https://github.com/CoiaPrant/MediaUnlock_Test/raw/main/check.sh && chmod +x ./netflix.sh && ./netflix.sh
}
function vps_netflix2(){
wget -N --no-check-certificate -O ./netflix.sh https://github.com/lmc999/RegionRestrictionCheck/raw/main/check.sh && chmod +x ./netflix.sh && ./netflix.sh
}
function vps_netflixgo(){
wget -N --no-check-certificate -O netflixcheck https://github.com/sjlleo/netflix-verify/releases/download/2.61/nf_2.61_linux_amd64 && chmod +x ./netflixcheck && ./netflixcheck -method full
}
function vps_superspeed(){
bash <(curl -Lso- https://git.io/superspeed)
#wget -N --no-check-certificate https://raw.githubusercontent.com/ernisn/superspeed/master/superspeed.sh && chmod +x superspeed.sh && ./superspeed.sh
}
function vps_bench(){
wget -N --no-check-certificate https://raw.githubusercontent.com/teddysun/across/master/bench.sh && chmod +x bench.sh && bash bench.sh
}
function vps_zbench(){
wget -N --no-check-certificate https://raw.githubusercontent.com/FunctionClub/ZBench/master/ZBench-CN.sh && chmod +x ZBench-CN.sh && bash ZBench-CN.sh
}
function vps_testrace(){
wget -N --no-check-certificate https://raw.githubusercontent.com/nanqinlang-script/testrace/master/testrace.sh && chmod +x testrace.sh && ./testrace.sh
}
function vps_LemonBench(){
wget -O LemonBench.sh -N --no-check-certificate https://ilemonra.in/LemonBenchIntl && chmod +x LemonBench.sh && ./LemonBench.sh fast
}
function installBBR(){
wget -O tcp_old.sh -N --no-check-certificate "https://raw.githubusercontent.com/chiakge/Linux-NetSpeed/master/tcp.sh" && chmod +x tcp_old.sh && ./tcp_old.sh
}
function installBBR2(){
if [[ -f ./tcp.sh ]]; then
mv ./tcp.sh ./tcp_old.sh
fi
wget -N --no-check-certificate "https://raw.githubusercontent.com/ylx2016/Linux-NetSpeed/master/tcp.sh" && chmod +x tcp.sh && ./tcp.sh
}
function installWireguard(){
bash <(wget -qO- https://github.com/jinwyp/one_click_script/raw/master/install_kernel.sh)
# wget -N --no-check-certificate https://github.com/jinwyp/one_click_script/raw/master/install_kernel.sh && chmod +x ./install_kernel.sh && ./install_kernel.sh
}
function installBTPanel(){
if [ "$osRelease" == "centos" ]; then
yum install -y wget && wget -O install.sh http://download.bt.cn/install/install_6.0.sh && sh install.sh
else
# curl -sSO http://download.bt.cn/install/install_panel.sh && bash install_panel.sh
wget -O install.sh http://download.bt.cn/install/install-ubuntu_6.0.sh && sudo bash install.sh
fi
}
function installBTPanelCrack(){
if [ "$osRelease" == "centos" ]; then
yum install -y wget && wget -O install.sh https://download.fenhao.me/install/install_6.0.sh && sh install.sh
else
wget -O install.sh https://download.fenhao.me/install/install-ubuntu_6.0.sh && sudo bash install.sh
fi
}
function installBTPanelCrack2(){
if [ "$osRelease" == "centos" ]; then
yum install -y wget && wget -O install.sh http://v7.hostcli.com/install/install_6.0.sh && sh install.sh
else
wget -O install.sh http://v7.hostcli.com/install/install-ubuntu_6.0.sh && sudo bash install.sh
fi
}
configNetworkRealIp=""
configNetworkLocalIp=""
configSSLDomain=""
configSSLAcmeScriptPath="${HOME}/.acme.sh"
configWebsiteFatherPath="${HOME}/website"
configSSLCertBakPath="${HOME}/sslbackup"
configSSLCertPath="${HOME}/website/cert"
configSSLCertKeyFilename="private.key"
configSSLCertFullchainFilename="fullchain.cer"
configWebsitePath="${HOME}/website/html"
configTrojanWindowsCliPrefixPath=$(cat /dev/urandom | head -1 | md5sum | head -c 20)
configWebsiteDownloadPath="${configWebsitePath}/download/${configTrojanWindowsCliPrefixPath}"
configDownloadTempPath="${HOME}/temp"
configRanPath="${HOME}/ran"
versionTrojan="1.16.0"
downloadFilenameTrojan="trojan-${versionTrojan}-linux-amd64.tar.xz"
versionTrojanGo="0.10.5"
downloadFilenameTrojanGo="trojan-go-linux-amd64.zip"
versionV2ray="4.41.1"
downloadFilenameV2ray="v2ray-linux-64.zip"
versionXray="1.4.2"
downloadFilenameXray="Xray-linux-64.zip"
versionTrojanWeb="2.10.5"
downloadFilenameTrojanWeb="trojan-linux-amd64"
promptInfoTrojanName=""
isTrojanGo="no"
isTrojanGoSupportWebsocket="false"
configTrojanGoWebSocketPath=$(cat /dev/urandom | head -1 | md5sum | head -c 8)
configTrojanPasswordPrefixInput="jin"
configTrojanPath="${HOME}/trojan"
configTrojanGoPath="${HOME}/trojan-go"
configTrojanWebPath="${HOME}/trojan-web"
configTrojanLogFile="${HOME}/trojan-access.log"
configTrojanGoLogFile="${HOME}/trojan-go-access.log"
configTrojanBasePath=${configTrojanPath}
configTrojanBaseVersion=${versionTrojan}
configTrojanWebNginxPath=$(cat /dev/urandom | head -1 | md5sum | head -c 5)
configTrojanWebPort="$(($RANDOM + 10000))"
isInstallNginx="true"
isNginxWithSSL="no"
nginxConfigPath="/etc/nginx/nginx.conf"
nginxAccessLogFilePath="${HOME}/nginx-access.log"
nginxErrorLogFilePath="${HOME}/nginx-error.log"
promptInfoXrayInstall="V2ray"
promptInfoXrayVersion=""
promptInfoXrayName="v2ray"
isXray="no"
configV2rayWebSocketPath=$(cat /dev/urandom | head -1 | md5sum | head -c 8)
configV2rayGRPCServiceName=$(cat /dev/urandom | head -1 | md5sum | head -c 8)
configV2rayPort="$(($RANDOM + 10000))"
configV2rayGRPCPort="$(($RANDOM + 10000))"
configV2rayVmesWSPort="$(($RANDOM + 10000))"
configV2rayVmessTCPPort="$(($RANDOM + 10000))"
configV2rayPortShowInfo=$configV2rayPort
configV2rayPortGRPCShowInfo=$configV2rayGRPCPort
configV2rayIsTlsShowInfo="tls"
configV2rayTrojanPort="$(($RANDOM + 10000))"
configV2rayPath="${HOME}/v2ray"
configV2rayAccessLogFilePath="${HOME}/v2ray-access.log"
configV2rayErrorLogFilePath="${HOME}/v2ray-error.log"
configV2rayProtocol="vmess"
configV2rayVlessMode=""
configV2rayWSorGrpc="ws"
configReadme=${HOME}/readme_trojan_v2ray.txt
function downloadAndUnzip(){
if [ -z $1 ]; then
green " ================================================== "
green " 下载文件地址为空!"
green " ================================================== "
exit
fi
if [ -z $2 ]; then
green " ================================================== "
green " 目标路径地址为空!"
green " ================================================== "
exit
fi
if [ -z $3 ]; then
green " ================================================== "
green " 下载文件的文件名为空!"
green " ================================================== "
exit
fi
mkdir -p ${configDownloadTempPath}
if [[ $3 == *"tar.xz"* ]]; then
green "===== 下载并解压tar文件: $3 "
wget -O ${configDownloadTempPath}/$3 $1
tar xf ${configDownloadTempPath}/$3 -C ${configDownloadTempPath}
mv ${configDownloadTempPath}/trojan/* $2
rm -rf ${configDownloadTempPath}/trojan
else
green "===== 下载并解压zip文件: $3 "
wget -O ${configDownloadTempPath}/$3 $1
unzip -d $2 ${configDownloadTempPath}/$3
fi
}
function getGithubLatestReleaseVersion(){
# https://github.com/p4gefau1t/trojan-go/issues/63
wget --no-check-certificate -qO- https://api.github.com/repos/$1/tags | grep 'name' | cut -d\" -f4 | head -1 | cut -b 2-
}
function getTrojanAndV2rayVersion(){
# https://github.com/trojan-gfw/trojan/releases/download/v1.16.0/trojan-1.16.0-linux-amd64.tar.xz
echo ""
if [[ $1 == "trojan" ]] ; then
versionTrojan=$(getGithubLatestReleaseVersion "trojan-gfw/trojan")
downloadFilenameTrojan="trojan-${versionTrojan}-linux-amd64.tar.xz"
echo "versionTrojan: ${versionTrojan}"
fi
if [[ $1 == "trojan-go" ]] ; then
versionTrojanGo=$(getGithubLatestReleaseVersion "p4gefau1t/trojan-go")
echo "versionTrojanGo: ${versionTrojanGo}"
fi
if [[ $1 == "v2ray" ]] ; then
versionV2ray=$(getGithubLatestReleaseVersion "v2fly/v2ray-core")
echo "versionV2ray: ${versionV2ray}"
fi
if [[ $1 == "xray" ]] ; then
versionXray=$(getGithubLatestReleaseVersion "XTLS/Xray-core")
echo "versionXray: ${versionXray}"
fi
if [[ $1 == "trojan-web" ]] ; then
versionTrojanWeb=$(getGithubLatestReleaseVersion "Jrohy/trojan")
echo "versionTrojanWeb: ${versionTrojanWeb}"
fi
if [[ $1 == "wgcf" ]] ; then
versionWgcf=$(getGithubLatestReleaseVersion "ViRb3/wgcf")
downloadFilenameWgcf="wgcf_${versionWgcf}_linux_amd64"
echo "versionWgcf: ${versionWgcf}"
fi
}
function stopServiceNginx(){
serviceNginxStatus=`ps -aux | grep "nginx: worker" | grep -v "grep"`
if [[ -n "$serviceNginxStatus" ]]; then
${sudoCmd} systemctl stop nginx.service
fi
}
function stopServiceV2ray(){
if [[ -f "${osSystemMdPath}v2ray.service" ]] || [[ -f "/etc/systemd/system/v2ray.service" ]] || [[ -f "/lib/systemd/system/v2ray.service" ]] ; then
${sudoCmd} systemctl stop v2ray.service
fi
}
function isTrojanGoInstall(){
if [ "$isTrojanGo" = "yes" ] ; then
getTrojanAndV2rayVersion "trojan-go"
configTrojanBaseVersion=${versionTrojanGo}
configTrojanBasePath="${configTrojanGoPath}"
promptInfoTrojanName="-go"
else
getTrojanAndV2rayVersion "trojan"
configTrojanBaseVersion=${versionTrojan}
configTrojanBasePath="${configTrojanPath}"
promptInfoTrojanName=""
fi
}
function compareRealIpWithLocalIp(){
echo
echo
green " 是否检测域名指向的IP正确 (默认检测,如果域名指向的IP不是本机器IP则无法继续. 如果已开启CDN不方便关闭可以选择否)"
read -p "是否检测域名指向的IP正确? 请输入[Y/n]:" isDomainValidInput
isDomainValidInput=${isDomainValidInput:-Y}
if [[ $isDomainValidInput == [Yy] ]]; then
if [ -n $1 ]; then
configNetworkRealIp=`ping $1 -c 1 | sed '1{s/[^(]*(//;s/).*//;q}'`
# configNetworkLocalIp=`curl ipv4.icanhazip.com`
configNetworkLocalIp=`curl v4.ident.me`
green " ================================================== "
green " 域名解析地址为 ${configNetworkRealIp}, 本VPS的IP为 ${configNetworkLocalIp}. "
green " ================================================== "
if [[ ${configNetworkRealIp} == ${configNetworkLocalIp} ]] ; then
green " ================================================== "
green " 域名解析的IP正常!"
green " ================================================== "
true
else
green " ================================================== "
red " 域名解析地址与本VPS IP地址不一致!"
red " 本次安装失败,请确保域名解析正常, 请检查域名和DNS是否生效!"
green " ================================================== "
false
fi
else
green " ================================================== "
red " 域名输入错误!"
green " ================================================== "
false
fi
else
green " ================================================== "