-
Notifications
You must be signed in to change notification settings - Fork 185
/
Copy pathserver
executable file
·2357 lines (1958 loc) · 75.5 KB
/
server
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)
[[ "openvz lxc lxc-libvirt systemd-nspawn docker podman proot pouch" =~ $(systemd-detect-virt) ]] && virt_type="container"
export DEBIAN_FRONTEND=noninteractive
branch="main"
[[ -f "/etc/nginx/conf.d/default.conf" ]] && sed -i 's/fastopen=128/fastopen=500/g' /etc/nginx/conf.d/default.conf
pkgDEP(){
[[ -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 '^subversion$') ]] && apt remove --purge subversion
[[ -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 '^psmisc$') ]] && aptPKG+=(psmisc)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^idn2$') ]] && aptPKG+=(idn2)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^dns-root-data$') ]] && aptPKG+=(dns-root-data)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^netcat-openbsd$') ]] && aptPKG+=(netcat-openbsd)
[[ -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 '^socat$') ]] && aptPKG+=(socat)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^screen$') ]] && aptPKG+=(screen)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^ethtool$') ]] && aptPKG+=(ethtool)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^qrencode$') ]] && aptPKG+=(qrencode)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^sqlite3$') ]] && aptPKG+=(sqlite3)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^unbound$') ]] && aptPKG+=(unbound)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^libjemalloc2') ]] && aptPKG+=(libjemalloc2)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^google-perftools') ]] && aptPKG+=(google-perftools)
[[ -z $(dpkg -l | awk '{print$2}' | grep '^irqbalance$') ]] && [[ $(nproc --all) -gt 1 ]] && aptPKG+=(irqbalance)
[[ -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
}
repoDL(){
echo -e "${WHITE}[...]\c" && echo -e "\t${WHITE}Repository${cRES}\r\c"
sha256sum_de_GWD=$(curl -sSLo- https://raw.githubusercontent.com/jacyl4/de_GWD/$branch/de_GWD_"$architecture".zip.sha256sum)
sha256sum_don_server=$(curl -sSLo- https://raw.githubusercontent.com/jacyl4/de_GWD/$branch/resource/doh/doh_s_"$architecture".sha256sum)
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_sample=$(curl -sSLo- https://raw.githubusercontent.com/jacyl4/de_GWD/$branch/resource/server/sample.zip.sha256sum)
if [[ $(checkSum /opt/de_GWD/doh-server $sha256sum_don_server) = "false" ]]; then
rm -rf /tmp/doh-server
wget --show-progress -cqO /tmp/doh-server https://raw.githubusercontent.com/jacyl4/de_GWD/$branch/resource/doh/doh_s_$architecture
[[ $(checkSum /tmp/doh-server $sha256sum_don_server) = "false" ]] && echo -e "${RED}Download Failed${cRES}" && exit
[[ $(checkSum /tmp/doh-server $sha256sum_don_server) = "true" ]] && mv -f /tmp/doh-server /opt/de_GWD/doh-server && chmod +x /opt/de_GWD/doh-server
fi
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 "${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/de_GWD.zip $sha256sum_de_GWD) = "false" ]]; then
rm -rf /tmp/de_GWD.zip
wget --show-progress -cqO /tmp/de_GWD.zip https://raw.githubusercontent.com/jacyl4/de_GWD/$branch/de_GWD_"$architecture".zip
[[ $(checkSum /tmp/de_GWD.zip $sha256sum_de_GWD) = "false" ]] && echo -e "${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
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 [[ $(checkSum /opt/de_GWD/.repo/sample.zip $sha256sum_sample) = "false" ]]; then
rm -rf /tmp/sample.zip
wget --show-progress -cqO /tmp/sample.zip https://raw.githubusercontent.com/jacyl4/de_GWD/$branch/resource/server/sample.zip
[[ $(checkSum /tmp/sample.zip $sha256sum_sample) = "false" ]] && echo -e "${RED}Download Failed${cRES}" && exit
[[ $(checkSum /tmp/sample.zip $sha256sum_sample) = "true" ]] && mv -f /tmp/sample.zip /opt/de_GWD/.repo/sample.zip
fi
localVer=$(awk 'NR==1' /opt/de_GWD/version.php 2>/dev/null)
remoteVer=$(curl -sSLo- https://raw.githubusercontent.com/jacyl4/de_GWD/main/version.php | head -n 1)
if [[ $localVer != $remoteVer ]]; then
rm -rf /tmp/version.php
wget --show-progress -cqO /tmp/version.php https://raw.githubusercontent.com/jacyl4/de_GWD/main/version.php
[[ $? -ne 0 ]] && echo -e "${WHITE}Version File${RED} Download Failed${cRES}" && exit
[[ $(du -sk /tmp/version.php 2>/dev/null | awk '{print$1}') -ge 4 ]] && mv -f /tmp/version.php /opt/de_GWD/version.php
fi
echo -e "${WHITE}[ ${GREEN}✓ ${WHITE}]\c" && echo -e "\t${WHITE}Repository${cRES}"
}
preUpdate(){
[[ -f "/etc/nginx/conf.d/HSTS" ]] && rm -rf /etc/nginx/conf.d/HSTS
[[ -f "/etc/nginx/conf.d/ssl_certificate" ]] && rm -rf /etc/nginx/conf.d/ssl_certificate
if [[ -d "/opt/AdGuardHome" ]]; then
systemctl stop AdGuardHome >/dev/null 2>&1
rm -rf /etc/systemd/system/AdGuardHome.service
rm -rf /lib/systemd/system/AdGuardHome.service
rm -rf /opt/AdGuardHome
rm -rf /usr/bin/yq
fi
if [[ -f "/opt/de_GWD/iptablesrules-up" ]]; then
systemctl disable iptablesrules >/dev/null 2>&1
systemctl stop iptablesrules >/dev/null 2>&1
rm -rf /etc/systemd/system/iptablesrules.service >/dev/null 2>&1
rm -rf /lib/systemd/system/iptablesrules.service >/dev/null 2>&1
systemctl daemon-reload >/dev/null
rm -rf /opt/de_GWD/iptablesrules-down
rm -rf /opt/de_GWD/iptablesrules-up
rm -rf /opt/de_GWD/Q4amSun
fi
if [[ -n $(systemctl list-units | grep 'pihole') ]]; then
systemctl stop pihole-FTL
rm -rf /etc/.pihole /etc/pihole /opt/pihole /usr/bin/pihole-FTL /usr/local/bin/pihole /var/www/html/admin /var/log/pihole* /etc/dnsmasq.d/*
rm -rf /etc/systemd/system/pihole-FTL.service
systemctl daemon-reload
fi
[[ ! -f "/var/www/ssl/de_GWD.cer" ]] && mv -f /var/www/ssl/*.cer /var/www/ssl/de_GWD.cer && sed -i '/ssl_certificate /c\ssl_certificate \/var\/www\/ssl\/de_GWD.cer;' /etc/nginx/conf.d/default.conf
[[ ! -f "/var/www/ssl/de_GWD.key" ]] && mv -f /var/www/ssl/*.key /var/www/ssl/de_GWD.key && sed -i '/ssl_certificate_key /c\ssl_certificate_key \/var\/www\/ssl\/de_GWD.key;' /etc/nginx/conf.d/default.conf
[[ -f "/etc/nginx/conf.d/merge.sh" ]] && rm -rf /etc/nginx/conf.d/*
rm -rf /var/log/auth.log
rm -rf /usr/local/bin/autoUpdate
rm -rf /usr/local/bin/iptablesrules*
rm -rf /usr/local/bin/Q2H
rm -rf /usr/local/bin/version.php
rm -rf /usr/local/bin/vtrui
rm -rf /usr/bin/yq
rm -rf /etc/dns-over-https
rm -rf /etc/nginx/conf.d/0_serverUpstream
rm -rf /etc/nginx/conf.d/4_v2Proxy
rm -rf /opt/de_GWD/.repo/vtrui.zip
rm -rf /opt/de_GWD/.repo/IPchnroute
rm -rf /opt/de_GWD/clearKernel
rm -rf /dev/shm/de_GWD.socket*
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
service cron stop
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)
localAddrCIDR=$(ip -4 a | grep "$ethernetnum" | grep -Po '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/\d{1,2}\b' | head -n 1)
localAddr=$(echo $localAddrCIDR | cut -d/ -f1)
domain=$(awk '/server_name/ {print$2;exit}' /etc/nginx/conf.d/default.conf | sed 's/.$//')
topDomain=$(echo $domain | rev | awk -F. '{print $1"."$2}' | rev)
port=$(awk '/ssl .* reuseport/ {print$2}' /etc/nginx/conf.d/default.conf | grep '^[[:digit:]]*$' | head -n1)
[[ -z $port ]] && port="443"
path=$(jq -r '.inbounds[0].streamSettings.wsSettings.path' /opt/de_GWD/vtrui/config.json 2>/dev/null | grep -v '^null$')
uuids=$(jq -r '.inbounds[0].settings.clients[].id' /opt/de_GWD/vtrui/config.json 2>/dev/null | grep -v '^null$')
}
preInstall(){
sync; echo 3 >/proc/sys/vm/drop_caches >/dev/null 2>&1
rm -rf /etc/resolv.conf
cat << EOF >/etc/resolv.conf
nameserver 1.1.1.1
nameserver 8.8.8.8
EOF
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
mkdir -p /opt/de_GWD
mkdir -p /opt/de_GWD/.repo
cat << "EOF" >/opt/de_GWD/tcpTime
date -s "$(wget -qSO- --max-redirect=0 whatismyip.akamai.com 2>&1 | grep Date: | cut -d' ' -f5-8)Z"
[[ $? -ne "0" ]]&& date -s "$(curl -sI cloudflare.com| grep -i '^date:'|cut -d' ' -f2-)"
hwclock -w
EOF
chmod +x /opt/de_GWD/tcpTime
[[ $virt_type != "container" ]] && /opt/de_GWD/tcpTime
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 >>'/etc/systemd/system.conf' <<EOF
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
cat << EOF >/etc/apt/sources.list
deb http://cloudfront.debian.net/debian bookworm main contrib non-free non-free-firmware
deb http://cloudfront.debian.net/debian-security bookworm-security main contrib non-free non-free-firmware
deb http://cloudfront.debian.net/debian bookworm-updates main contrib non-free non-free-firmware
deb http://cloudfront.debian.net/debian bookworm-backports main contrib non-free non-free-firmware
EOF
apt update --fix-missing && apt upgrade --allow-downgrades -y
apt full-upgrade -y && apt autoremove --purge -y && apt clean -y && apt autoclean -y
pkgDEP
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.cloudflare.com iburst
server time1.google.com iburst
server time1.apple.com iburst
server ntp-3.arkena.net 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/resolv.conf
cat << EOF >/etc/resolv.conf
nameserver 127.0.0.1
EOF
mkdir -p /etc/unbound
cat << EOF >/etc/unbound/unbound.conf
server:
verbosity: 0
interface: 127.0.0.1
port: 53
do-ip4: yes
do-udp: yes
do-tcp: yes
do-ip6: no
prefer-ip6: no
edns-buffer-size: 1232
prefetch: yes
so-reuseport: yes
so-rcvbuf: 4m
so-sndbuf: 4m
num-threads: 2
msg-cache-slabs: 4
rrset-cache-slabs: 4
infra-cache-slabs: 4
key-cache-slabs: 4
forward-zone:
name: "."
forward-addr: 1.1.1.1
forward-addr: 1.0.0.1
forward-addr: 8.8.8.8
forward-addr: 8.8.4.4
forward-addr: 9.9.9.9
forward-addr: 208.67.222.222
forward-first: no
EOF
rm -rf /lib/systemd/system/unbound.service
cat << "EOF" >/etc/systemd/system/unbound.service
[Unit]
Description=Unbound DNS server
After=network.target
[Service]
Type=simple
Restart=on-failure
ReadOnlyPaths=/etc/unbound
ExecStart=/usr/sbin/unbound -d
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload >/dev/null
systemctl restart unbound >/dev/null 2>&1
systemctl enable unbound >/dev/null 2>&1
rm -rf /etc/resolvconf/update.d/unbound >/dev/null 2>&1
rm -rf /etc/systemd/resolved.conf >/dev/null 2>&1
systemctl mask --now systemd-resolved >/dev/null 2>&1
rm -rf /etc/resolvconf/resolv.conf.d/*
>/etc/resolvconf/resolv.conf.d/original
>/etc/resolvconf/resolv.conf.d/base
>/etc/resolvconf/resolv.conf.d/tail
rm -rf /etc/resolv.conf
rm -rf /run/resolvconf/interface
cat << EOF >/etc/resolvconf/resolv.conf.d/head
nameserver 127.0.0.1
EOF
if [[ -f "/etc/resolvconf/run/resolv.conf" ]]; then
ln -sf /etc/resolvconf/run/resolv.conf /etc/resolv.conf
elif [[ -f "/run/resolvconf/resolv.conf" ]]; then
ln -sf /run/resolvconf/resolv.conf /etc/resolv.conf
fi
sed -i '/dns-nameservers /d' /etc/network/interfaces
resolvconf -u
[[ -n $(which setenforce) ]] && setenforce 0
[[ -f "/etc/selinux/config" ]] && sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
[[ -f "/etc/ld.so.preload" ]] && sed -i "/libjemalloc/d" /etc/ld.so.preload
ldconfig
DPKGclean=$(dpkg --list | grep "^rc" | cut -d " " -f 3)
[[ -n $DPKGclean ]] && echo $DPKGclean | xargs sudo dpkg --purge
rm -rf /var/log/journal/*
systemctl restart systemd-journald >/dev/null 2>&1
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
if [[ $virt_type != "container" ]]; then
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_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_retrans_collapse = 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
fi
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 " | grep -v 'broadcast ' | 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 rtt 100ms besteffort dual-srchost nonat nowash split-gso ack-filter-aggressive 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 rtt 30ms diffserv4 dual-dsthost nonat wash 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
}
installNftables(){
rm -rf /etc/nftables*
rm -rf /opt/de_GWD/nftables
mkdir -p /opt/de_GWD/nftables
cat << "EOF" >/opt/de_GWD/nftables/flowtable_eth.sh
#!/bin/bash
interface_FT=$(find /sys/class/net ! -type d | xargs --max-args=1 realpath | grep 'device' | awk -F'/' '{print$NF}' | xargs -n1 | grep -v '^lo$' | grep -v '^ifb4lo$')
interface_BF=()
while IFS= read -r line; do
interface_BF+=("$line")
done <<< "$interface_FT"
echo "define flowtable_eth = { $(IFS=, ; echo "${interface_BF[*]}") };" >/opt/de_GWD/nftables/flowtable.eth
EOF
chmod +x /opt/de_GWD/nftables/flowtable_eth.sh
cat << "EOF" >/opt/de_GWD/nftables/default.nft
#!/usr/sbin/nft -f
include "/opt/de_GWD/nftables/flowtable.eth"
table inet bypassflow {
flowtable Acceleration {
hook ingress priority -300; devices = $flowtable_eth;
}
chain bypasschain {
type filter hook forward priority -300; policy accept;
ip daddr 172.16.0.0/24 flow offload @Acceleration
ip saddr 172.16.0.0/24 flow offload @Acceleration
ip daddr 172.17.0.0/16 flow offload @Acceleration
ip saddr 172.17.0.0/16 flow offload @Acceleration
}
}
table inet filter {
chain INPUT {
type filter hook input priority 0; policy accept;
iifname lo accept
iifname "wgcf" accept
iifname "docker0" accept
iifname "ifb4lo" accept
iifname "ifb4wgcf" accept
ct state established,related accept
tcp flags != syn ct state new drop
tcp flags & (fin|syn) == (fin|syn) drop
tcp flags & (syn|rst) == (syn|rst) drop
tcp flags & (fin|syn|rst|psh|ack|urg) == 0 drop
tcp flags & (fin|psh|urg) == (fin|psh|urg) drop
ct state invalid counter drop
# Drop 53 in
meta l4proto { tcp, udp } th dport 53 drop
meta l4proto { tcp, udp } th dport 4711 drop
}
chain FORWARD {
type filter hook forward priority 0; policy accept;
# WireGuard traffic
iifname "ifb4wgcf" accept
iifname "wgcf" accept
oifname "wgcf" accept
# Docker traffic
counter jump DOCKER-USER
counter jump DOCKER-ISOLATION-STAGE-1
oifname "docker0" ct state related,established counter accept
oifname "docker0" counter jump DOCKER
iifname "docker0" oifname != "docker0" counter accept
iifname "docker0" oifname "docker0" counter accept
}
chain OUTPUT {
type filter hook output priority 0; policy accept;
}
chain DOCKER {
}
chain DOCKER-USER {
counter accept
}
chain DOCKER-ISOLATION-STAGE-1 {
iifname "docker0" oifname != "docker0" counter jump DOCKER-ISOLATION-STAGE-2
counter return
}
chain DOCKER-ISOLATION-STAGE-2 {
oifname "docker0" counter drop
counter return
}
}
table inet router {
chain DOCKER {
iifname "docker0" counter accept
}
chain INPUT {
type nat hook input priority -100; policy accept;
}
chain OUTPUT {
type nat hook output priority -100; policy accept;
ip daddr != 127.0.0.0/8 fib daddr type local counter jump DOCKER
}
chain PREROUTING {
type nat hook prerouting priority dstnat; policy accept;
tcp flags & (syn|rst) == syn counter tcp option maxseg size set 1460
# Docker
fib daddr type local counter jump DOCKER
}
chain POSTROUTING {
type nat hook postrouting priority srcnat; policy accept;
# Docker
oifname != "docker0" ip saddr 172.17.0.0/16 counter masquerade
}
}
EOF
chmod +x /opt/de_GWD/nftables/default.nft
rm -rf /lib/systemd/system/nftables.service
cat << EOF >/etc/systemd/system/nftables.service
[Unit]
Description=nftables
Wants=network-pre.target
Before=network-pre.target shutdown.target
Conflicts=shutdown.target
DefaultDependencies=no
[Service]
Type=oneshot
RemainAfterExit=yes
StandardInput=null
ProtectSystem=full
ProtectHome=true
ExecStart=/bin/bash -c '/etc/rc_online.local' ; /bin/bash -c '/opt/de_GWD/nftables/flowtable_eth.sh' ; /usr/sbin/nft -f /opt/de_GWD/nftables/default.nft
ExecStop=/usr/sbin/nft flush ruleset
[Install]
WantedBy=sysinit.target
EOF
systemctl daemon-reload >/dev/null
systemctl enable nftables >/dev/null 2>&1
systemctl restart nftables
}
installDOH(){
echo -e "${WHITE}[...]\c" && echo -e "\t${WHITE}Install DoH server${cRES}\r\c"
cat << EOF >/opt/de_GWD/doh-server.conf
listen = [ "127.0.0.1:8053" ]
path = "/dq"
upstream = [
"udp:127.0.0.1:53",
"tcp:127.0.0.1:53"
]
timeout = 10
tries = 3
verbose = false
log_guessed_client_ip = false
ecs_allow_non_global_ip = false
ecs_use_precise_ip = false
EOF
mkdir -p /etc/NetworkManager/dispatcher.d
cat << "EOF" > /etc/NetworkManager/dispatcher.d/doh-server
#!/bin/bash
case "$2" in
up)
/usr/bin/systemctl is-active doh-server.service >/dev/null && /usr/bin/systemctl restart doh-server.service
;;
down)
/usr/bin/systemctl is-active doh-server.service >/dev/null && /usr/bin/systemctl restart doh-server.service
;;
*)
exit 0
;;
esac
EOF
chmod +x /etc/NetworkManager/dispatcher.d/doh-server
rm -rf /lib/systemd/system/doh-server.service
cat << "EOF" >/etc/systemd/system/doh-server.service
[Unit]
Description=DNS-over-HTTPS server
After=network.target
[Service]
User=root
Type=simple
ExecStart=/opt/de_GWD/doh-server -conf /opt/de_GWD/doh-server.conf
Restart=always
RestartSec=2
TimeoutStopSec=5
Nice=-8
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload >/dev/null
systemctl enable doh-server >/dev/null 2>&1
echo -e "${WHITE}[ ${GREEN}✓ ${WHITE}]\c" && echo -e "\t${WHITE}Install DoH server${cRES}"
}
installXray(){
echo -e "${WHITE}[...]\c" && echo -e "\t${WHITE}Install Xray${cRES}\r\c"
rm -rf /opt/de_GWD/vtrui
mkdir -p /opt/de_GWD/vtrui
if [[ -n $(unzip -tq /opt/de_GWD/.repo/de_GWD.zip | grep "No errors detected in compressed data") ]]; then
rm -rf /tmp/de_GWD
unzip /opt/de_GWD/.repo/de_GWD.zip -d /tmp/de_GWD >/dev/null 2>&1
mv -f /tmp/de_GWD/xray /opt/de_GWD/vtrui/vtrui
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
rm -rf /lib/systemd/system/vtrui.service
cat << EOF >/etc/systemd/system/vtrui.service
[Unit]
Description=vtrui
After=network.target nss-lookup.target
[Service]
User=www-data
ExecStart=/opt/de_GWD/vtrui/vtrui run -confdir /opt/de_GWD/vtrui
Restart=on-failure
RestartPreventExitStatus=23
Nice=-8
AmbientCapabilities=CAP_NET_RAW CAP_NET_ADMIN CAP_NET_BIND_SERVICE
CapabilityBoundingSet=CAP_NET_RAW CAP_NET_ADMIN CAP_NET_BIND_SERVICE
NoNewPrivileges=true
LimitNOFILE=10000000
LimitNPROC=10000000
LimitCORE=10000000