-
Notifications
You must be signed in to change notification settings - Fork 1
/
warp.sh
2364 lines (2066 loc) · 102 KB
/
warp.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
# 环境变量,用于在 Debian 或 Ubuntu 操作系统中设置非交互式(noninteractive)安装模式
export DEBIAN_FRONTEND=noninteractive
# 彩色文字
RED="\033[31m"
GREEN="\033[32m"
YELLOW="\033[33m"
PLAIN='\033[0m'
red() {
echo -e "\033[31m\033[01m$1\033[0m"
}
green() {
echo -e "\033[32m\033[01m$1\033[0m"
}
yellow() {
echo -e "\033[33m\033[01m$1\033[0m"
}
# 多方式判断操作系统,如非支持的操作系统,则退出脚本
REGEX=("debian" "ubuntu" "centos|red hat|kernel|oracle linux|alma|rocky" "'amazon linux'" "fedora" "alpine")
RELEASE=("Debian" "Ubuntu" "CentOS" "CentOS" "Fedora" "Alpine")
PACKAGE_UPDATE=("apt-get update" "apt-get update" "yum -y update" "yum -y update" "yum -y update" "apk update -f")
PACKAGE_INSTALL=("apt -y install" "apt -y install" "yum -y install" "yum -y install" "yum -y install" "apk add -f")
PACKAGE_UNINSTALL=("apt -y autoremove" "apt -y autoremove" "yum -y autoremove" "yum -y autoremove" "yum -y autoremove" "apk del -f")
[[ $EUID -ne 0 ]] && red "注意:请在root用户下运行脚本" && exit 1
CMD=("$(grep -i pretty_name /etc/os-release 2>/dev/null | cut -d \" -f2)" "$(hostnamectl 2>/dev/null | grep -i system | cut -d : -f2)" "$(lsb_release -sd 2>/dev/null)" "$(grep -i description /etc/lsb-release 2>/dev/null | cut -d \" -f2)" "$(grep . /etc/redhat-release 2>/dev/null)" "$(grep . /etc/issue 2>/dev/null | cut -d \\ -f1 | sed '/^[ ]*$/d')")
for i in "${CMD[@]}"; do
SYS="$i" && [[ -n $SYS ]] && break
done
for ((int = 0; int < ${#REGEX[@]}; int++)); do
if [[ $(echo "$SYS" | tr '[:upper:]' '[:lower:]') =~ ${REGEX[int]} ]]; then
SYSTEM="${RELEASE[int]}" && [[ -n $SYSTEM ]] && break
fi
done
[[ -z $SYSTEM ]] && red "不支持当前VPS系统, 请使用主流的操作系统" && exit 1
# 某些系统未自带 curl,检测并安装
if [[ -z $(type -P curl) ]]; then
if [[ ! $SYSTEM == "CentOS" ]]; then
${PACKAGE_UPDATE[int]}
fi
${PACKAGE_INSTALL[int]} curl
fi
# 检查系统内核版本
main=$(uname -r | awk -F . '{print $1}')
minor=$(uname -r | awk -F . '{print $2}')
# 获取系统版本号
OSID=$(grep -i version_id /etc/os-release | cut -d \" -f2 | cut -d . -f1)
# 检查VPS虚拟化
VIRT=$(systemd-detect-virt)
# 删除 WGCF 默认配置文件中的监听 IP
wg1="sed -i '/0\.0\.0\.0\/0/d' /etc/wireguard/wgcf.conf" # IPv4
wg2="sed -i '/\:\:\/0/d' /etc/wireguard/wgcf.conf" # IPv6
# 设置 WGCF 配置文件的 DNS 服务器
wg3="sed -i 's/1.1.1.1/1.1.1.1,1.0.0.1,8.8.8.8,8.8.4.4,2606:4700:4700::1111,2606:4700:4700::1001,2001:4860:4860::8888,2001:4860:4860::8844/g' /etc/wireguard/wgcf.conf"
wg4="sed -i 's/1.1.1.1/2606:4700:4700::1111,2606:4700:4700::1001,2001:4860:4860::8888,2001:4860:4860::8844,1.1.1.1,1.0.0.1,8.8.8.8,8.8.4.4/g' /etc/wireguard/wgcf.conf"
# 设置允许外部 IP 访问
wg5='sed -i "7 s/^/PostUp = ip -4 rule add from $(ip route get 1.1.1.1 | grep -oP '"'src \K\S+') lookup main\n/"'" /etc/wireguard/wgcf.conf && sed -i "7 s/^/PostDown = ip -4 rule delete from $(ip route get 1.1.1.1 | grep -oP '"'src \K\S+') lookup main\n/"'" /etc/wireguard/wgcf.conf' # IPv4
wg6='sed -i "7 s/^/PostUp = ip -6 rule add from $(ip route get 2606:4700:4700::1111 | grep -oP '"'src \K\S+') lookup main\n/"'" /etc/wireguard/wgcf.conf && sed -i "7 s/^/PostDown = ip -6 rule delete from $(ip route get 2606:4700:4700::1111 | grep -oP '"'src \K\S+') lookup main\n/"'" /etc/wireguard/wgcf.conf' # IPv6
wg7='sed -i "7 s/^/PostUp = ip -4 rule add from $(ip route get 1.1.1.1 | grep -oP '"'src \K\S+') lookup main\n/"'" /etc/wireguard/wgcf.conf && sed -i "7 s/^/PostDown = ip -4 rule delete from $(ip route get 1.1.1.1 | grep -oP '"'src \K\S+') lookup main\n/"'" /etc/wireguard/wgcf.conf && sed -i "7 s/^/PostUp = ip -6 rule add from $(ip route get 2606:4700:4700::1111 | grep -oP '"'src \K\S+') lookup main\n/"'" /etc/wireguard/wgcf.conf && sed -i "7 s/^/PostDown = ip -6 rule delete from $(ip route get 2606:4700:4700::1111 | grep -oP '"'src \K\S+') lookup main\n/"'" /etc/wireguard/wgcf.conf' # 双栈
# 设置 WARP-GO 配置文件的监听 IP
wgo1='sed -i "s#.*AllowedIPs.*#AllowedIPs = 0.0.0.0/0#g" /opt/warp-go/warp.conf' # IPv4
wgo2='sed -i "s#.*AllowedIPs.*#AllowedIPs = ::/0#g" /opt/warp-go/warp.conf' # IPv6
wgo3='sed -i "s#.*AllowedIPs.*#AllowedIPs = 0.0.0.0/0,::/0#g" /opt/warp-go/warp.conf' # 双栈
# 设置允许外部 IP 访问
wgo4='sed -i "/\[Script\]/a PostUp = ip -4 rule add from $(ip route get 1.1.1.1 | grep -oP "src \K\S+") lookup main\n" /opt/warp-go/warp.conf && sed -i "/\[Script\]/a PostDown = ip -4 rule delete from $(ip route get 1.1.1.1 | grep -oP "src \K\S+") lookup main\n" /opt/warp-go/warp.conf' # IPv4
wgo5='sed -i "/\[Script\]/a PostUp = ip -6 rule add from $(ip route get 2606:4700:4700::1111 | grep -oP "src \K\S+") lookup main\n" /opt/warp-go/warp.conf && sed -i "/\[Script\]/a PostDown = ip -6 rule delete from $(ip route get 2606:4700:4700::1111 | grep -oP "src \K\S+") lookup main\n" /opt/warp-go/warp.conf' # IPv6
wgo6='sed -i "/\[Script\]/a PostUp = ip -4 rule add from $(ip route get 1.1.1.1 | grep -oP "src \K\S+") lookup main\n" /opt/warp-go/warp.conf && sed -i "/\[Script\]/a PostDown = ip -4 rule delete from $(ip route get 1.1.1.1 | grep -oP "src \K\S+") lookup main\n" /opt/warp-go/warp.conf && sed -i "/\[Script\]/a PostUp = ip -6 rule add from $(ip route get 2606:4700:4700::1111 | grep -oP "src \K\S+") lookup main\n" /opt/warp-go/warp.conf && sed -i "/\[Script\]/a PostDown = ip -6 rule delete from $(ip route get 2606:4700:4700::1111 | grep -oP "src \K\S+") lookup main\n" /opt/warp-go/warp.conf' # 双栈
# 检测 VPS 处理器架构
archAffix() {
case "$(uname -m)" in
i386 | i686) echo '386' ;;
x86_64 | amd64) echo 'amd64' ;;
armv8 | arm64 | aarch64) echo 'arm64' ;;
s390x) echo 's390x' ;;
*) red "不支持的CPU架构!" && exit 1 ;;
esac
}
# 检测 VPS 的出站 IP
check_ip() {
ipv4=$(curl -s4m8 ip.p3terx.com -k | sed -n 1p)
ipv6=$(curl -s6m8 ip.p3terx.com -k | sed -n 1p)
}
# 检测 VPS 的 IP 形式
check_stack() {
lan4=$(ip route get 1.1.1.1 2>/dev/null | grep -oP 'src \K\S+')
lan6=$(ip route get 2606:4700:4700::1111 2>/dev/null | grep -oP 'src \K\S+')
if [[ "$lan4" =~ ^([0-9]{1,3}\.){3} ]]; then
ping -c2 -W3 1.1.1.1 >/dev/null 2>&1 && out4=1
fi
if [[ "$lan6" != "::1" && "$lan6" =~ ^([a-f0-9]{1,4}:){2,4}[a-f0-9]{1,4} ]]; then
ping6 -c2 -w10 2606:4700:4700::1111 >/dev/null 2>&1 && out6=1
fi
}
# 检测 VPS 的 WARP 状态
check_warp() {
warp_v4=$(curl -s4m8 https://www.cloudflare.com/cdn-cgi/trace -k | grep warp | cut -d= -f2)
warp_v6=$(curl -s6m8 https://www.cloudflare.com/cdn-cgi/trace -k | grep warp | cut -d= -f2)
}
# 检测 WARP+ 账户流量情况
check_quota() {
if [[ "$CHECK_TYPE" = 1 ]]; then
# 如为WARP-Cli,使用其自带接口获取流量
QUOTA=$(warp-cli --accept-tos account 2>/dev/null | grep -oP 'Quota: \K\d+')
else
# 判断为 WGCF 或 WARP-GO,从客户端相应的配置文件中提取
if [[ -e "/opt/warp-go/warp-go" ]]; then
ACCESS_TOKEN=$(grep 'Token' /opt/warp-go/warp.conf | cut -d= -f2 | sed 's# ##g')
DEVICE_ID=$(grep 'Device' /opt/warp-go/warp.conf | cut -d= -f2 | sed 's# ##g')
fi
if [[ -n $(type -P wg-quick) && -n $(type -P wgcf) ]]; then
ACCESS_TOKEN=$(grep 'access_token' /etc/wireguard/wgcf-account.toml | cut -d \' -f2)
DEVICE_ID=$(grep 'device_id' /etc/wireguard/wgcf-account.toml | cut -d \' -f2)
fi
# 使用API,获取流量信息
API=$(curl -s "https://api.cloudflareclient.com/v0a884/reg/$DEVICE_ID" -H "User-Agent: okhttp/3.12.1" -H "Authorization: Bearer $ACCESS_TOKEN")
QUOTA=$(grep -oP '"quota":\K\d+' <<<$API)
fi
# 流量单位换算
[[ $QUOTA -gt 10000000000000 ]] && QUOTA="$(echo "scale=2; $QUOTA/1000000000000" | bc) TB" || QUOTA="$(echo "scale=2; $QUOTA/1000000000" | bc) GB"
}
# 检查 TUN 模块是否开启
check_tun() {
TUN=$(cat /dev/net/tun 2>&1 | tr '[:upper:]' '[:lower:]')
if [[ ! $TUN =~ "in bad state"|"处于错误状态"|"ist in schlechter Verfassung" ]]; then
if [[ $VIRT == lxc ]]; then
if [[ $main -lt 5 ]] || [[ $minor -lt 6 ]]; then
red "检测到目前VPS未开启TUN模块, 请到后台控制面板处开启"
exit 1
else
return 0
fi
elif [[ $VIRT == "openvz" ]]; then
wget -N --no-check-certificate https://gitlab.com/Misaka-blog/warp-script/-/raw/main/files/tun.sh && bash tun.sh
else
red "检测到目前VPS未开启TUN模块, 请到后台控制面板处开启"
exit 1
fi
fi
}
# 修改 IPv4 / IPv6 优先级设置
stack_priority() {
[[ -e /etc/gai.conf ]] && sed -i '/^precedence \:\:ffff\:0\:0/d;/^label 2002\:\:\/16/d' /etc/gai.conf
yellow "选择 IPv4 / IPv6 优先级"
echo ""
echo -e " ${GREEN}1.${PLAIN} IPv4 优先"
echo -e " ${GREEN}2.${PLAIN} IPv6 优先"
echo -e " ${GREEN}3.${PLAIN} 默认优先级 ${YELLOW}(默认)${PLAIN}"
echo ""
read -rp "请选择选项 [1-3]:" priority
case $priority in
1) echo "precedence ::ffff:0:0/96 100" >>/etc/gai.conf ;;
2) echo "label 2002::/16 2" >>/etc/gai.conf ;;
*) yellow "将使用 VPS 默认的 IP 优先级" ;;
esac
}
# 检查适合 VPS 的最佳 MTU 值
check_mtu() {
yellow "正在检测并设置 MTU 最佳值, 请稍等..."
check_ip
MTUy=1500
MTUc=10
if [[ -n ${ipv6} && -z ${ipv4} ]]; then
ping='ping6'
IP1='2606:4700:4700::1001'
IP2='2001:4860:4860::8888'
else
ping='ping'
IP1='1.1.1.1'
IP2='8.8.8.8'
fi
while true; do
if ${ping} -c1 -W1 -s$((${MTUy} - 28)) -Mdo ${IP1} >/dev/null 2>&1 || ${ping} -c1 -W1 -s$((${MTUy} - 28)) -Mdo ${IP2} >/dev/null 2>&1; then
MTUc=1
MTUy=$((${MTUy} + ${MTUc}))
else
MTUy=$((${MTUy} - ${MTUc}))
if [[ ${MTUc} = 1 ]]; then
break
fi
fi
if [[ ${MTUy} -le 1360 ]]; then
MTUy='1360'
break
fi
done
# 将 MTU 最佳值放置至 MTU 变量中备用
MTU=$((${MTUy} - 80))
green "MTU 最佳值 = $MTU 已设置完毕!"
}
# 检查适合 VPS 的最佳 Endpoint IP 地址
check_endpoint() {
yellow "正在检测并设置最佳 Endpoint IP,请稍等,大约需要 1-2 分钟..."
# 下载优选工具软件,感谢某匿名网友的分享的优选工具
wget https://gitlab.com/Misaka-blog/warp-script/-/raw/main/files/warp-yxip/warp-linux-$(archAffix) -O warp >/dev/null 2>&1
# 根据 VPS 的出站 IP 情况,生成对应的优选 Endpoint IP 段列表
check_ip
# 生成优选 Endpoint IP 文件
if [[ -n $ipv4 ]]; then
n=0
iplist=100
while true; do
temp[$n]=$(echo 162.159.192.$(($RANDOM % 256)))
n=$(($n + 1))
if [ $n -ge $iplist ]; then
break
fi
temp[$n]=$(echo 162.159.193.$(($RANDOM % 256)))
n=$(($n + 1))
if [ $n -ge $iplist ]; then
break
fi
temp[$n]=$(echo 162.159.195.$(($RANDOM % 256)))
n=$(($n + 1))
if [ $n -ge $iplist ]; then
break
fi
temp[$n]=$(echo 162.159.204.$(($RANDOM % 256)))
n=$(($n + 1))
if [ $n -ge $iplist ]; then
break
fi
temp[$n]=$(echo 188.114.96.$(($RANDOM % 256)))
n=$(($n + 1))
if [ $n -ge $iplist ]; then
break
fi
temp[$n]=$(echo 188.114.97.$(($RANDOM % 256)))
n=$(($n + 1))
if [ $n -ge $iplist ]; then
break
fi
temp[$n]=$(echo 188.114.98.$(($RANDOM % 256)))
n=$(($n + 1))
if [ $n -ge $iplist ]; then
break
fi
temp[$n]=$(echo 188.114.99.$(($RANDOM % 256)))
n=$(($n + 1))
if [ $n -ge $iplist ]; then
break
fi
done
while true; do
if [ $(echo ${temp[@]} | sed -e 's/ /\n/g' | sort -u | wc -l) -ge $iplist ]; then
break
else
temp[$n]=$(echo 162.159.192.$(($RANDOM % 256)))
n=$(($n + 1))
fi
if [ $(echo ${temp[@]} | sed -e 's/ /\n/g' | sort -u | wc -l) -ge $iplist ]; then
break
else
temp[$n]=$(echo 162.159.193.$(($RANDOM % 256)))
n=$(($n + 1))
fi
if [ $(echo ${temp[@]} | sed -e 's/ /\n/g' | sort -u | wc -l) -ge $iplist ]; then
break
else
temp[$n]=$(echo 162.159.195.$(($RANDOM % 256)))
n=$(($n + 1))
fi
if [ $(echo ${temp[@]} | sed -e 's/ /\n/g' | sort -u | wc -l) -ge $iplist ]; then
break
else
temp[$n]=$(echo 162.159.204.$(($RANDOM % 256)))
n=$(($n + 1))
fi
if [ $(echo ${temp[@]} | sed -e 's/ /\n/g' | sort -u | wc -l) -ge $iplist ]; then
break
else
temp[$n]=$(echo 188.114.96.$(($RANDOM % 256)))
n=$(($n + 1))
fi
if [ $(echo ${temp[@]} | sed -e 's/ /\n/g' | sort -u | wc -l) -ge $iplist ]; then
break
else
temp[$n]=$(echo 188.114.97.$(($RANDOM % 256)))
n=$(($n + 1))
fi
if [ $(echo ${temp[@]} | sed -e 's/ /\n/g' | sort -u | wc -l) -ge $iplist ]; then
break
else
temp[$n]=$(echo 188.114.98.$(($RANDOM % 256)))
n=$(($n + 1))
fi
if [ $(echo ${temp[@]} | sed -e 's/ /\n/g' | sort -u | wc -l) -ge $iplist ]; then
break
else
temp[$n]=$(echo 188.114.99.$(($RANDOM % 256)))
n=$(($n + 1))
fi
done
else
n=0
iplist=100
while true; do
temp[$n]=$(echo [2606:4700:d0::$(printf '%x\n' $(($RANDOM * 2 + $RANDOM % 2))):$(printf '%x\n' $(($RANDOM * 2 + $RANDOM % 2))):$(printf '%x\n' $(($RANDOM * 2 + $RANDOM % 2))):$(printf '%x\n' $(($RANDOM * 2 + $RANDOM % 2)))])
n=$(($n + 1))
if [ $n -ge $iplist ]; then
break
fi
temp[$n]=$(echo [2606:4700:d1::$(printf '%x\n' $(($RANDOM * 2 + $RANDOM % 2))):$(printf '%x\n' $(($RANDOM * 2 + $RANDOM % 2))):$(printf '%x\n' $(($RANDOM * 2 + $RANDOM % 2))):$(printf '%x\n' $(($RANDOM * 2 + $RANDOM % 2)))])
n=$(($n + 1))
if [ $n -ge $iplist ]; then
break
fi
done
while true; do
if [ $(echo ${temp[@]} | sed -e 's/ /\n/g' | sort -u | wc -l) -ge $iplist ]; then
break
else
temp[$n]=$(echo [2606:4700:d0::$(printf '%x\n' $(($RANDOM * 2 + $RANDOM % 2))):$(printf '%x\n' $(($RANDOM * 2 + $RANDOM % 2))):$(printf '%x\n' $(($RANDOM * 2 + $RANDOM % 2))):$(printf '%x\n' $(($RANDOM * 2 + $RANDOM % 2)))])
n=$(($n + 1))
fi
if [ $(echo ${temp[@]} | sed -e 's/ /\n/g' | sort -u | wc -l) -ge $iplist ]; then
break
else
temp[$n]=$(echo [2606:4700:d1::$(printf '%x\n' $(($RANDOM * 2 + $RANDOM % 2))):$(printf '%x\n' $(($RANDOM * 2 + $RANDOM % 2))):$(printf '%x\n' $(($RANDOM * 2 + $RANDOM % 2))):$(printf '%x\n' $(($RANDOM * 2 + $RANDOM % 2)))])
n=$(($n + 1))
fi
done
fi
# 将生成的 IP 段列表放到 ip.txt 里,待程序优选
echo ${temp[@]} | sed -e 's/ /\n/g' | sort -u >ip.txt
# 取消 Linux 自带的线程限制,以便生成优选 Endpoint IP
ulimit -n 102400
# 启动 WARP Endpoint IP 优选工具
chmod +x warp && ./warp >/dev/null 2>&1
# 将 result.csv 文件的优选 Endpoint IP 提取出来,放置到 best_endpoint 变量中备用
best_endpoint=$(cat result.csv | sed -n 2p | awk -F ',' '{print $1}')
# 查询优选出来的 Endpoint IP 的 loss 是否为 100.00%,如是,则替换为默认的 Endpoint IP
endpoint_loss=$(cat result.csv | sed -n 2p | awk -F ',' '{print $2}')
if [[ $endpoint_loss == "100.00%" ]]; then
# 检查 VPS 的出站 IP 情况
check_ip
# 如未有 IPv4 则使用 IPv6 的 Endpoint IP,如有 IPv4 则使用 IPv4 Endpoint IP
if [[ -z $ipv4 ]]; then
best_endpoint="[2606:4700:4700::1111]:2408"
else
best_endpoint="162.159.193.10:2408"
fi
fi
# 删除 WARP Endpoint IP 优选工具及其附属文件
rm -f warp ip.txt result.csv
green "最佳 Endpoint IP = $best_endpoint 已设置完毕!"
}
# 选择 WGCF 安装 / 切换模式
select_wgcf() {
yellow "请选择 WGCF 安装 / 切换的模式"
echo ""
echo -e " ${GREEN}1.${PLAIN} 安装 / 切换 WGCF-WARP 单栈模式 ${YELLOW}(IPv4)${PLAIN}"
echo -e " ${GREEN}2.${PLAIN} 安装 / 切换 WGCF-WARP 单栈模式 ${YELLOW}(IPv6)${PLAIN}"
echo -e " ${GREEN}3.${PLAIN} 安装 / 切换 WGCF-WARP 双栈模式"
echo ""
read -p "请输入选项 [1-3]: " wgcf_mode
if [ "$wgcf_mode" = "1" ]; then
install_wgcf_ipv4
elif [ "$wgcf_mode" = "2" ]; then
install_wgcf_ipv6
elif [ "$wgcf_mode" = "3" ]; then
install_wgcf_dual
else
red "输入错误,请重新输入"
select_wgcf
fi
}
install_wgcf_ipv4() {
# 检查 WARP 状态
check_warp
# 如启动 WARP,则关闭
if [[ -f "/opt/warp-go/warp-go" ]]; then
systemctl stop warp-go
systemctl disable warp-go
elif [[ -n $(type -P wg-quick) && -n $(type -P wgcf) ]]; then
wg-quick down wgcf 2>/dev/null
systemctl stop wg-quick@wgcf >/dev/null 2>&1
systemctl disable wg-quick@wgcf
fi
# 因为 WGCF 和 WARP-GO 冲突,故检测 WARP-GO 之后打断安装
if [[ -f "/opt/warp-go/warp-go" ]]; then
red "WARP-GO 已安装,请先卸载 WARP-GO"
exit 1
fi
# 检查 VPS 的 IP 形式
check_stack
# 根据检测结果,选择适合的模式安装
if [[ -n $lan4 && -n $out4 && -z $lan6 && -z $out6 ]]; then
# IPv4 Only
wgcf1=$wg2 && wgcf2=$wg3 && wgcf3=$wg5
elif [[ -z $lan4 && -z $out4 && -n $lan6 && -n $out6 ]]; then
# IPv6 Only
wgcf1=$wg2 && wgcf2=$wg4
elif [[ -n $lan4 && -n $out4 && -n $lan6 && -n $out6 ]]; then
# 双栈
wgcf1=$wg2 && wgcf2=$wg3 && wgcf3=$wg5
elif [[ -n $lan4 && -z $out4 && -n $lan6 && -n $out6 ]]; then
# NAT IPv4 + IPv6
wgcf1=$wg2 && wgcf2=$wg4 && wgcf3=$wg5
fi
# 检测是否安装 WGCF,如安装,则切换配置文件。反之执行安装操作
if [[ -n $(type -P wg-quick) && -n $(type -P wgcf) ]]; then
switch_wgcf_conf
else
install_wgcf
fi
}
install_wgcf_ipv6() {
# 检查 WARP 状态
check_warp
# 如启动 WARP,则关闭
if [[ -f "/opt/warp-go/warp-go" ]]; then
systemctl stop warp-go
systemctl disable warp-go
elif [[ -n $(type -P wg-quick) && -n $(type -P wgcf) ]]; then
wg-quick down wgcf 2>/dev/null
systemctl stop wg-quick@wgcf >/dev/null 2>&1
systemctl disable wg-quick@wgcf
fi
# 因为 WGCF 和 WARP-GO 冲突,故检测 WARP-GO 之后打断安装
if [[ -f "/opt/warp-go/warp-go" ]]; then
red "WARP-GO 已安装,请先卸载 WARP-GO"
exit 1
fi
# 检查 VPS 的 IP 形式
check_stack
# 根据检测结果,选择适合的模式安装
if [[ -n $lan4 && -n $out4 && -z $lan6 && -z $out6 ]]; then
# IPv4 Only
wgcf1=$wg1 && wgcf2=$wg3
elif [[ -z $lan4 && -z $out4 && -n $lan6 && -n $out6 ]]; then
# IPv6 Only
wgcf1=$wg1 && wgcf2=$wg4 && wgcf3=$wg6
elif [[ -n $lan4 && -n $out4 && -n $lan6 && -n $out6 ]]; then
# 双栈
wgcf1=$wg1 && wgcf2=$wg3 && wgcf3=$wg6
elif [[ -n $lan4 && -z $out4 && -n $lan6 && -n $out6 ]]; then
# NAT IPv4 + IPv6
wgcf1=$wg1 && wgcf2=$wg4 && wgcf3=$wg6
fi
# 检测是否安装 WGCF,如安装,则切换配置文件。反之执行安装操作
if [[ -n $(type -P wg-quick) && -n $(type -P wgcf) ]]; then
switch_wgcf_conf
else
install_wgcf
fi
}
install_wgcf_dual() {
# 检查 WARP 状态
check_warp
# 如启动 WARP,则关闭
if [[ -f "/opt/warp-go/warp-go" ]]; then
systemctl stop warp-go
systemctl disable warp-go
elif [[ -n $(type -P wg-quick) && -n $(type -P wgcf) ]]; then
wg-quick down wgcf 2>/dev/null
systemctl stop wg-quick@wgcf >/dev/null 2>&1
systemctl disable wg-quick@wgcf
fi
# 因为 WGCF 和 WARP-GO 冲突,故检测 WARP-GO 之后打断安装
if [[ -f "/opt/warp-go/warp-go" ]]; then
red "WARP-GO 已安装,请先卸载 WARP-GO"
exit 1
fi
# 检查 VPS 的 IP 形式
check_stack
# 根据检测结果,选择适合的模式安装
if [[ -n $lan4 && -n $out4 && -z $lan6 && -z $out6 ]]; then
# IPv4 Only
wgcf1=$wg3 && wgcf2=$wg5
elif [[ -z $lan4 && -z $out4 && -n $lan6 && -n $out6 ]]; then
# IPv6 Only
wgcf1=$wg4 && wgcf2=$wg6
elif [[ -n $lan4 && -n $out4 && -n $lan6 && -n $out6 ]]; then
# 双栈
wgcf1=$wg3 && wgcf2=$wg7
elif [[ -n $lan4 && -z $out4 && -n $lan6 && -n $out6 ]]; then
# NAT IPv4 + IPv6
wgcf1=$wg4 && wgcf2=$wg6
fi
# 检测是否安装 WGCF,如安装,则切换配置文件。反之执行安装操作
if [[ -n $(type -P wg-quick) && -n $(type -P wgcf) ]]; then
switch_wgcf_conf
else
install_wgcf
fi
}
# 下载 WGCF
init_wgcf() {
wget --no-check-certificate https://gitlab.com/Misaka-blog/warp-script/-/raw/main/files/wgcf/wgcf-latest-linux-$(archAffix) -O /usr/local/bin/wgcf
chmod +x /usr/local/bin/wgcf
}
# 利用 WGCF 注册 CloudFlare WARP 账户
register_wgcf() {
if [[ $country4 == "Russia" || $country6 == "Russia" ]]; then
# 下载 WARP API 工具
wget https://gitlab.com/Misaka-blog/warp-script/-/raw/main/files/warp-api/main-linux-$(archAffix)
chmod +x main-linux-$(archAffix)
# 运行 WARP API
arch=$(archAffix)
result_output=$(./main-linux-$arch)
# 获取设备 ID、私钥及 WARP TOKEN
device_id=$(echo "$result_output" | awk -F ': ' '/device_id/{print $2}')
private_key=$(echo "$result_output" | awk -F ': ' '/private_key/{print $2}')
warp_token=$(echo "$result_output" | awk -F ': ' '/token/{print $2}')
license_key=$(echo "$result_output" | awk -F ': ' '/license/{print $2}')
# 写入 WGCF 配置文件
cat << EOF > wgcf-account.toml
access_token = '$warp_token'
device_id = '$device_id'
license_key = '$license_key'
private_key = '$private_key'
EOF
# 删除 WARP API 工具
rm -f main-linux-$(archAffix)
# 生成 WireGuard 配置文件
wgcf generate && chmod +x wgcf-profile.conf
else
# 如已注册 WARP 账户,则自动拉取。避免造成 CloudFlare 服务器负担
if [[ -f /etc/wireguard/wgcf-account.toml ]]; then
cp -f /etc/wireguard/wgcf-account.toml /root/wgcf-account.toml
fi
# 注册 WARP 账户,直到注册成功为止
until [[ -e wgcf-account.toml ]]; do
yellow "正在向 CloudFlare WARP 注册账号, 如提示 429 Too Many Requests 错误请耐心等待脚本重试注册即可"
wgcf register --accept-tos
sleep 5
done
chmod +x wgcf-account.toml
# 生成 WireGuard 配置文件
wgcf generate && chmod +x wgcf-profile.conf
fi
}
# 配置 WGCF 的 WireGuard 配置文件
conf_wgcf() {
echo $wgcf1 | sh
echo $wgcf2 | sh
echo $wgcf3 | sh
}
# 检查 WGCF 是否启动成功,如未启动成功则提示
check_wgcf() {
yellow "正在启动 WGCF-WARP"
i=0
while [ $i -le 4 ]; do
let i++
wg-quick down wgcf 2>/dev/null
systemctl stop wg-quick@wgcf >/dev/null 2>&1
systemctl start wg-quick@wgcf >/dev/null 2>&1
check_warp
if [[ $warp_v4 =~ on|plus ]] || [[ $warp_v6 =~ on|plus ]]; then
green "WGCF-WARP 已启动成功!"
systemctl enable wg-quick@wgcf >/dev/null 2>&1
echo ""
red "下面是恰饭广告:"
yellow "灵梦机场"
green "专线节点加速、支持流媒体解锁、支持ChatGPT、晚高峰4k秒开、大多为x0.5倍节点,这一切,仅9.9元"
yellow "优惠尽在:https://reimu.work/auth/register?code=aKKj"
yellow "TG群:https://t.me/ReimuCloudGrup"
echo ""
before_showinfo && show_info
break
else
red "WGCF-WARP 启动失败!"
fi
check_warp
if [[ ! $warp_v4 =~ on|plus && ! $warp_v6 =~ on|plus ]]; then
wg-quick down wgcf 2>/dev/null
systemctl stop wg-quick@wgcf >/dev/null 2>&1
systemctl disable wg-quick@wgcf >/dev/null 2>&1
red "安装 WGCF-WARP 失败!"
green "建议如下:"
yellow "1. 强烈建议使用官方源升级系统及内核加速!如已使用第三方源及内核加速,请务必更新到最新版,或重置为官方源"
yellow "2. 部分 VPS 系统极度精简,相关依赖需自行安装后再尝试"
yellow "3. 查看 https://www.cloudflarestatus.com/ ,你当前VPS就近区域可能处于黄色的【Re-routed】状态"
yellow "4. WGCF 在香港、美西区域遭到 CloudFlare 官方封禁,请卸载 WGCF ,然后使用 WARP-GO 重试"
yellow "5. 脚本可能跟不上时代, 建议截图发布到 GitLab Issues 或 TG 群询问"
exit 1
fi
done
}
install_wgcf() {
# 检测系统要求,如未达到要求则打断安装
[[ $SYSTEM == "CentOS" ]] && [[ ${OSID} -lt 7 ]] && yellow "当前系统版本:${CMD} \nWGCF-WARP模式仅支持CentOS / Almalinux / Rocky / Oracle Linux 7及以上版本的系统" && exit 1
[[ $SYSTEM == "Debian" ]] && [[ ${OSID} -lt 10 ]] && yellow "当前系统版本:${CMD} \nWGCF-WARP模式仅支持Debian 10及以上版本的系统" && exit 1
[[ $SYSTEM == "Fedora" ]] && [[ ${OSID} -lt 29 ]] && yellow "当前系统版本:${CMD} \nWGCF-WARP模式仅支持Fedora 29及以上版本的系统" && exit 1
[[ $SYSTEM == "Ubuntu" ]] && [[ ${OSID} -lt 18 ]] && yellow "当前系统版本:${CMD} \nWGCF-WARP模式仅支持Ubuntu 16.04及以上版本的系统" && exit 1
# 检测 TUN 模块是否开启
check_tun
# 设置 IPv4 / IPv6 优先级
stack_priority
# 安装 WGCF 必需依赖
if [[ $SYSTEM == "Alpine" ]]; then
${PACKAGE_INSTALL[int]} sudo curl wget bash grep net-tools iproute2 openresolv openrc iptables ip6tables wireguard-tools
fi
if [[ $SYSTEM == "CentOS" ]]; then
${PACKAGE_INSTALL[int]} epel-release
${PACKAGE_INSTALL[int]} sudo curl wget unzip iproute net-tools wireguard-tools iptables bc htop screen python3 iputils qrencode
if [[ $OSID == 9 ]] && [[ -z $(type -P resolvconf) ]]; then
wget -N https://gitlab.com/Misaka-blog/warp-script/-/raw/main/files/resolvconf -O /usr/sbin/resolvconf
chmod +x /usr/sbin/resolvconf
fi
fi
if [[ $SYSTEM == "Fedora" ]]; then
${PACKAGE_INSTALL[int]} sudo curl wget unzip iproute net-tools wireguard-tools iptables bc htop screen python3 iputils qrencode
fi
if [[ $SYSTEM == "Debian" ]]; then
${PACKAGE_UPDATE[int]}
${PACKAGE_INSTALL[int]} sudo wget curl unzip lsb-release bc htop screen python3 iputils-ping qrencode
echo "deb http://deb.debian.org/debian $(lsb_release -sc)-backports main" | tee /etc/apt/sources.list.d/backports.list
${PACKAGE_UPDATE[int]}
${PACKAGE_INSTALL[int]} --no-install-recommends net-tools iproute2 openresolv dnsutils wireguard-tools iptables
fi
if [[ $SYSTEM == "Ubuntu" ]]; then
${PACKAGE_UPDATE[int]}
${PACKAGE_INSTALL[int]} sudo curl wget unzip lsb-release bc htop screen python3 iputils-ping qrencode
${PACKAGE_INSTALL[int]} --no-install-recommends net-tools iproute2 openresolv dnsutils wireguard-tools iptables
fi
# 如 Linux 系统内核版本 < 5.6,或为 OpenVZ / LXC 虚拟化架构的VPS,则安装 Wireguard-GO
if [[ $main -lt 5 ]] || [[ $minor -lt 6 ]] || [[ $VIRT =~ lxc|openvz ]]; then
wget -N --no-check-certificate https://gitlab.com/Misaka-blog/warp-script/-/raw/main/files/wireguard-go/wireguard-go-$(archAffix) -O /usr/bin/wireguard-go
chmod +x /usr/bin/wireguard-go
fi
# IPv4 only VPS 开启 IPv6 支持
if [[ $(sysctl -a | grep 'disable_ipv6.*=.*1') || $(cat /etc/sysctl.{conf,d/*} | grep 'disable_ipv6.*=.*1') ]]; then
sed -i '/disable_ipv6/d' /etc/sysctl.{conf,d/*}
echo 'net.ipv6.conf.all.disable_ipv6 = 0' >/etc/sysctl.d/ipv6.conf
sysctl -w net.ipv6.conf.all.disable_ipv6=0
fi
# 下载并安装 WGCF
init_wgcf
# 在 WGCF 处注册账户
register_wgcf
# 检测 /etc/wireguard 文件夹是否创建,如未创建则创建一个
if [[ ! -d "/etc/wireguard" ]]; then
mkdir /etc/wireguard
fi
# 移动对应的配置文件,避免用户删除
cp -f wgcf-profile.conf /etc/wireguard/wgcf.conf
mv -f wgcf-profile.conf /etc/wireguard/wgcf-profile.conf
mv -f wgcf-account.toml /etc/wireguard/wgcf-account.toml
# 设置 WGCF 的 WireGuard 配置文件
conf_wgcf
# 检查最佳 MTU 值,并应用至 WGCF 配置文件
check_mtu
sed -i "s/MTU.*/MTU = $MTU/g" /etc/wireguard/wgcf.conf
# 优选 EndPoint IP,并应用至 WGCF 配置文件
check_endpoint
sed -i "s/engage.cloudflareclient.com:2408/$best_endpoint/g" /etc/wireguard/wgcf.conf
# 启动 WGCF,并检查 WGCF 是否启动成功
check_wgcf
}
switch_wgcf_conf() {
# 关闭 WGCF
wg-quick down wgcf 2>/dev/null
systemctl stop wg-quick@wgcf 2>/dev/null
systemctl disable wg-quick@wgcf 2>/dev/null
# 删除配置好的 WGCF WireGuard 配置文件,并重新从 wgcf-profile.conf 拉取
rm -rf /etc/wireguard/wgcf.conf
cp -f /etc/wireguard/wgcf-profile.conf /etc/wireguard/wgcf.conf >/dev/null 2>&1
# 设置 WGCF 的 WireGuard 配置文件
conf_wgcf
# 检查最佳 MTU 值,并应用至 WGCF 配置文件
check_mtu
sed -i "s/MTU.*/MTU = $MTU/g" /etc/wireguard/wgcf.conf
# 优选 EndPoint IP,并应用至 WGCF 配置文件
check_endpoint
sed -i "s/engage.cloudflareclient.com:2408/$best_endpoint/g" /etc/wireguard/wgcf.conf
# 启动 WGCF,并检查 WGCF 是否启动成功
check_wgcf
}
# 卸载 WGCF
uninstall_wgcf() {
# 关闭 WGCF
wg-quick down wgcf 2>/dev/null
systemctl stop wg-quick@wgcf 2>/dev/null
systemctl disable wg-quick@wgcf 2>/dev/null
# 卸载 WireGuard 依赖
${PACKAGE_UNINSTALL[int]} wireguard-tools
# 因为 WireProxy 需要依赖 WGCF,如未检测到,则删除账户信息文件
if [[ -z $(type -P wireproxy) ]]; then
rm -f /usr/local/bin/wgcf
rm -f /etc/wireguard/wgcf-profile.toml
rm -f /etc/wireguard/wgcf-account.toml
fi
# 删除 WGCF WireGuard 配置文件
rm -f /etc/wireguard/wgcf.conf
# 如有 WireGuard-GO,则删除
rm -f /usr/bin/wireguard-go
# 恢复 VPS 默认的出站规则
if [[ -e /etc/gai.conf ]]; then
sed -i '/^precedence[ ]*::ffff:0:0\/96[ ]*100/d' /etc/gai.conf
fi
green "WGCF-WARP 已彻底卸载成功!"
before_showinfo && show_info
}
# 设置 WARP-GO 配置文件
conf_wpgo() {
echo $wpgo1 | sh
echo $wpgo2 | sh
}
# 利用 WARP API,注册 WARP 免费版账号并应用至 WARP-GO
register_wpgo(){
# 下载 WARP API 工具
wget https://gitlab.com/Misaka-blog/warp-script/-/raw/main/files/warp-api/main-linux-$(archAffix)
chmod +x main-linux-$(archAffix)
# 运行 WARP API
arch=$(archAffix)
result_output=$(./main-linux-$arch)
# 获取设备 ID、私钥及 WARP TOKEN
device_id=$(echo "$result_output" | awk -F ': ' '/device_id/{print $2}')
private_key=$(echo "$result_output" | awk -F ': ' '/private_key/{print $2}')
warp_token=$(echo "$result_output" | awk -F ': ' '/token/{print $2}')
# 写入 WARP-GO 配置文件
cat << EOF > /opt/warp-go/warp.conf
[Account]
Device = $device_id
PrivateKey = $private_key
Token = $warp_token
Type = free
Name = WARP
MTU = 1280
[Peer]
PublicKey = bmXOC+F1FxEMF9dyiK2H5/1SUtzH0JuVo51h2wPfgyo=
Endpoint = 162.159.193.10:1701
# AllowedIPs = 0.0.0.0/0
# AllowedIPs = ::/0
KeepAlive = 30
EOF
sed -i '0,/AllowedIPs/{/AllowedIPs/d;}' /opt/warp-go/warp.conf
sed -i '/KeepAlive/a [Script]' /opt/warp-go/warp.conf
# 删除 WARP API 工具
rm -f main-linux-$(archAffix)
}
# 检测 WARP-GO 是否正常运行
check_wpgo() {
yellow "正在启动 WARP-GO"
i=0
while [ $i -le 4 ]; do
let i++
kill -15 $(pgrep warp-go) >/dev/null 2>&1
sleep 2
systemctl stop warp-go
systemctl disable warp-go >/dev/null 2>&1
systemctl start warp-go
systemctl enable warp-go >/dev/null 2>&1
check_warp
sleep 2
if [[ $warp_v4 =~ on|plus ]] || [[ $warp_v6 =~ on|plus ]]; then
green "WARP-GO 已启动成功!"
echo ""
red "下面是恰饭广告:"
yellow "灵梦机场"
green "专线节点加速、支持流媒体解锁、支持ChatGPT、晚高峰4k秒开、大多为x0.5倍节点,这一切,仅9.9元"
yellow "优惠尽在:https://reimu.work/auth/register?code=aKKj"
yellow "TG群:https://t.me/ReimuCloudGrup"
echo ""
before_showinfo && show_info
break
else
red "WARP-GO 启动失败!"
fi
check_warp
if [[ ! $warp_v4 =~ on|plus && ! $warp_v6 =~ on|plus ]]; then
systemctl stop warp-go
systemctl disable warp-go >/dev/null 2>&1
red "安装 WARP-GO 失败!"
green "建议如下:"
yellow "1. 强烈建议使用官方源升级系统及内核加速!如已使用第三方源及内核加速,请务必更新到最新版,或重置为官方源"
yellow "2. 部分 VPS 系统极度精简,相关依赖需自行安装后再尝试"
yellow "3. 脚本可能跟不上时代, 建议截图发布到 GitLab Issues 或 TG 群询问"
exit 1
fi
done
}
# 选择 WARP-GO 安装 / 切换模式
select_wpgo() {
yellow "请选择 WARP-GO 安装 / 切换的模式"
echo ""
echo -e " ${GREEN}1.${PLAIN} 安装 / 切换 WARP-GO 单栈模式 ${YELLOW}(IPv4)${PLAIN}"
echo -e " ${GREEN}2.${PLAIN} 安装 / 切换 WARP-GO 单栈模式 ${YELLOW}(IPv6)${PLAIN}"
echo -e " ${GREEN}3.${PLAIN} 安装 / 切换 WARP-GO 双栈模式"
echo ""
read -p "请输入选项 [1-3]: " wpgo_mode
if [ "$wpgo_mode" = "1" ]; then
install_wpgo_ipv4
elif [ "$wpgo_mode" = "2" ]; then
install_wpgo_ipv6
elif [ "$wpgo_mode" = "3" ]; then
install_wpgo_dual
else
red "输入错误,请重新输入"
select_wpgo
fi
}
install_wpgo_ipv4() {
# 检查 WARP 状态
check_warp
# 如启动 WARP,则关闭
if [[ -f "/opt/warp-go/warp-go" ]]; then
systemctl stop warp-go
systemctl disable warp-go
elif [[ -n $(type -P wg-quick) && -n $(type -P wgcf) ]]; then
wg-quick down wgcf 2>/dev/null
systemctl stop wg-quick@wgcf >/dev/null 2>&1
systemctl disable wg-quick@wgcf
fi
# 因为 WARP-GO 和 WGCF 冲突,故检测 WGCF 之后打断安装
if [[ -n $(type -P wg-quick) && -n $(type -P wgcf) ]]; then
red "WGCF-WARP 已安装,请先卸载 WGCF-WARP"
exit 1
fi
# 检查 VPS 的 IP 形式
check_stack
# 根据检测结果,选择适合的模式安装
if [[ -n $lan4 && -n $out4 && -z $lan6 && -z $out6 ]]; then
# IPv4 Only
wpgo1=$wgo1 && wpgo2=$wgo4
elif [[ -z $lan4 && -z $out4 && -n $lan6 && -n $out6 ]]; then
# IPv6 Only
wpgo1=$wgo1 && wpgo2=$wgo5
elif [[ -n $lan4 && -n $out4 && -n $lan6 && -n $out6 ]]; then
# 双栈
wpgo1=$wgo1 && wpgo2=$wgo6
elif [[ -n $lan4 && -z $out4 && -n $lan6 && -n $out6 ]]; then
# NAT IPv4 + IPv6
wpgo1=$wgo1 && wpgo2=$wgo6
fi
# 检测是否安装 WARP-GO,如安装,则切换配置文件。反之执行安装操作
if [[ -f "/opt/warp-go/warp-go" ]]; then
switch_wpgo_conf
else
install_wpgo
fi
}
install_wpgo_ipv6() {
# 检查 WARP 状态
check_warp
# 如启动 WARP,则关闭
if [[ -f "/opt/warp-go/warp-go" ]]; then
systemctl stop warp-go
systemctl disable warp-go
elif [[ -n $(type -P wg-quick) && -n $(type -P wgcf) ]]; then
wg-quick down wgcf 2>/dev/null
systemctl stop wg-quick@wgcf >/dev/null 2>&1
systemctl disable wg-quick@wgcf
fi
# 因为 WARP-GO 和 WGCF 冲突,故检测 WGCF 之后打断安装
if [[ -n $(type -P wg-quick) && -n $(type -P wgcf) ]]; then
red "WGCF-WARP 已安装,请先卸载 WGCF-WARP"
exit 1
fi
# 检查 VPS 的 IP 形式
check_stack
# 根据检测结果,选择适合的模式安装
if [[ -n $lan4 && -n $out4 && -z $lan6 && -z $out6 ]]; then
# IPv4 Only
wpgo1=$wgo2 && wpgo2=$wgo4
elif [[ -z $lan4 && -z $out4 && -n $lan6 && -n $out6 ]]; then
# IPv6 Only
wpgo1=$wgo2 && wpgo2=$wgo5
elif [[ -n $lan4 && -n $out4 && -n $lan6 && -n $out6 ]]; then
# 双栈
wpgo1=$wgo2 && wpgo2=$wgo6
elif [[ -n $lan4 && -z $out4 && -n $lan6 && -n $out6 ]]; then
# NAT IPv4 + IPv6
wpgo1=$wgo2 && wpgo2=$wgo6
fi
# 检测是否安装 WARP-GO,如安装,则切换配置文件。反之执行安装操作
if [[ -f "/opt/warp-go/warp-go" ]]; then
switch_wpgo_conf
else
install_wpgo
fi
}
install_wpgo_dual() {
# 检查 WARP 状态
check_warp