-
Notifications
You must be signed in to change notification settings - Fork 185
/
Copy pathclient
2853 lines (2395 loc) · 94.8 KB
/
client
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
RED='\E[1;31m'
GREEN='\E[1;32m'
YELLOW='\E[1;33m'
BLUE='\E[1;34m'
PURPLE='\E[1;35m'
CYAN='\E[1;36m'
WHITE='\E[1;37m'
cRES='\E[0m'
chmod 777 /tmp
architecture=$(dpkg --print-architecture)
export DEBIAN_FRONTEND=noninteractive
TTYD_Ver="1.7.3"
branch="main"
installCMD=`cat << EOF
bash <(wget --no-check-certificate -qO- https://ghproxy.net/https://raw.githubusercontent.com/jacyl4/de_GWD/main/client)
EOF
`
if [[ $architecture = "arm64" ]];then
chnAPTsource="mirrors.tuna.tsinghua.edu.cn"
elif [[ $architecture = "amd64" ]]; then
chnAPTsource="mirrors.aliyun.com"
fi
pkgDEP1(){
if [[ $architecture = "arm64" ]];then
unset Freeze_Package
Freeze_Package+=($(dpkg -l | grep 'linux-u-boot-' | awk '{print $2}'))
Freeze_Package+=($(dpkg -l | grep 'linux-image-' | awk '{print $2}'))
Freeze_Package+=($(dpkg -l | grep 'linux-headers-' | awk '{print $2}'))
Freeze_Package+=($(dpkg -l | grep 'linux-dtb-' | awk '{print $2}'))
echo ${Freeze_Package[@]} | xargs -n1 apt-mark hold
fi
[[ -n $(dpkg -l | awk '{print$2}' | grep '^ipset$') ]] && apt remove --purge ipset
[[ -n $(dpkg -l | awk '{print$2}' | grep '^haveged$') ]] && apt remove --purge haveged
[[ -n $(dpkg -l | awk '{print$2}' | grep '^os-prober$') ]] && apt remove --purge os-prober
[[ -n $(dpkg -l | awk '{print$2}' | grep '^systemd-timesyncd$') ]] && apt remove --purge systemd-timesyncd
unset aptPKG
[[ -z $(dpkg -l | awk '{print$2}' | grep '^sudo$') ]] && aptPKG+=(sudo)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^wget$') ]] && aptPKG+=(wget)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^curl$') ]] && aptPKG+=(curl)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^git$') ]] && aptPKG+=(git)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^locales$') ]] && aptPKG+=(locales)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^netcat-openbsd$') ]] && aptPKG+=(netcat-openbsd)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^lsof$') ]] && aptPKG+=(lsof)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^dnsutils$') ]] && aptPKG+=(dnsutils)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^net-tools$') ]] && aptPKG+=(net-tools)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^resolvconf$') ]] && aptPKG+=(resolvconf)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^nftables$') ]] && aptPKG+=(nftables)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^ca-certificates$') ]] && aptPKG+=(ca-certificates)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^apt-transport-https$') ]] && aptPKG+=(apt-transport-https)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^gnupg2$') ]] && aptPKG+=(gnupg2)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^unzip$') ]] && aptPKG+=(unzip)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^zstd$') ]] && aptPKG+=(zstd)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^jq$') ]] && aptPKG+=(jq)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^bc$') ]] && aptPKG+=(bc)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^moreutils$') ]] && aptPKG+=(moreutils)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^rng-tools-debian$') ]] && aptPKG+=(rng-tools-debian)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^chrony$') ]] && aptPKG+=(chrony)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^irqbalance$') ]] && [[ $(nproc --all) -gt 1 ]] && aptPKG+=(irqbalance)
[[ -n $aptPKG ]] && apt update && apt install $(echo ${aptPKG[@]})
}
pkgDEP2(){
unset aptPKG
[[ -z $(dpkg -l | awk '{print$2}' | grep '^psmisc$') ]] && aptPKG+=(psmisc)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^dns-root-data$') ]] && aptPKG+=(dns-root-data)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^idn2$') ]] && aptPKG+=(idn2)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^ethtool$') ]] && aptPKG+=(ethtool)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^tmux$') ]] && aptPKG+=(tmux)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^socat$') ]] && aptPKG+=(socat)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^zip$') ]] && aptPKG+=(zip)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^lighttpd$') ]] && aptPKG+=(lighttpd)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^php7.4-fpm$') ]] && aptPKG+=(php7.4-fpm)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^php7.4-cgi$') ]] && aptPKG+=(php7.4-cgi)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^php7.4-sqlite3$') ]] && aptPKG+=(php7.4-sqlite3)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^php7.4-xml$') ]] && aptPKG+=(php7.4-xml)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^php7.4-intl$') ]] && aptPKG+=(php7.4-intl)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^php7.4-json$') ]] && aptPKG+=(php7.4-json)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^sqlite3$') ]] && aptPKG+=(sqlite3)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^libjemalloc2') ]] && aptPKG+=(libjemalloc2)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^google-perftools') ]] && aptPKG+=(google-perftools)
[[ -n $aptPKG ]] && apt update && apt install $(echo ${aptPKG[@]})
}
checkSum(){
sha256sumL=$(sha256sum $1 2>/dev/null | awk '{print$1}')
if [[ $sha256sumL = $2 ]]; then
echo "true"
elif [[ $sha256sumL != $2 ]]; then
echo "false"
fi
}
preDL(){
mkdir -p /opt/de_GWD
mkdir -p /opt/de_GWD/.repo
sha256sum_IPchnroute=$(curl -ksSLo- https://ghproxy.net/https://raw.githubusercontent.com/jacyl4/chnroute/main/IPchnroute.sha256sum)
if [[ -n $sha256sum_IPchnroute ]] && [[ $(checkSum /opt/de_GWD/.repo/IPchnroute $sha256sum_IPchnroute) = "false" ]] ; then
rm -rf /tmp/IPchnroute
wget --no-check-certificate --show-progress -cqO /tmp/IPchnroute https://ghproxy.net/https://raw.githubusercontent.com/jacyl4/chnroute/main/IPchnroute
[[ $(checkSum /tmp/IPchnroute $sha256sum_IPchnroute) = "false" ]] && echo -e "${WHITE}IPchnroute${RED} Download Failed${cRES}" && exit
[[ $(checkSum /tmp/IPchnroute $sha256sum_IPchnroute) = "true" ]] && mv -f /tmp/IPchnroute /opt/de_GWD/.repo/IPchnroute
fi
if [[ -f "./de_GWD_$architecture.zip" ]]; then
mv -f ./de_GWD_$architecture.zip /opt/de_GWD/.repo/de_GWD.zip
else
sha256sum_de_GWD=$(curl -ksSLo- https://ghproxy.net/https://raw.githubusercontent.com/jacyl4/de_GWD/main/de_GWD_"$architecture".zip.sha256sum)
if [[ -n $sha256sum_de_GWD ]] && [[ $(checkSum /opt/de_GWD/.repo/de_GWD.zip $sha256sum_de_GWD) = "false" ]]; then
rm -rf /tmp/de_GWD.zip
wget --no-check-certificate --show-progress -cqO /tmp/de_GWD.zip https://ghproxy.net/https://raw.githubusercontent.com/jacyl4/de_GWD/main/de_GWD_"$architecture".zip
[[ $(checkSum /tmp/de_GWD.zip $sha256sum_de_GWD) = "false" ]] && rm -rf /tmp/de_GWD.zip && wget --no-check-certificate --show-progress -cqO /tmp/de_GWD.zip https://de-gwd.accxio.workers.dev/de_GWD_"$architecture".zip
[[ $(checkSum /tmp/de_GWD.zip $sha256sum_de_GWD) = "false" ]] && echo -e "${WHITE}de_GWD Zip${RED} Download Failed${cRES}" && exit
[[ $(checkSum /tmp/de_GWD.zip $sha256sum_de_GWD) = "true" ]] && mv -f /tmp/de_GWD.zip /opt/de_GWD/.repo/de_GWD.zip
fi
fi
[[ -z $(unzip -tq /opt/de_GWD/.repo/de_GWD.zip | grep "No errors detected in compressed data") ]] && echo -e "${WHITE}de_GWD Zip${RED} Download Failed${cRES}" && exit
cat << "EOF" >/opt/de_GWD/tcpTime
#!/bin/bash
echo
date -s "$(curl -sI aliyun.com| grep -i '^date:'|cut -d' ' -f2-)"
[[ $? -ne "0" ]] && date -s "$(wget -qSO- --max-redirect=0 --dns-timeout=3 baidu.com 2>&1 | grep Date: | cut -d' ' -f5-8)Z"
hwclock -w
echo
EOF
chmod +x /opt/de_GWD/tcpTime
/opt/de_GWD/tcpTime
}
repoDL(){
echo -e "${WHITE}[...]\c" && echo -e "\t${WHITE}Repo Download${cRES}\r\c"
sha256sum_nginx=$(curl -sSLo- https://raw.githubusercontent.com/jacyl4/de_GWD/$branch/resource/nginx/nginx_"$architecture".sha256sum)
sha256sum_nginxConf=$(curl -sSLo- https://raw.githubusercontent.com/jacyl4/de_GWD/$branch/resource/nginx/nginxConf.zip.sha256sum)
sha256sum_client=$(curl -sSLo- https://raw.githubusercontent.com/jacyl4/de_GWD/$branch/resource/client/Archive.zip.sha256sum)
if [[ $(checkSum /usr/sbin/nginx $sha256sum_nginx) = "false" ]]; then
rm -rf /tmp/nginx
wget --show-progress -cqO /tmp/nginx https://raw.githubusercontent.com/jacyl4/de_GWD/$branch/resource/nginx/nginx_"$architecture"
[[ $(checkSum /tmp/nginx $sha256sum_nginx) = "false" ]] && echo -e "${WHITE}NGINX Core${RED} Download Failed${cRES}" && exit
[[ $(checkSum /tmp/nginx $sha256sum_nginx) = "true" ]] && mv -f /tmp/nginx /usr/sbin/nginx && chmod +x /usr/sbin/nginx
fi
if [[ $(checkSum /opt/de_GWD/.repo/nginxConf.zip $sha256sum_nginxConf) = "false" ]]; then
rm -rf /tmp/nginxConf.zip
wget --show-progress -cqO /tmp/nginxConf.zip https://raw.githubusercontent.com/jacyl4/de_GWD/$branch/resource/nginx/nginxConf.zip
[[ $(checkSum /tmp/nginxConf.zip $sha256sum_nginxConf) = "false" ]] && echo -e "${RED}Download Failed${cRES}" && exit
[[ $(checkSum /tmp/nginxConf.zip $sha256sum_nginxConf) = "true" ]] && mv -f /tmp/nginxConf.zip /opt/de_GWD/.repo/nginxConf.zip
fi
if [[ $(ttyd -v 2>&1 | grep -o '[0-9]\.[0-9]\.[0-9]') != $TTYD_Ver ]]; then
wget --show-progress -cqO /tmp/ttyd https://github.com/tsl0922/ttyd/releases/download/$TTYD_Ver/ttyd.$(uname -m)
[[ $? -ne 0 ]] && echo -e "${WHITE}TTYD${RED} Download Failed${cRES}"
[[ $(du -sk /tmp/ttyd 2>/dev/null | awk '{print$1}') -gt 1000 ]] && mv -f /tmp/ttyd /usr/bin/ttyd && chmod +x /usr/bin/ttyd && TTYD_UPDATE="true"
fi
if [[ $(checkSum /opt/de_GWD/.repo/client.zip $sha256sum_client) = "false" ]]; then
rm -rf /tmp/client.zip
wget --show-progress -cqO /tmp/client.zip https://raw.githubusercontent.com/jacyl4/de_GWD/$branch/resource/client/Archive.zip
[[ $(checkSum /tmp/client.zip $sha256sum_client) = "false" ]] && echo -e "${WHITE}Client Zip${RED} Download Failed${cRES}" && exit
[[ $(checkSum /tmp/client.zip $sha256sum_client) = "true" ]] && mv -f /tmp/client.zip /opt/de_GWD/.repo/client.zip
fi
localVer=$(awk 'NR==1' /opt/de_GWD/.repo/version.php 2>/dev/null)
remoteVer=$(curl -sSLo- https://raw.githubusercontent.com/jacyl4/de_GWD/main/version.php | head -n 1)
if [[ $localVer != $remoteVer ]] || [[ ! -f '/opt/de_GWD/.repo/version.php' ]]; then
rm -rf /opt/de_GWD/.repo/version.php
wget --show-progress -cqO /opt/de_GWD/.repo/version.php https://raw.githubusercontent.com/jacyl4/de_GWD/main/version.php
[[ $? -ne 0 ]] && echo -e "${WHITE}Version file${RED} Download Failed${cRES}" && exit
fi
echo -e "${WHITE}[ ${GREEN}✓ ${WHITE}]\c" && echo -e "\t${WHITE}Repo Download${cRES}"
}
cleanDep(){
echo -e "${WHITE}[...]\c" && echo -e "\t${WHITE}Clean-up${cRES}\r\c"
service cron stop
sed -i "/nfsvers/d" /etc/fstab >/dev/null 2>&1
sed -i '/quic/d' /etc/nginx/conf.d/*.conf >/dev/null 2>&1
[[ $(jq '.v2nodeDIV.nodeSM' /opt/de_GWD/0conf) = "[]" ]] && jq '.v2nodeDIV.nodeSM={}' /opt/de_GWD/0conf | sponge /opt/de_GWD/0conf
[[ $(jq '.v2nodeDIV.nodeDT' /opt/de_GWD/0conf) = "[]" ]] && jq '.v2nodeDIV.nodeDT={}' /opt/de_GWD/0conf | sponge /opt/de_GWD/0conf
[[ $(jq '.v2nodeDIV.nodeCU' /opt/de_GWD/0conf) = "[]" ]] && jq '.v2nodeDIV.nodeCU={}' /opt/de_GWD/0conf | sponge /opt/de_GWD/0conf
[[ -n $(jq '.v2nodeDIV.nodeCU.custom' /opt/de_GWD/0conf | grep -v '^null$') ]] && jq 'del(.v2nodeDIV.nodeCU.custom)' /opt/de_GWD/0conf | sponge /opt/de_GWD/0conf
[[ -n $(jq '.v2nodeDIV.nodeDT.divert' /opt/de_GWD/0conf | grep -v '^null$') ]] && jq 'del(.v2nodeDIV.nodeDT.divert)' /opt/de_GWD/0conf | sponge /opt/de_GWD/0conf
[[ -n $(jq '.v2nodeDIV.nodeDT.ip' /opt/de_GWD/0conf | grep -v '^null$') ]] && jq 'del(.v2nodeDIV.nodeDT.ip)' /opt/de_GWD/0conf | sponge /opt/de_GWD/0conf
[[ -n $(jq '.listB' /opt/de_GWD/0conf | grep -v '^null$') ]] && jq 'del(.listB)' /opt/de_GWD/0conf | sponge /opt/de_GWD/0conf
[[ -n $(jq '.listW' /opt/de_GWD/0conf | grep -v '^null$') ]] && jq 'del(.listW)' /opt/de_GWD/0conf | sponge /opt/de_GWD/0conf
[[ -n $(jq '.listBlan' /opt/de_GWD/0conf | grep -v '^null$') ]] && jq 'del(.listBlan)' /opt/de_GWD/0conf | sponge /opt/de_GWD/0conf
[[ -n $(jq '.listWlan' /opt/de_GWD/0conf | grep -v '^null$') ]] && jq 'del(.listWlan)' /opt/de_GWD/0conf | sponge /opt/de_GWD/0conf
[[ -n $(jq '.dns.APPLEcn' /opt/de_GWD/0conf | grep -v '^null$') ]] && jq 'del(.dns.APPLEcn)' /opt/de_GWD/0conf | sponge /opt/de_GWD/0conf
[[ -n $(jq '.dns.STEAMcn' /opt/de_GWD/0conf | grep -v '^null$') ]] && jq 'del(.dns.STEAMcn)' /opt/de_GWD/0conf | sponge /opt/de_GWD/0conf
[[ -n $(jq '.v2nodeDIV.directApple' /opt/de_GWD/0conf | grep -v '^null$') ]] && jq 'del(.v2nodeDIV.directApple)' /opt/de_GWD/0conf | sponge /opt/de_GWD/0conf
[[ -n $(jq '.v2nodeDIV.directSteam' /opt/de_GWD/0conf | grep -v '^null$') ]] && jq 'del(.v2nodeDIV.directSteam)' /opt/de_GWD/0conf | sponge /opt/de_GWD/0conf
dohORI=$(jq -r '.dns.DOH' /opt/de_GWD/0conf | grep -v '^null$')
dogORI=$(jq -r '.dns.DoG' /opt/de_GWD/0conf | grep -v '^null$')
[[ -n $dohORI ]] && jq --argjson doh "$dohORI" '.dns.doh=$doh' /opt/de_GWD/0conf | jq 'del(.dns.DOH)' | sponge /opt/de_GWD/0conf
[[ -n $dogORI ]] && jq --arg dog "$dogORI" '.dns.dog=$dog' /opt/de_GWD/0conf | jq 'del(.dns.DoG)' | sponge /opt/de_GWD/0conf
adlists=$(jq -r '.dns.adlistsURL' /opt/de_GWD/0conf 2>/dev/null | grep -v '^null$')
[[ -n $(jq '.[]' <<< "$adlists") ]] && jq --argjson adlists "$adlists" '.dns.adlists=$adlists' /opt/de_GWD/0conf | sponge /opt/de_GWD/0conf
adBlist=$(jq -r '.dns.adBlistURL' /opt/de_GWD/0conf 2>/dev/null | grep -v '^null$')
[[ -n $(jq '.[]' <<< "$adBlist") ]] && jq --argjson adBlist "$adBlist" '.dns.adBlist=$adBlist' /opt/de_GWD/0conf | sponge /opt/de_GWD/0conf
adBregex=$(jq -r '.dns.regexRule' /opt/de_GWD/0conf 2>/dev/null | grep -v '^null$')
[[ -n $(jq '.[]' <<< "$adBregex") ]] && jq --argjson adBregex "$adBregex" '.dns.adBregex=$adBregex' /opt/de_GWD/0conf | sponge /opt/de_GWD/0conf
adWlist=$(jq -r '.dns.adWlistURL' /opt/de_GWD/0conf 2>/dev/null | grep -v '^null$')
[[ -n $(jq '.[]' <<< "$adWlist") ]] && jq --argjson adWlist "$adWlist" '.dns.adWlist=$adWlist' /opt/de_GWD/0conf | sponge /opt/de_GWD/0conf
jq 'del(.dns.adlistsURL)' /opt/de_GWD/0conf |\
jq 'del(.dns.regexRule)' |\
jq 'del(.dns.adWlistURL)' |\
jq 'del(.dns.adBlistURL)' | sponge /opt/de_GWD/0conf
[[ -d "/opt/bitwardenrs" ]] && mv -f /opt/bitwardenrs /opt/bitwarden
if [[ -f "/etc/systemd/system/doh-client.service" ]] || [[ -f "/lib/systemd/system/doh-client.service" ]]; then
systemctl disable --now doh-client >/dev/null 2>&1
rm -rf /lib/systemd/system/doh-client.service
rm -rf /etc/systemd/system/doh-client.service
rm -rf /opt/de_GWD/doh-client*
rm -rf "/etc/NetworkManager/dispatcher.d"
systemctl daemon-reload >/dev/null
fi
if [[ -f "/etc/systemd/system/doh-server.service" ]] || [[ -f "/lib/systemd/system/doh-server.service" ]]; then
systemctl disable --now doh-server >/dev/null 2>&1
rm -rf /lib/systemd/system/doh-server.service
rm -rf /etc/systemd/system/doh-server.service
rm -rf /opt/de_GWD/doh-server*
rm -rf "/etc/NetworkManager/dispatcher.d"
systemctl daemon-reload >/dev/null
fi
if [[ -f "/etc/systemd/system/iptables-proxy.service" ]] || [[ -f "/lib/systemd/system/iptables-proxy.service" ]]; then
systemctl disable iptables-proxy >/dev/null 2>&1
rm -rf /etc/systemd/system/iptables-proxy.service >/dev/null 2>&1
rm -rf /lib/systemd/system/iptables-proxy.service >/dev/null 2>&1
systemctl daemon-reload >/dev/null
/opt/de_GWD/iptables-proxy-down
rm -rf /opt/de_GWD/iptables-proxy-down
rm -rf /opt/de_GWD/iptables-proxy-up
fi
if [[ -d "/opt/de_GWD/xDNSc" ]]; then
systemctl disable xDNSc >/dev/null 2>&1
systemctl stop xDNSc >/dev/null 2>&1
rm -rf /etc/systemd/system/xDNSc.service
rm -rf /lib/systemd/system/xDNSc.service
systemctl daemon-reload >/dev/null
rm -rf /opt/de_GWD/xDNSc
jq 'del(.dns.xDNS)' /opt/de_GWD/0conf | sponge /opt/de_GWD/0conf
fi
if [[ -d "/opt/de_GWD/xDNSs" ]]; then
systemctl disable xDNSs >/dev/null 2>&1
systemctl stop xDNSs >/dev/null 2>&1
rm -rf /etc/systemd/system/xDNSs.service
rm -rf /lib/systemd/system/xDNSs.service
systemctl daemon-reload >/dev/null
rm -rf /opt/de_GWD/xDNSs
jq 'del(.FORWARD.xDNSs)' /opt/de_GWD/0conf | sponge /opt/de_GWD/0conf
fi
if [[ `dpkg -l | grep php | grep fpm | awk '{print $2}'` = "php7.3-fpm" ]] || [[ `dpkg -l | grep php | grep fpm | awk '{print $2}'` = "php8.0-fpm" ]]; then
rm -rf /etc/php/7.3/
apt remove --purge '^php7.3.*'
rm -rf /etc/php/8.0/
apt remove --purge '^php8.0.*'
fi
[[ -f "/etc/nginx/off" ]] && rm -rf /etc/nginx/off
rm -rf /etc/dnsmasq.d/89-bogus-domains.china.conf
rm -rf /etc/dnsmasq.d/89-bogus-nxdomains.china.conf
[[ -n $(dpkg -l | awk '{print$2}' | grep '^smartdns$') ]] && rm -rf /etc/smartdns && apt remove --purge smartdns
[[ -n $(systemctl cat v2dns 2>/dev/null) ]] && systemctl disable --now v2dns >/dev/null 2>&1 && \
rm -rf /lib/systemd/system/v2dns.service && \
rm -rf /etc/systemd/system/v2dns.service && \
rm -rf /opt/de_GWD/v2dns
[[ -n $(dpkg -l | awk '{print$2}' | grep '^haveged$') ]] && apt remove --purge haveged
[[ -n $(dpkg -l | awk '{print$2}' | grep '^subversion$') ]] && apt remove --purge subversion
rm -rf /etc/pihole/migration_backup
rm -rf /etc/dnsmasq.d/89-bogus-nxdomain.china.conf
rm -rf /etc/apt/sources.list.d/unstable.list
rm -rf /etc/apt/preferences.d/limit-unstable
rm -rf /opt/de_GWD/.repo/vtrui.zip
rm -rf /opt/de_GWD/chnroute.txt
rm -rf /opt/de_GWD/Q4am
rm -rf /opt/de_GWD/Q4H
rm -rf /opt/de_GWD/Q2H
rm -rf /etc/dns-over-https
rm -rf /usr/bin/vtrui
rm -rf /usr/local/bin/yq
rm -rf /usr/sbin/yq
rm -rf /etc/vtrui
rm -rf /opt/de_GWD/ttyd
rm -rf /opt/de_GWD/IPxDNSSET
rm -rf /opt/de_GWD/chnrouteSET
rm -rf /opt/de_GWD/IPGlobalDNSSET
rm -rf /opt/de_GWD/IPlistBlanSET
rm -rf /opt/de_GWD/IPlistBSET
rm -rf /opt/de_GWD/IPlistWlanSET
rm -rf /opt/de_GWD/IPlistWSET
rm -rf /opt/de_GWD/IPv2nodeSET
rm -rf /opt/de_GWD/__MACOSX
rm -rf /opt/de_GWD/clearKernel
rm -rf /var/www/html/__MACOSX
rm -rf /var/log/smartdns.log
rm -rf /etc/dnsmasq.d/00-wg.conf
rm -rf /etc/dnsmasq.d/99-extra.conf
[[ -f "/etc/rc.local" ]] && rm -rf /etc/rc.local
if [[ -n $(systemctl list-unit-files --type=service | grep 'rc_online') ]]; then
systemctl stop rc_online
rm -rf /etc/systemd/system/rc_online.service
systemctl daemon-reload >/dev/null
fi
echo -e "${WHITE}[ ${GREEN}✓ ${WHITE}]\c" && echo -e "\t${WHITE}Clean-up${cRES}"
}
preUpdate(){
echo -e "${BLUE}################################################################# ${cRES}"
echo -e "${GREEN}DNS information${cRES}"
echo
ethernetnum=$(find /sys/class/net ! -type d | xargs --max-args=1 realpath | grep 'device' | xargs -n 1 | grep -v 'virtual' | grep -v 'ifb' | awk -F'/' '{print$NF}' | head -n1)
gatewayAddr=$(jq -r '.address.upstreamIP' /opt/de_GWD/0conf | grep -Po '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}')
localAddrCIDR=$(jq -r '.address.localIP' /opt/de_GWD/0conf | grep -v '^null$')
localAddr=$(echo $localAddrCIDR | cut -d / -f1)
netmask=$(echo $localAddrCIDR | sed -r 's/([0-9]{1,3}\.){3}[0-9]{1,3}//g')
if [[ -n $netmask ]]; then
localCIDR="$(echo $localAddr | cut -d . -f1-3).0$netmask"
else
netmask="/24"
localAddrCIDR="$localAddr$netmask"
localCIDR="$(echo $localAddr | cut -d . -f1-3).0$netmask"
fi
DoG=$(jq -r '.dns.dog' /opt/de_GWD/0conf 2>/dev/null | grep -v '^null$')
doh1=$(jq -r '.dns.doh[]' /opt/de_GWD/0conf 2>/dev/null | grep -v '^null$' | awk NR==1)
doh2=$(jq -r '.dns.doh[]' /opt/de_GWD/0conf 2>/dev/null | grep -v '^null$' | awk NR==2)
[[ -n $doh1 ]] && echo -e "\t${WHITE}DNS over Https 1: \c" && echo -e "${YELLOW}$doh1${cRES}"
[[ -n $doh2 ]] && echo -e "\t${WHITE}DNS over Https 2: \c" && echo -e "${YELLOW}$doh2${cRES}"
[[ -n $DoG ]] && echo -e "\t${WHITE}DNS over gRPC : \c" && echo -e "${YELLOW}$DoG${cRES}"
domain=$(jq -r '.update.v2node.domain' /opt/de_GWD/0conf 2>/dev/null | grep -v '^null$')
tls=$(jq -r '.update.v2node.tls' /opt/de_GWD/0conf 2>/dev/null | grep -v '^null$')
port=$(jq -r '.update.v2node.port' /opt/de_GWD/0conf 2>/dev/null | grep -v '^null$')
uuid=$(jq -r '.update.v2node.uuid' /opt/de_GWD/0conf 2>/dev/null | grep -v '^null$')
path=$(jq -r '.update.v2node.path' /opt/de_GWD/0conf 2>/dev/null | grep -v '^null$')
if [[ -z $domain ]] || [[ -z $uuid ]]; then
cp -f /opt/de_GWD/0conf_bak /opt/de_GWD/0conf
clear
preUpdate
fi
[[ -z $tls ]] && tls=$domain
piholePW=$(jq -r '.address.PWD' /opt/de_GWD/0conf 2>/dev/null | grep -v '^null$')
serverName=$(jq -r '.address.serverName' /opt/de_GWD/0conf 2>/dev/null | grep -v '^null$')
webUIport=$(jq -r '.address.webUIport' /opt/de_GWD/0conf 2>/dev/null | grep -v '^null$')
updatePort=$(jq -r '.update.updatePort' /opt/de_GWD/0conf 2>/dev/null | grep -v '^null$')
echo
echo -e "${GREEN}Node Information${cRES}"
echo
echo -e "\t${WHITE}Domain : \c" && echo -e "${YELLOW}$domain${cRES}"
echo -e "\t${WHITE}Port : \c" && echo -e "${YELLOW}$port${cRES}"
echo -e "\t${WHITE}UUID : \c" && echo -e "${YELLOW}$uuid${cRES}"
echo -e "\t${WHITE}Path : \c" && echo -e "${YELLOW}$path${cRES}"
echo -e "${BLUE}################################################################# ${cRES}"
echo
}
de_GWDconnect(){
if [[ $1 = "u" ]]; then
echo -e "${WHITE}de_GWD server connect ${cRES}\c" && echo -e "\t${WHITE}[...]${cRES}\r\c"
else
echo -e "\t${WHITE}de_GWD server connect${cRES}\r\c"
fi
local serverConnect1=$(curl -Is -m 5 google.com)
local serverConnect2=$(curl -Is -m 5 youtube.com)
if [[ $1 = "u" ]]; then
if [[ $2 = "a" ]]; then
preDL
updateGWD_Green
[[ -z $serverConnect1 ]] || [[ -z $serverConnect2 ]] && exit
else
if [[ -n $serverConnect1 ]] && [[ -n $serverConnect2 ]] && [[ $(systemctl is-active 'vtrui') = "active" ]]; then
echo -e "${WHITE}de_GWD server connect ${cRES}\c" && echo -e "\t${WHITE}[${GREEN} ✓ ${WHITE}]${cRES}"
de_GWDconnect_check="OK"
echo -e "${GREEN}================================= ${cRES}"
echo -e "${GREEN}[Y]: Full Update${cRES}"
echo -e "${GREEN}[*]: Any other key to Fast Update${cRES}"
echo -e "${GREEN}================================= ${cRES}"
read -s -n 1 updateDebian
echo -e "${WHITE}[...]\c" && echo -e "\t${WHITE}Start Updating de_GWD${cRES}\r\c"
if [[ $updateDebian = "Y" ]] || [[ $updateDebian = "y" ]]; then
preDL
updateAPT
fi
preDL
updateGWD_Green
else
echo -e "${WHITE}de_GWD server connect ${cRES}\c" && echo -e "\t${WHITE}[${RED} ✕ ${WHITE}]${cRES}"
updateGWD_Red
fi
fi
else
if [[ -n $serverConnect1 ]] && [[ -n $serverConnect2 ]] && [[ $(systemctl is-active 'vtrui') = "active" ]]; then
echo -e "${WHITE}[ ${GREEN}✓ ${WHITE}]\c" && echo -e "\t${WHITE}de_GWD server connect${cRES}"
else
echo -e "${WHITE}[ ${RED}✕ ${WHITE}]\c" && echo -e "\t${WHITE}de_GWD server connect${cRES}"
fi
if [[ -z $serverConnect1 ]] || [[ -z $serverConnect2 ]]; then
cat << EOF >/etc/resolv.conf
nameserver 119.29.29.29
nameserver 180.76.76.76
nameserver 114.114.114.114
nameserver 223.5.5.5
EOF
systemctl stop smartdns >/dev/null 2>&1
systemctl stop nftables >/dev/null 2>&1
exit
fi
fi
}
preInstall(){
sync; echo 3 >/proc/sys/vm/drop_caches >/dev/null 2>&1
if [[ $(systemctl is-active swap.target) != "active" ]]; then
systemctl unmask swap.target >/dev/null 2>&1
systemctl start swap.target >/dev/null 2>&1
fi
if [[ $(free -m | awk 'NR==3{print$2}') = "0" ]] && [[ $virt_type != "container" ]]; then
if [[ $(df -T / | awk '{print$2}' | tail -n 1) = "btrfs" ]]; then
btrfs subvolume create /swap 2>/dev/null
btrfs filesystem mkswapfile --size 1g --uuid clear /swap/swapfile 2>/dev/null
swapon /swap/swapfile
sed -i "/swapfile/d" /etc/fstab
echo "/swap/swapfile none swap defaults 0 0" >>/etc/fstab
else
fallocate -l 1G /swapfile 2>/dev/null
dd if=/dev/zero of=/swapfile bs=1M count=1024 status=progress 2>/dev/null
chmod 600 /swapfile
mkswap -U clear /swapfile
swapon /swapfile
sed -i "/swapfile/d" /etc/fstab
echo "/swapfile none swap defaults 0 0" >>/etc/fstab
fi
echo "RESUME=" >/etc/initramfs-tools/conf.d/resume
fi
cat << EOF >/etc/apt/apt.conf.d/01InstallLess
APT::Get::Assume-Yes "true";
APT::Install-Recommends "false";
APT::Install-Suggests "false";
EOF
cat << EOF >/etc/apt/apt.conf.d/71debconf
Dpkg::Options {
"--force-confdef";
"--force-confold";
};
EOF
sed -i '/ulimit -SHn/d' /etc/profile
sed -i '/ulimit -c/d' /etc/profile
sed -i '/ulimit -d/d' /etc/profile
sed -i '/ulimit -f/d' /etc/profile
sed -i '/ulimit -m/d' /etc/profile
sed -i '/ulimit -s/d' /etc/profile
sed -i '/ulimit -t/d' /etc/profile
sed -i '/ulimit -u/d' /etc/profile
sed -i '/ulimit -v/d' /etc/profile
sed -i '/HISTCONTROL=/d' /etc/profile
sed -i '/alias reboot=/d' /etc/profile
cat << EOF >>/etc/profile
ulimit -SHn 1000000
ulimit -t 65536
ulimit -u 65536
ulimit -c 65536
ulimit -d unlimited
ulimit -f unlimited
ulimit -s unlimited
ulimit -v unlimited
HISTCONTROL=ignoredups
alias reboot="sudo systemctl reboot"
EOF
source /etc/profile
sed -i '/pam_limits.so/d' /etc/pam.d/common-session
echo "session required pam_limits.so" >>/etc/pam.d/common-session
cat << EOF >/etc/security/limits.conf
root soft nofile 1000000
root hard nofile 1000000
root soft nproc 1000000
root hard nproc 1000000
root soft core 1000000
root hard core 1000000
root hard memlock unlimited
root soft memlock unlimited
www-data soft nofile 1000000
www-data hard nofile 1000000
www-data soft nproc 1000000
www-data hard nproc 1000000
www-data soft core 1000000
www-data hard core 1000000
www-data hard memlock unlimited
www-data soft memlock unlimited
* soft nofile 1000000
* hard nofile 1000000
* soft nproc 1000000
* hard nproc 1000000
* soft core 1000000
* hard core 1000000
* hard memlock unlimited
* soft memlock unlimited
EOF
sed -i '/DefaultLimitCORE/d' /etc/systemd/system.conf
sed -i '/DefaultLimitNOFILE/d' /etc/systemd/system.conf
sed -i '/DefaultLimitNPROC/d' /etc/systemd/system.conf
cat << EOF >>/etc/systemd/system.conf
DefaultLimitCORE=1000000
DefaultLimitNOFILE=1000000
DefaultLimitNPROC=1000000
EOF
systemctl daemon-reload
rm -f /var/cache/apt/archives/lock
rm -f /var/lib/apt/lists/lock
rm -f /var/lib/dpkg/lock
rm -f /var/lib/dpkg/lock-frontend
dpkg --configure -a
pkgDEP1
cat << EOF >/etc/default/rng-tools-debian
# -*- mode: sh -*-
#-
# Configuration for the rng-tools-debian initscript
# Set to the input source for random data, leave undefined
# for the initscript to attempt auto-detection. Set to /dev/null
# for the viapadlock driver.
#HRNGDEVICE=/dev/hwrng
#HRNGDEVICE=/dev/null
HRNGDEVICE=/dev/urandom
# Additional options to send to rngd. See the rngd(8) manpage for
# more information. Do not specify -r/--rng-device here, use
# HRNGDEVICE for that instead.
#RNGDOPTIONS="--hrng=intelfwh --fill-watermark=90% --feed-interval=1"
#RNGDOPTIONS="--hrng=viakernel --fill-watermark=90% --feed-interval=1"
#RNGDOPTIONS="--hrng=viapadlock --fill-watermark=90% --feed-interval=1"
# For TPM (also add tpm-rng to /etc/initramfs-tools/modules or /etc/modules):
#RNGDOPTIONS="--fill-watermark=90% --feed-interval=1"
# If you need to configure which RNG to use, do it here:
#HRNGSELECT="virtio_rng.0"
# Use this instead of sysfsutils, which starts too late.
EOF
systemctl restart rng-tools
cat << EOF >/etc/chrony/chrony.conf
server time.cloud.tencent.com iburst
server time4.cloud.tencent.com iburst
server time5.cloud.tencent.com iburst
server ntp.aliyun.com iburst
server ntp6.aliyun.com iburst
server ntp7.aliyun.com iburst
driftfile /var/lib/chrony/chrony.drift
logdir /var/log/chrony
maxupdateskew 100.0
rtcsync
makestep 1 3
leapsectz right/UTC
EOF
systemctl restart chrony
systemctl enable chrony >/dev/null 2>&1
rm -rf /etc/systemd/resolved.conf >/dev/null 2>&1
systemctl daemon-reload >/dev/null
systemctl mask --now systemd-resolved >/dev/null 2>&1
[[ -n $(which setenforce) ]] && setenforce 0
[[ -f "/etc/selinux/config" ]] && sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
ip rule del table 220 >/dev/null 2>&1
ip route flush table 220 >/dev/null 2>&1
ip route flush cache >/dev/null 2>&1
ip route del local default dev lo table 220 >/dev/null 2>&1
[[ -n $(systemctl cat nftables 2>/dev/null) ]] && systemctl stop nftables >/dev/null 2>&1
[[ -n $(systemctl cat vtrui 2>/dev/null) ]] && systemctl stop vtrui >/dev/null 2>&1
[[ -n "$(ps -e | grep 'pihole-FTL' )" ]] && systemctl stop pihole-FTL
kill -9 $(ps -e | grep 'pihole' | awk '{print$1}') >/dev/null 2>&1
cat << EOF >/etc/resolv.conf
nameserver 119.29.29.29
nameserver 180.76.76.76
nameserver 114.114.114.114
nameserver 223.5.5.5
EOF
}
preConf(){
echo -e "${WHITE}[...]\c" && echo -e "\t${WHITE}System Config${cRES}\r\c"
localeSet=`cat << EOF
LANG=en_US.UTF-8
LANGUAGE=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=en_US.UTF-8
EOF
`
if [[ -z $(localectl list-locales | grep "en_US.UTF-8") ]]; then
echo "$localeSet" >/etc/default/locale
echo "en_US.UTF-8 UTF-8" >/etc/locale.gen
locale-gen "en_US.UTF-8"
localectl set-locale en_US.UTF-8
update-locale LANG=en_US.UTF-8 LANGUAGE=en_US.UTF-8 LC_ALL=en_US.UTF-8
fi
[[ $(date +"%Z %z") != "CST +0800" ]] && timedatectl set-timezone "Asia/Shanghai"
timedatectl set-local-rtc 0 >/dev/null 2>&1
timedatectl set-ntp true
sed -i '/nf_conntrack/d' /etc/modules-load.d/modules.conf
sed -i '/ifb/d' /etc/modules-load.d/modules.conf
cat << EOF >>/etc/modules-load.d/modules.conf
nf_conntrack
ifb
sch_cake
EOF
modprobe nf_conntrack
modprobe ifb
modprobe sch_cake
cat << EOF >/etc/sysctl.conf
vm.overcommit_memory = 1
vm.swappiness = 5
vm.dirty_ratio = 10
vm.dirty_background_ratio = 5
fs.file-max = 1000000
fs.inotify.max_user_instances = 819200
fs.inotify.max_queued_events = 32000
fs.inotify.max_user_watches = 64000
net.unix.max_dgram_qlen = 10240
net.netfilter.nf_conntrack_acct = 0
net.netfilter.nf_conntrack_checksum = 0
net.netfilter.nf_conntrack_events = 1
net.netfilter.nf_conntrack_timestamp = 0
net.netfilter.nf_conntrack_max = 1048576
net.netfilter.nf_conntrack_buckets = 65536
net.netfilter.nf_conntrack_tcp_loose = 1
net.netfilter.nf_conntrack_tcp_be_liberal = 1
net.netfilter.nf_conntrack_tcp_max_retrans = 3
net.netfilter.nf_conntrack_generic_timeout = 60
net.netfilter.nf_conntrack_tcp_timeout_unacknowledged = 30
net.netfilter.nf_conntrack_tcp_timeout_fin_wait = 30
net.netfilter.nf_conntrack_tcp_timeout_time_wait = 30
net.netfilter.nf_conntrack_tcp_timeout_close_wait = 15
net.netfilter.nf_conntrack_tcp_timeout_close = 5
net.netfilter.nf_conntrack_tcp_timeout_last_ack = 30
net.netfilter.nf_conntrack_tcp_timeout_syn_recv = 30
net.netfilter.nf_conntrack_tcp_timeout_syn_sent = 30
net.netfilter.nf_conntrack_tcp_timeout_established = 3600
net.netfilter.nf_conntrack_sctp_timeout_established = 3600
net.netfilter.nf_conntrack_udp_timeout = 15
net.netfilter.nf_conntrack_udp_timeout_stream = 45
net.core.somaxconn = 65536
net.core.netdev_max_backlog = 262144
net.core.optmem_max = 262144
net.core.rmem_default = 262144
net.core.wmem_default = 262144
net.core.rmem_max = 33554432
net.core.wmem_max = 33554432
net.mptcp.enabled = 1
net.ipv4.conf.all.arp_accept = 0
net.ipv4.conf.default.arp_accept = 0
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.default.arp_ignore = 1
net.ipv4.conf.all.rp_filter = 0
net.ipv4.conf.default.rp_filter = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv4.conf.all.secure_redirects = 0
net.ipv4.conf.default.secure_redirects = 0
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.default.accept_source_route = 0
net.ipv4.conf.all.route_localnet = 1
net.ipv4.route.flush = 1
net.ipv4.ip_local_port_range = 1024 65535
net.ipv4.ip_local_reserved_ports = 3000
net.ipv4.ip_forward = 1
net.ipv4.conf.all.forwarding = 1
net.ipv4.conf.default.forwarding = 1
net.ipv4.ip_no_pmtu_disc = 0
net.ipv4.udp_rmem_min = 262144
net.ipv4.udp_wmem_min = 262144
net.ipv4.tcp_mem = 16384 131072 524288
net.ipv4.tcp_rmem = 8192 262144 16777216
net.ipv4.tcp_wmem = 8192 262144 16777216
net.ipv4.tcp_max_tw_buckets = 131072
net.ipv4.tcp_max_orphans = 131072
net.ipv4.tcp_max_syn_backlog = 32768
net.ipv4.tcp_limit_output_bytes = 1048576
net.ipv4.tcp_adv_win_scale = 1
net.ipv4.tcp_moderate_rcvbuf = 1
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_workaround_signed_windows = 0
net.ipv4.tcp_mtu_probing = 0
net.ipv4.tcp_mtu_probe_floor = 48
net.ipv4.tcp_base_mss = 1024
net.ipv4.tcp_no_metrics_save = 0
net.ipv4.tcp_no_ssthresh_metrics_save = 1
net.ipv4.tcp_sack = 1
net.ipv4.tcp_dsack = 1
net.ipv4.tcp_frto = 0
net.ipv4.tcp_recovery = 1
net.ipv4.tcp_early_retrans = 3
net.ipv4.tcp_min_rtt_wlen = 120
net.ipv4.tcp_reordering = 3
net.ipv4.tcp_ecn = 0
net.ipv4.tcp_fin_timeout = 10
net.ipv4.tcp_fastopen = 3
net.ipv4.tcp_fastopen_blackhole_timeout_sec = 0
net.ipv4.tcp_fastopen_key = 00000000-00000000-00000000-00000000
net.ipv4.tcp_keepalive_time = 7200
net.ipv4.tcp_keepalive_intvl = 75
net.ipv4.tcp_keepalive_probes = 9
net.ipv4.tcp_timestamps = 1
net.ipv4.tcp_syncookies = 0
net.ipv4.tcp_tw_reuse = 2
net.ipv4.tcp_syn_retries = 2
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_retries1 = 3
net.ipv4.tcp_retries2 = 8
net.ipv4.tcp_orphan_retries = 0
net.ipv4.tcp_challenge_ack_limit = 100000
net.ipv4.tcp_slow_start_after_idle = 0
net.ipv4.tcp_autocorking = 0
net.ipv4.tcp_rfc1337 = 1
net.core.default_qdisc = cake
EOF
sed -i '/net.ipv4.tcp_congestion_control/d' /etc/sysctl.conf
if [[ $(uname -r) =~ "bbrplus" ]]; then
echo "net.ipv4.tcp_congestion_control = bbrplus" >>/etc/sysctl.conf
else
echo "net.ipv4.tcp_congestion_control = bbr" >>/etc/sysctl.conf
fi
sync
sysctl -p >/dev/null 2>&1
if [[ -n $(dpkg -l | awk '{print$2}' | grep '^docker-ce$') ]] && [[ -n $(dpkg -l | awk '{print$2}' | grep '^containerd.io$') ]]; then
mkdir -p /etc/docker/
systemctl stop docker docker.socket containerd
cat << EOF >/etc/docker/daemon.json
{
"iptables": false
}
EOF
systemctl restart docker
fi
cat << EOF >/etc/rc_online.local
#!/bin/bash
echo madvise >/sys/kernel/mm/transparent_hugepage/enabled
$(which ip) route show table local | grep ' dev lo ' | while read line; do
line=\$(echo \$line | awk -F' mtu ' '{print\$1}')
$(which ip) route change \$line mtu 65520 initcwnd 1000 initrwnd 1000 fastopen_no_cookie 1 congctl lock cubic
done
NIC_local=\$($(which ip) route | grep -v 'scope link' | awk -F' dev ' '{print\$2}' | cut -d' ' -f1)
$(which ip) route show table local | grep " dev \$NIC_local " | while read line; do
line=\$(echo \$line | awk -F' mtu ' '{print\$1}')
$(which ip) route change \$line mtu 1500 fastopen_no_cookie 1 congctl lock $(sysctl net.ipv4.tcp_congestion_control | awk -F' = ' '{print$2}')
done
$(which ip) route | grep " dev \$NIC_local " | while read line; do
line=\$(echo \$line | awk -F' mtu ' '{print\$1}')
$(which ip) route change \$line mtu 1500 fastopen_no_cookie 1 congctl lock $(sysctl net.ipv4.tcp_congestion_control | awk -F' = ' '{print$2}')
done
NIC_device=\$(find /sys/class/net ! -type d | xargs --max-args=1 realpath | grep 'device')
for ifb in \$(echo \$NIC_device | xargs -n 1 | grep 'virtual' | awk -F'/' '{print\$NF}' | grep '^ifb'); do
$(which ip) link set \$ifb down
$(which ip) link delete \$ifb
done
$(which ip) link set lo qlen 1000000 mtu 65520
$(which tc) qdisc del dev lo root >/dev/null 2>&1
$(which tc) qdisc add dev lo root cake unlimited rtt 10us diffserv4 dual-srchost no-split-gso no-ack-filter raw egress
$(which ip) link add name ifb4lo type ifb >/dev/null 2>&1
$(which tc) qdisc del dev lo ingress >/dev/null 2>&1
$(which tc) qdisc add dev lo handle ffff: ingress
$(which tc) qdisc del dev ifb4lo root >/dev/null 2>&1
$(which tc) qdisc add dev ifb4lo root cake unlimited rtt 10us diffserv4 dual-dsthost no-split-gso no-ack-filter raw ingress
$(which ip) link set ifb4lo qlen 1000000 mtu 65520
$(which ip) link set ifb4lo up
$(which tc) filter add dev lo parent ffff: matchall action mirred egress redirect dev ifb4lo
echo \$NIC_device | xargs -n 1 | grep 'virtual' | awk -F'/' '{print\$NF}' | grep -v 'docker' | grep -v 'ifb' | grep -v '^lo\$' | while read line; do
MTU_NUM=\$(< /sys/class/net/\$line/mtu)
ifb4eth=\$(echo "ifb4\$line" | cut -c 1-15)
$(which ip) link set \$line qlen 4096 mtu \$MTU_NUM
$(which tc) qdisc del dev \$line root >/dev/null 2>&1
$(which tc) qdisc add dev \$line root cake unlimited rtt 10us diffserv4 dual-srchost nonat nowash no-split-gso ack-filter raw overhead 18 mpu 64 noatm egress
$(which ip) link add name \$ifb4eth type ifb >/dev/null 2>&1
$(which tc) qdisc del dev \$line ingress >/dev/null 2>&1
$(which tc) qdisc add dev \$line handle ffff: ingress
$(which tc) qdisc del dev \$ifb4eth root >/dev/null 2>&1
$(which tc) qdisc add dev \$ifb4eth root cake unlimited rtt 10us diffserv4 dual-dsthost nonat nowash no-split-gso ack-filter raw overhead 18 mpu 64 noatm ingress
$(which ip) link set \$ifb4eth qlen 4096 mtu \$MTU_NUM
$(which ip) link set \$ifb4eth up
$(which tc) filter add dev \$line parent ffff: matchall action mirred egress redirect dev \$ifb4eth
done
echo \$NIC_device | xargs -n 1 | grep -v 'virtual' | awk -F'/' '{print\$NF}' | while read line; do
MTU_NUM=\$(< /sys/class/net/\$line/mtu)
ifb4eth=\$(echo "ifb4\$line" | cut -c 1-15)
$(which ip) link set \$line qlen 4096 mtu \$MTU_NUM
$(which tc) qdisc del dev \$line root >/dev/null 2>&1
$(which tc) qdisc add dev \$line root cake unlimited diffserv4 dual-srchost nonat nowash no-split-gso ack-filter ethernet egress
$(which ip) link add name \$ifb4eth type ifb >/dev/null 2>&1
$(which tc) qdisc del dev \$line ingress >/dev/null 2>&1
$(which tc) qdisc add dev \$line handle ffff: ingress
$(which tc) qdisc del dev \$ifb4eth root >/dev/null 2>&1
$(which tc) qdisc add dev \$ifb4eth root cake unlimited diffserv4 dual-dsthost nonat nowash no-split-gso ack-filter ethernet ingress
$(which ip) link set \$ifb4eth qlen 4096 mtu \$MTU_NUM
$(which ip) link set \$ifb4eth up
$(which tc) filter add dev \$line parent ffff: matchall action mirred egress redirect dev \$ifb4eth
$(which ethtool) -s \$line duplex full >/dev/null 2>&1
$(which ethtool) -K \$line rx on rx-all on rx-gro on tx on sg on tso on gso on gro on >/dev/null 2>&1
done
$(which ip) tcp_metrics flush
$(which ip) route flush cache
EOF
chmod +x /etc/rc_online.local
mkdir -p /etc/systemd/system/networking.service.d/
cat << EOF >/etc/systemd/system/networking.service.d/override.conf
[Service]
ExecStartPost=/etc/rc_online.local
EOF
systemctl daemon-reload >/dev/null
/etc/rc_online.local
echo -e "${WHITE}[ ${GREEN}✓ ${WHITE}]\c" && echo -e "\t${WHITE}System Config${cRES}"
}
installSmartDNS(){
echo -e "${WHITE}[...]\c" && echo -e "\t${WHITE}Proxy Components Prepared${cRES}\r\c"
if [[ -n $(unzip -tq /opt/de_GWD/.repo/de_GWD.zip | grep "No errors detected in compressed data") ]]; then
rm -rf /opt/de_GWD/smartdns
rm -rf /opt/de_GWD/coredns
rm -rf /opt/de_GWD/mosdns
rm -rf /opt/de_GWD/vtrui
mkdir -p /opt/de_GWD/smartdns
mkdir -p /opt/de_GWD/coredns
mkdir -p /opt/de_GWD/mosdns
mkdir -p /opt/de_GWD/vtrui
rm -rf /tmp/de_GWD
unzip /opt/de_GWD/.repo/de_GWD.zip -d /tmp/de_GWD >/dev/null
cp -f /tmp/de_GWD/yq /usr/bin/yq
cp -f /tmp/de_GWD/smartdns /opt/de_GWD/smartdns/smartdns
cp -f /tmp/de_GWD/coredns /opt/de_GWD/coredns/coredns
cp -f /tmp/de_GWD/mosdns /opt/de_GWD/mosdns/mosdns
cp -f /tmp/de_GWD/xray /opt/de_GWD/vtrui/vtrui
chmod +x /usr/bin/yq
chmod +x /opt/de_GWD/smartdns/smartdns
chmod +x /opt/de_GWD/coredns/coredns
chmod +x /opt/de_GWD/mosdns/mosdns
chmod +x /opt/de_GWD/vtrui/vtrui
rm -rf /tmp/de_GWD*
else
rm -rf /opt/de_GWD/.repo/de_GWD.zip
echo -e "${WHITE}de_GWD Zip${RED} Download Failed${cRES}" && exit
fi
echo -e "${WHITE}[ ${GREEN}✓ ${WHITE}]\c" && echo -e "\t${WHITE}Proxy Components Prepared${cRES}"
rm -rf /lib/systemd/system/coredns.service
cat << EOF >/etc/systemd/system/coredns.service
[Unit]
Description=CoreDNS DNS server
After=network.target
[Service]
User=root
Type=simple
ExecStart=/opt/de_GWD/coredns/coredns -conf /opt/de_GWD/coredns/corefile
ExecReload=$(which kill) -SIGUSR1 \$MAINPID
KillMode=process
Restart=always
RestartSec=2
TimeoutStopSec=5
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload >/dev/null
rm -rf /lib/systemd/system/mosdns.service
cat << EOF >/etc/systemd/system/mosdns.service
[Unit]
Description=mosdns
ConditionFileIsExecutable=/opt/de_GWD/mosdns/mosdns
[Service]
User=root
Type=simple
ExecStart=/opt/de_GWD/mosdns/mosdns start --as-service -d /opt/de_GWD/mosdns
ExecStop=$(which kill) -s STOP \$MAINPID
KillMode=process
Restart=always
RestartSec=2
TimeoutStopSec=5