forked from laoz77/trojan-gfw-script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrojangui.sh
1980 lines (1938 loc) · 66.8 KB
/
trojangui.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
clear
if [[ $(id -u) != 0 ]]; then
echo Please run this script as root.
exit 1
fi
if [[ -f /etc/init.d/aegis ]] || [[ -f /etc/systemd/system/aliyun.service ]]; then
systemctl stop aegis || true
systemctl disable aegis || true
rm -rf /etc/init.d/aegis || true
systemctl stop aliyun || true
systemctl disable aliyun || true
systemctl stop cloud-config || true
systemctl disable cloud-config || true
systemctl stop cloud-final || true
systemctl disable cloud-final || true
systemctl stop cloud-init-local.service || true
systemctl disable cloud-init-local.service || true
systemctl stop cloud-init || true
systemctl disable cloud-init || true
systemctl stop exim4 || true
systemctl disable exim4 || true
systemctl stop apparmor || true
systemctl disable apparmor || true
rm -rf /etc/systemd/system/aliyun.service || true
rm -rf /lib/systemd/system/cloud-config.service || true
rm -rf /lib/systemd/system/cloud-config.target || true
rm -rf /lib/systemd/system/cloud-final.service || true
rm -rf /lib/systemd/system/cloud-init-local.service || true
rm -rf /lib/systemd/system/cloud-init.service || true
systemctl daemon-reload || true
if [[ $(lsb_release -cs) == stretch ]]; then
cat > '/etc/apt/sources.list' << EOF
#------------------------------------------------------------------------------#
# OFFICIAL DEBIAN REPOS
#------------------------------------------------------------------------------#
###### Debian Main Repos
deb http://deb.debian.org/debian/ oldstable main contrib non-free
deb-src http://deb.debian.org/debian/ oldstable main contrib non-free
deb http://deb.debian.org/debian/ oldstable-updates main contrib non-free
deb-src http://deb.debian.org/debian/ oldstable-updates main contrib non-free
deb http://deb.debian.org/debian-security oldstable/updates main
deb-src http://deb.debian.org/debian-security oldstable/updates main
deb http://ftp.debian.org/debian stretch-backports main
deb-src http://ftp.debian.org/debian stretch-backports main
EOF
fi
if [[ $(lsb_release -cs) == bionic ]]; then
cat > '/etc/apt/sources.list' << EOF
#------------------------------------------------------------------------------#
# OFFICIAL UBUNTU REPOS #
#------------------------------------------------------------------------------#
###### Ubuntu Main Repos
deb http://us.archive.ubuntu.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://us.archive.ubuntu.com/ubuntu/ bionic main restricted universe multiverse
###### Ubuntu Update Repos
deb http://us.archive.ubuntu.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://us.archive.ubuntu.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://us.archive.ubuntu.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://us.archive.ubuntu.com/ubuntu/ bionic-updates main restricted universe multiverse
EOF
echo "nameserver 1.1.1.1" > '/etc/resolv.conf' || true
fi
fi
#######color code############
ERROR="31m" # Error message
SUCCESS="32m" # Success message
WARNING="33m" # Warning message
INFO="36m" # Info message
LINK="92m" # Share Link Message
#############################
cipher_server="ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384"
cipher_client="ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA:AES128-SHA:AES256-SHA:DES-CBC3-SHA"
#############################
colorEcho(){
COLOR=$1
echo -e "\033[${COLOR}${@:2}\033[0m"
}
#########Domain resolve verification###################
isresolved(){
if [ $# = 2 ]
then
myip=$2
else
myip=`curl -s http://dynamicdns.park-your-domain.com/getip`
fi
ips=(`nslookup $1 1.1.1.1 | grep -v 1.1.1.1 | grep Address | cut -d " " -f 2`)
for ip in "${ips[@]}"
do
if [ $ip == $myip ]
then
return 0
else
continue
fi
done
return 1
}
###############User input################
userinput(){
whiptail --clear --ok-button "吾意已決 立即執行" --title "User choose" --checklist --separate-output --nocancel "請按空格來選擇:(Trojan-GFW Nginx and BBR 為強制選項,已經包含)
若不確定,請保持默認配置並回車" 18 78 10 \
"1" "系统升级(System Upgrade)" on \
"2" "安裝Dnsmasq(Dns cache and adblock)" on \
"3" "安裝Qbittorrent(Powerful Bittorrent Client)" on \
"4" "安裝Bittorrent-Tracker(Nginx Https Proxy)" on \
"5" "安裝Aria2(Powerful non-Bittorrent Client)" on \
"6" "安裝Filebrowser(qbt and aria2 download tool)" on \
"7" "安裝Netdata(Server status monitor tool)" on \
"8" "安裝V2ray(Vmess+Websocket+TLS+Nginx)" off \
"9" "安裝Shadowsocks+V2ray-plugin+Websocket+TLS+Nginx" off \
"10" "安裝BBRPLUS 不推薦因為BBR已經包含(because BBR has been included)" off \
"11" "仅启用TLS1.3(TLS1.3 ONLY)" off 2>results
while read choice
do
case $choice in
1)
system_upgrade=1
;;
2)
dnsmasq_install=1
;;
3)
install_qbt=1
;;
4)
install_tracker=1
;;
5)
install_aria=1
;;
6)
install_file=1
;;
7)
install_netdata=1
;;
8)
install_v2ray=1
;;
9)
install_ss=1
;;
10)
install_bbrplus=1
;;
11)
tls13only=1
;;
*)
;;
esac
done < results
####################################
if [[ $system_upgrade = 1 ]]; then
if [[ $(lsb_release -cs) == stretch ]]; then
if (whiptail --title "System Upgrade" --yesno "Upgrade to Debian 10?" 8 78); then
debian10_install=1
else
debian10_install=0
fi
fi
if [[ $(lsb_release -cs) == jessie ]]; then
if (whiptail --title "System Upgrade" --yesno "Upgrade to Debian 9?" 8 78); then
debian9_install=1
else
debian9_install=0
fi
fi
if [[ $(lsb_release -cs) == xenial ]]; then
if (whiptail --title "System Upgrade" --yesno "Upgrade to Ubuntu 18.04?" 8 78); then
ubuntu18_install=1
else
ubuntu18_install=0
fi
fi
fi
#####################################
while [[ -z $domain ]]; do
domain=$(whiptail --inputbox --nocancel "朽木不可雕也,糞土之牆不可污也,快輸入你的域名並按回車" 8 78 --title "Domain input" 3>&1 1>&2 2>&3)
done
while [[ -z $password1 ]]; do
password1=$(whiptail --passwordbox --nocancel "別動不動就爆粗口,你把你媽揣兜了隨口就說,快輸入你想要的密碼一併按回車" 8 78 --title "password1 input" 3>&1 1>&2 2>&3)
if [[ $password1 == "" ]]; then
password1="12345678"
fi
done
while [[ -z $password2 ]]; do
password2=$(whiptail --passwordbox --nocancel "你別逼我在我和你全家之間加動詞或者是名詞啊,快輸入想要的密碼二並按回車" 8 78 --title "password2 input" 3>&1 1>&2 2>&3)
if [[ $password2 == "" ]]; then
password2="123456789"
fi
done
###################################
if [[ $install_qbt = 1 ]]; then
while [[ -z $qbtpath ]]; do
qbtpath=$(whiptail --inputbox --nocancel "Put your thinking cap on,快输入你的想要的Qbittorrent路径并按回车" 8 78 /qbt/ --title "Qbittorrent path input" 3>&1 1>&2 2>&3)
done
fi
#####################################
if [[ $install_tracker = 1 ]]; then
while [[ -z $trackerpath ]]; do
trackerpath=$(whiptail --inputbox --nocancel "Put your thinking cap on,快输入你的想要的Bittorrent-Tracker路径并按回车" 8 78 /announce --title "Bittorrent-Tracker path input" 3>&1 1>&2 2>&3)
done
while [[ -z $trackerstatuspath ]]; do
trackerstatuspath=$(whiptail --inputbox --nocancel "Put your thinking cap on.,快输入你的想要的Bittorrent-Tracker状态路径并按回车" 8 78 /status --title "Bittorrent-Tracker download path input" 3>&1 1>&2 2>&3)
done
fi
####################################
if [[ $install_aria = 1 ]]; then
while [[ -z $ariapath ]]; do
ariapath=$(whiptail --inputbox --nocancel "Put your thinking cap on.,快输入你的想要的Aria2 RPC路径并按回车" 8 78 /jsonrpc --title "Aria2 path input" 3>&1 1>&2 2>&3)
done
while [[ -z $ariapasswd ]]; do
ariapasswd=$(whiptail --passwordbox --nocancel "Put your thinking cap on.,快输入你的想要的Aria2 rpc token并按回车" 8 78 --title "Aria2 rpc token input" 3>&1 1>&2 2>&3)
if [[ $ariapasswd == "" ]]; then
ariapasswd="123456789"
fi
done
fi
####################################
if [[ $install_file = 1 ]]; then
while [[ -z $filepath ]]; do
filepath=$(whiptail --inputbox --nocancel "Put your thinking cap on,快输入你的想要的Filebrowser路径并按回车" 8 78 /files/ --title "Filebrowser path input" 3>&1 1>&2 2>&3)
done
fi
####################################
if [[ $install_netdata = 1 ]]; then
while [[ -z $netdatapath ]]; do
netdatapath=$(whiptail --inputbox --nocancel "Put your thinking cap on,快输入你的想要的Netdata路径并按回车" 8 78 /netdata/ --title "Netdata path input" 3>&1 1>&2 2>&3)
done
fi
####################################
if [[ $install_v2ray = 1 ]]; then
while [[ -z $path ]]; do
path=$(whiptail --inputbox --nocancel "Put your thinking cap on,快输入你的想要的V2ray Websocket路径并按回车" 8 78 /secret --title "Websocket path input" 3>&1 1>&2 2>&3)
done
while [[ -z $alterid ]]; do
alterid=$(whiptail --inputbox --nocancel "快输入你的想要的alter id大小(只能是数字)并按回车" 8 78 64 --title "alterid input" 3>&1 1>&2 2>&3)
done
fi
####################################
if [[ $install_ss = 1 ]]; then
while [[ -z $sspath ]]; do
sspath=$(whiptail --inputbox --nocancel "Put your thinking cap on,快输入你的想要的ss-Websocket路径并按回车" 8 78 /ss --title "ss-Websocket path input" 3>&1 1>&2 2>&3)
done
while [[ -z $sspasswd ]]; do
sspasswd=$(whiptail --passwordbox --nocancel "Put your thinking cap on,快输入你的想要的ss密码并按回车" 8 78 --title "ss passwd input" 3>&1 1>&2 2>&3)
done
ssen=$(whiptail --title "SS encrypt method Menu" --menu --nocancel "Choose an option RTFM: https://www.johnrosen1.com/trojan/" 12 78 3 \
"1" "aes-128-gcm" \
"2" "aes-256-gcm" \
"3" "chacha20-poly1305" 3>&1 1>&2 2>&3)
case $ssen in
1)
ssmethod=aes-128-gcm
;;
2)
ssmethod=aes-256-gcm
;;
3)
ssmethod=chacha20-poly1305
;;
esac
else
echo "Continuing"
fi
}
###############OS detect####################
osdist(){
set -e
if cat /etc/*release | grep ^NAME | grep -q CentOS; then
dist=centos
elif cat /etc/*release | grep ^NAME | grep -q Red; then
dist=centos
elif cat /etc/*release | grep ^NAME | grep -q Fedora; then
dist=centos
elif cat /etc/*release | grep ^NAME | grep -q Ubuntu; then
dist=ubuntu
elif cat /etc/*release | grep ^NAME | grep -q Debian; then
dist=debian
else
TERM=ansi whiptail --title "OS SUPPORT" --infobox "OS NOT SUPPORTED, couldn't install Trojan-gfw" 8 78
exit 1;
fi
}
##############Upgrade system optional########
upgradesystem(){
if [[ $dist = centos ]]; then
yum upgrade -y
elif [[ $dist = ubuntu ]]; then
export UBUNTU_FRONTEND=noninteractive
if [[ $ubuntu18_install = 1 ]]; then
cat > '/etc/apt/sources.list' << EOF
#------------------------------------------------------------------------------#
# OFFICIAL UBUNTU REPOS #
#------------------------------------------------------------------------------#
###### Ubuntu Main Repos
deb http://us.archive.ubuntu.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://us.archive.ubuntu.com/ubuntu/ bionic main restricted universe multiverse
###### Ubuntu Update Repos
deb http://us.archive.ubuntu.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://us.archive.ubuntu.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://us.archive.ubuntu.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://us.archive.ubuntu.com/ubuntu/ bionic-updates main restricted universe multiverse
EOF
apt-get update
sh -c 'echo "y\n\ny\ny\ny\ny\ny\ny\ny\n" | DEBIAN_FRONTEND=noninteractive apt-get dist-upgrade -q -y' || true
sh -c 'echo "y\n\ny\ny\ny\ny\ny\ny\ny\n" | DEBIAN_FRONTEND=noninteractive apt-get dist-upgrade -q -y' || true
fi
sh -c 'echo "y\n\ny\ny\ny\ny\ny\ny\ny\n" | DEBIAN_FRONTEND=noninteractive apt-get upgrade -qq -y' || true
apt-get autoremove -qq -y
clear
elif [[ $dist = debian ]]; then
export DEBIAN_FRONTEND=noninteractive
sh -c 'echo "y\n\ny\ny\ny\ny\ny\ny\ny\n" | DEBIAN_FRONTEND=noninteractive apt-get upgrade -qq -y' || true
if [[ $debian10_install = 1 ]]; then
cat > '/etc/apt/sources.list' << EOF
#------------------------------------------------------------------------------#
# OFFICIAL DEBIAN REPOS
#------------------------------------------------------------------------------#
###### Debian Main Repos
deb http://deb.debian.org/debian/ stable main contrib non-free
deb-src http://deb.debian.org/debian/ stable main contrib non-free
deb http://deb.debian.org/debian/ stable-updates main contrib non-free
deb-src http://deb.debian.org/debian/ stable-updates main contrib non-free
deb http://deb.debian.org/debian-security stable/updates main
deb-src http://deb.debian.org/debian-security stable/updates main
deb http://ftp.debian.org/debian buster-backports main
deb-src http://ftp.debian.org/debian buster-backports main
EOF
apt-get update
sh -c 'echo "y\n\ny\ny\ny\ny\ny\ny\ny\n" | DEBIAN_FRONTEND=noninteractive apt-get dist-upgrade -q -y' || true
sh -c 'echo "y\n\ny\ny\ny\ny\ny\ny\ny\n" | DEBIAN_FRONTEND=noninteractive apt-get dist-upgrade -q -y' || true
clear
fi
if [[ $debian9_install = 1 ]]; then
cat > '/etc/apt/sources.list' << EOF
#------------------------------------------------------------------------------#
# OFFICIAL DEBIAN REPOS
#------------------------------------------------------------------------------#
###### Debian Main Repos
deb http://deb.debian.org/debian/ oldstable main contrib non-free
deb-src http://deb.debian.org/debian/ oldstable main contrib non-free
deb http://deb.debian.org/debian/ oldstable-updates main contrib non-free
deb-src http://deb.debian.org/debian/ oldstable-updates main contrib non-free
deb http://deb.debian.org/debian-security oldstable/updates main
deb-src http://deb.debian.org/debian-security oldstable/updates main
deb http://ftp.debian.org/debian stretch-backports main
deb-src http://ftp.debian.org/debian stretch-backports main
EOF
apt-get update
sh -c 'echo "y\n\ny\ny\ny\ny\ny\ny\ny\n" | DEBIAN_FRONTEND=noninteractive apt-get dist-upgrade -q -y' || true
sh -c 'echo "y\n\ny\ny\ny\ny\ny\ny\ny\n" | DEBIAN_FRONTEND=noninteractive apt-get dist-upgrade -q -y' || true
fi
sh -c 'echo "y\n\ny\ny\ny\ny\ny\ny\ny\n" | DEBIAN_FRONTEND=noninteractive apt-get autoremove -qq -y' || true
clear
else
clear
TERM=ansi whiptail --title "error can't upgrade system" --infobox "error can't upgrade system" 8 78
exit 1;
fi
}
#########Open ports########################
openfirewall(){
colorEcho ${INFO} "设置 firewall"
#sh -c 'echo "1\n" | DEBIAN_FRONTEND=noninteractive update-alternatives --config iptables'
iptables -I INPUT -p tcp -m tcp --dport 443 -j ACCEPT || true
iptables -I INPUT -p tcp -m tcp --dport 80 -j ACCEPT || true
iptables -I OUTPUT -j ACCEPT || true
ip6tables -I INPUT -p tcp -m tcp --dport 443 -j ACCEPT || true
ip6tables -I INPUT -p tcp -m tcp --dport 80 -j ACCEPT || true
ip6tables -I OUTPUT -j ACCEPT || true
if [[ $dist = centos ]]; then
setenforce 0 || true
cat > '/etc/selinux/config' << EOF
SELINUX=disabled
SELINUXTYPE=targeted
EOF
firewall-cmd --zone=public --add-port=80/tcp --permanent || true
firewall-cmd --zone=public --add-port=443/tcp --permanent || true
elif [[ $dist = ubuntu ]]; then
export DEBIAN_FRONTEND=noninteractive
apt-get install iptables-persistent -qq -y > /dev/null || true
elif [[ $dist = debian ]]; then
export DEBIAN_FRONTEND=noninteractive
apt-get install iptables-persistent -qq -y > /dev/null || true
else
clear
TERM=ansi whiptail --title "error can't install iptables-persistent" --infobox "error can't install iptables-persistent" 8 78
exit 1;
fi
}
##########install dependencies#############
installdependency(){
colorEcho ${INFO} "Updating system"
if [[ $dist = centos ]]; then
yum update -y
elif [[ $dist = ubuntu ]]; then
apt-get update -qq
elif [[ $dist = debian ]]; then
apt-get update -qq
else
clear
TERM=ansi whiptail --title "error can't update system" --infobox "error can't update system" 8 78
exit 1;
fi
###########################################
clear
colorEcho ${INFO} "安装所有必备软件(Install all necessary Software)"
if [[ $dist = centos ]]; then
yum install -y sudo curl wget gnupg python3-qrcode unzip bind-utils epel-release chrony systemd
elif [[ $dist = ubuntu ]] || [[ $dist = debian ]]; then
apt-get install sudo curl xz-utils wget apt-transport-https gnupg dnsutils lsb-release python-pil unzip resolvconf ntpdate systemd dbus ca-certificates locales iptables software-properties-common -qq -y
if [[ $(lsb_release -cs) == xenial ]] || [[ $(lsb_release -cs) == trusty ]] || [[ $(lsb_release -cs) == jessie ]]; then
TERM=ansi whiptail --title "Skipping generating QR code!" --infobox "你的操作系统不支持 python3-qrcode,Skipping generating QR code!" 8 78
else
apt-get install python3-qrcode -qq -y
fi
else
clear
TERM=ansi whiptail --title "error can't install dependency" --infobox "error can't install dependency" 8 78
exit 1;
fi
clear
#############################################
if [[ -f /etc/trojan/trojan.crt ]]; then
:
else
if isresolved $domain
then
:
else
clear
whiptail --title "Domain verification fail" --msgbox --scrolltext "域名解析验证失败,请自行验证解析是否成功并且请关闭Cloudfalare CDN并检查VPS控制面板防火墙(80 443)是否打开!!!Domain verification fail,Pleae turn off Cloudflare CDN and Open port 80 443 on VPS panel !!!" 8 78
colorEcho ${ERROR} "域名解析验证失败,请自行验证解析是否成功并且请关闭Cloudfalare CDN并检查VPS控制面板防火墙(80 443)是否打开!!!"
colorEcho ${ERROR} "Domain verification fail,Pleae turn off Cloudflare CDN and Open port 80 443 on VPS panel !!!"
exit -1
clear
fi
fi
#############################################
if [[ $system_upgrade = 1 ]]; then
upgradesystem
fi
clear
#############################################
if [[ $tls13only = 1 ]]; then
cipher_server="TLS_AES_128_GCM_SHA256"
fi
#####################################################
if [[ -f /etc/apt/sources.list.d/nginx.list ]]; then
:
else
clear
colorEcho ${INFO} "安装Nginx(Install Nginx ing)"
if [[ $dist = centos ]]; then
yum install nginx -y
systemctl stop nginx || true
elif [[ $dist = debian ]] || [[ $dist = ubuntu ]]; then
wget https://nginx.org/keys/nginx_signing.key -q
apt-key add nginx_signing.key
rm -rf nginx_signing.key
touch /etc/apt/sources.list.d/nginx.list
cat > '/etc/apt/sources.list.d/nginx.list' << EOF
deb https://nginx.org/packages/mainline/$dist/ $(lsb_release -cs) nginx
deb-src https://nginx.org/packages/mainline/$dist/ $(lsb_release -cs) nginx
EOF
apt-get remove nginx-common -qq -y
apt-get update -qq
apt-get install nginx -qq -y
else
clear
TERM=ansi whiptail --title "error can't install nginx" --infobox "error can't install nginx" 8 78
exit 1;
fi
fi
nginxconf
clear
#############################################
if [[ $install_qbt = 1 ]]; then
if [[ -f /usr/bin/qbittorrent-nox ]]; then
:
else
clear
colorEcho ${INFO} "安装Qbittorrent(Install Qbittorrent ing)"
if [[ $dist = centos ]]; then
yum install -y epel-release
yum update -y
yum install qbittorrent-nox -y
elif [[ $dist = ubuntu ]]; then
export DEBIAN_FRONTEND=noninteractive
add-apt-repository ppa:qbittorrent-team/qbittorrent-stable -y
apt-get install qbittorrent-nox -qq -y
elif [[ $dist = debian ]]; then
export DEBIAN_FRONTEND=noninteractive
apt-get install qbittorrent-nox -qq -y
else
clear
TERM=ansi whiptail --title "error can't install qbittorrent-nox" --infobox "error can't install qbittorrent-nox" 8 78
exit 1;
fi
cat > '/etc/systemd/system/qbittorrent.service' << EOF
[Unit]
Description=qBittorrent Daemon Service
Documentation=man:qbittorrent-nox(1)
Wants=network-online.target
After=network-online.target nss-lookup.target
[Service]
# if you have systemd >= 240, you probably want to use Type=exec instead
Type=simple
User=root
ExecStart=/usr/bin/qbittorrent-nox
TimeoutStopSec=infinity
Restart=on-failure
RestartSec=3s
[Install]
WantedBy=multi-user.target
EOF
mkdir /usr/share/nginx/qbt/
chmod 755 /usr/share/nginx/qbt/
fi
fi
clear
#############################################
if [[ $install_tracker = 1 ]]; then
if [[ -f /usr/bin/bittorrent-tracker ]]; then
:
else
clear
colorEcho ${INFO} "安装Bittorrent-tracker(Install bittorrent-tracker ing)"
if [[ $dist = centos ]]; then
curl -sL https://rpm.nodesource.com/setup_13.x | bash -
elif [[ $dist = ubuntu ]]; then
export DEBIAN_FRONTEND=noninteractive
curl -sL https://deb.nodesource.com/setup_13.x | sudo -E bash -
apt-get install -qq -y nodejs
elif [[ $dist = debian ]]; then
export DEBIAN_FRONTEND=noninteractive
curl -sL https://deb.nodesource.com/setup_13.x | bash -
apt-get install -qq -y nodejs
else
clear
TERM=ansi whiptail --title "error can't install qbittorrent-nox" --infobox "error can't install qbittorrent-nox" 8 78
exit 1;
fi
npm install -g bittorrent-tracker --silent
cat > '/etc/systemd/system/tracker.service' << EOF
[Unit]
Description=Bittorrent-Tracker Daemon Service
Wants=network-online.target
After=network-online.target nss-lookup.target
[Service]
# if you have systemd >= 240, you probably want to use Type=exec instead
Type=simple
User=root
RemainAfterExit=yes
ExecStart=/usr/bin/bittorrent-tracker --http --ws --trust-proxy
TimeoutStopSec=infinity
Restart=on-failure
RestartSec=3s
[Install]
WantedBy=multi-user.target
EOF
fi
fi
clear
#############################################
if [[ $install_file = 1 ]]; then
if [[ -f /usr/local/bin/filebrowser ]]; then
:
else
clear
colorEcho ${INFO} "安装Filebrowser(Install Filebrowser ing)"
if [[ $dist = centos ]]; then
curl -fsSL https://raw.githubusercontent.com/filebrowser/get/master/get.sh | bash
elif [[ $dist = ubuntu ]] || [[ $dist = debian ]]; then
export DEBIAN_FRONTEND=noninteractive
curl -fsSL https://raw.githubusercontent.com/filebrowser/get/master/get.sh | bash
else
clear
TERM=ansi whiptail --title "error can't install filebrowser" --infobox "error can't install filebrowser" 8 78
exit 1;
fi
cat > '/etc/systemd/system/filebrowser.service' << EOF
[Unit]
Description=filebrowser browser
After=network.target
[Service]
User=root
Group=root
ExecStart=/usr/local/bin/filebrowser -r /usr/share/nginx/ -d /etc/filebrowser/database.db -b $filepath -p 8081
ExecReload=/usr/bin/kill -HUP \$MAINPID
ExecStop=/usr/bin/kill -s STOP \$MAINPID
RestartSec=3s
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
mkdir /etc/filebrowser/
touch /etc/filebrowser/database.db
fi
fi
clear
#############################################
if [[ $install_aria = 1 ]]; then
if [[ -f /usr/local/bin/aria2c ]]; then
:
else
clear
colorEcho ${INFO} "安装aria2(Install aria2 ing)"
#apt-get install build-essential nettle-dev libgmp-dev libssh2-1-dev libc-ares-dev libxml2-dev zlib1g-dev libsqlite3-dev pkg-config libssl-dev autoconf automake autotools-dev autopoint libtool libuv1-dev libcppunit-dev -qq -y
apt-get install nettle-dev libgmp-dev libssh2-1-dev libc-ares-dev libxml2-dev zlib1g-dev libsqlite3-dev pkg-config libssl-dev libtool libuv1-dev libcppunit-dev -qq -y
#wget https://github.com/aria2/aria2/releases/download/release-1.35.0/aria2-1.35.0.tar.xz -q
wget https://raw.githubusercontent.com/johnrosen1/trojan-gfw-script/master/aria2c.xz -q
xz --decompress aria2c.xz
#rm aria2c.xz
cp aria2c /usr/local/bin/aria2c
chmod +x /usr/local/bin/aria2c
rm aria2c
#cd aria2-1.35.0
#./configure --without-gnutls --with-openssl
#make -j $(nproc --all)
#make install
#apt remove build-essential autoconf automake autotools-dev autopoint libtool -qq -y
apt-get autoremove -qq -y
touch /usr/local/bin/aria2.session
mkdir /usr/share/nginx/aria2/
chmod 755 /usr/share/nginx/aria2/
cd ..
rm -rf aria2-1.35.0
cat > '/etc/systemd/system/aria2.service' << EOF
[Unit]
Description=Aria2c download manager
Requires=network.target
After=network.target
[Service]
Type=forking
User=root
RemainAfterExit=yes
ExecStart=/usr/local/bin/aria2c --conf-path=/etc/aria2.conf --daemon
ExecReload=/usr/bin/kill -HUP \$MAINPID
ExecStop=/usr/bin/kill -s STOP \$MAINPID
RestartSec=1min
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
cat > '/etc/aria2.conf' << EOF
#rpc-secure=true
#rpc-certificate=/etc/trojan/trojan.crt
#rpc-private-key=/etc/trojan/trojan.key
## 下载设置 ##
continue=true
max-concurrent-downloads=50
split=16
min-split-size=10M
max-connection-per-server=16
lowest-speed-limit=0
#max-overall-download-limit=0
#max-download-limit=0
#max-overall-upload-limit=0
#max-upload-limit=0
disable-ipv6=false
max-tries=0
#retry-wait=0
## 进度保存相关 ##
input-file=/usr/local/bin/aria2.session
save-session=/usr/local/bin/aria2.session
save-session-interval=60
force-save=true
## RPC相关设置 ##
enable-rpc=true
rpc-allow-origin-all=true
rpc-listen-all=false
event-poll=epoll
# RPC监听端口, 端口被占用时可以修改, 默认:6800
rpc-listen-port=6800
# 设置的RPC授权令牌, v1.18.4新增功能, 取代 --rpc-user 和 --rpc-passwd 选项
rpc-secret=$ariapasswd
## BT/PT下载相关 ##
#follow-torrent=true
listen-port=51413
#bt-max-peers=55
enable-dht=true
enable-dht6=true
#dht-listen-port=6881-6999
bt-enable-lpd=true
#enable-peer-exchange=true
#bt-request-peer-speed-limit=50K
# 客户端伪装, PT需要
#peer-id-prefix=-TR2770-
#user-agent=Transmission/2.77
seed-ratio=0
# BT校验相关, 默认:true
#bt-hash-check-seed=true
bt-seed-unverified=true
bt-save-metadata=true
bt-require-crypto=true
## 磁盘相关 ##
#文件保存路径, 默认为当前启动位置
dir=/usr/share/nginx/aria2/
#enable-mmap=true
file-allocation=none
disk-cache=64M
EOF
fi
fi
#############################################
if [[ $dnsmasq_install = 1 ]]; then
if [[ -f /usr/sbin/dnsmasq ]]; then
:
else
clear
colorEcho ${INFO} "安装dnsmasq(Install dnsmasq ing)"
if [[ $dist = centos ]]; then
yum install -y dnsmasq || true
elif [[ $dist = ubuntu ]] || [[ $dist = debian ]]; then
export DEBIAN_FRONTEND=noninteractive
apt-get install dnsmasq -qq -y || true
else
clear
TERM=ansi whiptail --title "error can't install dnsmasq" --infobox "error can't install dnsmasq" 8 78
exit 1;
fi
if [[ $dist = ubuntu ]]; then
systemctl stop systemd-resolved || true
systemctl disable systemd-resolved || true > /dev/null
fi
touch /etc/dnsmasq.txt || true
cat > '/etc/dnsmasq.txt' << EOF
####Block 360####
0.0.0.0 360.cn
0.0.0.0 360.com
0.0.0.0 360jie.com
0.0.0.0 360kan.com
0.0.0.0 360taojin.com
0.0.0.0 i360mall.com
0.0.0.0 qhimg.com
0.0.0.0 qhmsg.com
0.0.0.0 qhres.com
0.0.0.0 qihoo.com
0.0.0.0 nicaifu.com
0.0.0.0 so.com
####Block Xunlei###
0.0.0.0 xunlei.com
####Block Baidu###
0.0.0.0 baidu.cn
0.0.0.0 baidu.com
0.0.0.0 baiducontent.com
0.0.0.0 baidupcs.com
0.0.0.0 baidustatic.com
0.0.0.0 baifubao.com
0.0.0.0 bdimg.com
0.0.0.0 bdstatic.com
0.0.0.0 duapps.com
0.0.0.0 quyaoya.com
0.0.0.0 tiebaimg.com
0.0.0.0 xiaodutv.com
0.0.0.0 sina.com
EOF
cat > '/etc/dnsmasq.conf' << EOF
port=53
domain-needed
bogus-priv
no-resolv
server=8.8.4.4#53
server=1.1.1.1#53
addn-hosts=/etc/dnsmasq.txt
address=/cn/0.0.0.0
interface=lo
bind-interfaces
cache-size=10000
no-negcache
log-queries
log-facility=/var/log/dnsmasq.log
EOF
echo "nameserver 127.0.0.1" > '/etc/resolv.conf'
systemctl restart dnsmasq || true
systemctl enable dnsmasq || true
fi
fi
clear
#############################################
if [[ $install_v2ray = 1 ]] || [[ $install_ss = 1 ]]; then
clear
installv2ray
fi
#############################################
if [[ $install_netdata = 1 ]]; then
if [[ -f /usr/sbin/netdata ]]; then
:
else
clear
colorEcho ${INFO} "安装Netdata(Install netdata ing)"
bash <(curl -Ss https://my-netdata.io/kickstart.sh) --dont-wait --disable-telemetry
sed -i 's/# bind to = \*/bind to = 127.0.0.1/g' /etc/netdata/netdata.conf
#sed -i 's/SEARCH_REGEX/REPLACEMENT/g' INPUTFILE
systemctl restart netdata
fi
fi
clear
#############################################
if [[ -f /etc/trojan/trojan.crt ]]; then
:
else
curl -s https://get.acme.sh | sh
sudo ~/.acme.sh/acme.sh --upgrade --auto-upgrade
fi
#############################################
if [[ -f /usr/local/bin/trojan ]]; then
:
else
clear
colorEcho ${INFO} "安装Trojan-GFW(Install Trojan-GFW ing)"
bash -c "$(curl -fsSL https://raw.githubusercontent.com/trojan-gfw/trojan-quickstart/master/trojan-quickstart.sh)"
systemctl daemon-reload
fi
clear
}
##################################################
issuecert(){
clear
colorEcho ${INFO} "申请(issuing) let\'s encrypt certificate"
if [[ -f /etc/trojan/trojan.crt ]]; then
myip=`curl -s http://dynamicdns.park-your-domain.com/getip`
TERM=ansi whiptail --title "证书已有,跳过申请" --infobox "证书已有,跳过申请。。。" 8 78
else
mkdir /etc/trojan/ &
rm -rf /etc/nginx/sites-available/* &
rm -rf /etc/nginx/sites-enabled/* &
rm -rf /etc/nginx/conf.d/*
touch /etc/nginx/conf.d/default.conf
cat > '/etc/nginx/conf.d/default.conf' << EOF
server {
listen 80;
server_name $domain;
root /usr/share/nginx/html;
}
EOF
systemctl start nginx
sudo ~/.acme.sh/acme.sh --issue --nginx -d $domain -k ec-256 --force --log --reloadcmd "systemctl reload trojan || true"
sudo ~/.acme.sh/acme.sh --installcert -d $domain --fullchainpath /etc/trojan/trojan.crt --keypath /etc/trojan/trojan.key --ecc
chmod +r /etc/trojan/trojan.key
fi
}
##################################################
renewcert(){
sudo ~/.acme.sh/acme.sh --issue --nginx -d $domain -k ec-256 --force --log --reloadcmd "systemctl reload trojan || true"
}
##################################################
changepasswd(){
clear
colorEcho ${INFO} "配置(configing) trojan-gfw"
if [[ -f /etc/trojan/trojan.pem ]]; then
colorEcho ${INFO} "DH已有,跳过生成。。。"
else
:
#openssl dhparam -out /etc/trojan/trojan.pem 2048
fi
cat > '/usr/local/etc/trojan/config.json' << EOF
{
"run_type": "server",
"local_addr": "::",
"local_port": 443,
"remote_addr": "127.0.0.1",
"remote_port": 80,
"password": [
"$password1",
"$password2"
],
"log_level": 1,
"ssl": {
"cert": "/etc/trojan/trojan.crt",
"key": "/etc/trojan/trojan.key",
"key_password": "",
"cipher": "$cipher_server",
"cipher_tls13":"TLS_AES_128_GCM_SHA256:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_256_GCM_SHA384",
"prefer_server_cipher": true,
"alpn": [
"http/1.1"
],
"reuse_session": true,
"session_ticket": false,
"session_timeout": 600,
"plain_http_response": "",
"curves": "",
"dhparam": ""
},
"tcp": {
"prefer_ipv4": true,
"no_delay": true,
"keep_alive": true,
"reuse_port": true,
"fast_open": true,
"fast_open_qlen": 20
},
"mysql": {
"enabled": false,
"server_addr": "127.0.0.1",
"server_port": 3306,
"database": "trojan",
"username": "trojan",
"password": ""
}
}
EOF
}
##########Nginx conf####################
nginxconf(){
cat > '/etc/nginx/nginx.conf' << EOF
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log warn;
#pid /var/run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 3000;
use epoll;
multi_accept on;
}
http {
#aio threads; //Please enable it by yourself,disabled for compatibility.
charset UTF-8;
tcp_nodelay on;
tcp_nopush on;
server_tokens off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
log_format main '\$remote_addr - \$remote_user [\$time_local] "\$request" '
'\$status $body_bytes_sent "\$http_referer" '
'"\$http_user_agent" "\$http_x_forwarded_for"';
sendfile on;
gzip on;
gzip_comp_level 8;
include /etc/nginx/conf.d/*.conf;
}
EOF
}
########Nginx config for Trojan only##############
nginxtrojan(){
clear
colorEcho ${INFO} "配置(configing) nginx"
rm -rf /etc/nginx/sites-available/* || true
rm -rf /etc/nginx/sites-enabled/* || true
rm -rf /etc/nginx/conf.d/* || true
touch /etc/nginx/conf.d/trojan.conf
cat > '/etc/nginx/conf.d/trojan.conf' << EOF
server {
listen 127.0.0.1:80;
server_name $domain;
if (\$http_user_agent = "") { return 444; }
if (\$host != "$domain") { return 404; }
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" always;
add_header X-Frame-Options SAMEORIGIN always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "no-referrer";