This repository has been archived by the owner on Aug 28, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 49
/
v2ray-go.sh
1577 lines (1551 loc) · 43.3 KB
/
v2ray-go.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
##################################################
# Anything wrong? Find me via telegram: @CN_SZTL #
##################################################
#! /bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
function set_fonts_colors(){
# Font colors
default_fontcolor="\033[0m"
red_fontcolor="\033[31m"
green_fontcolor="\033[32m"
# Background colors
green_backgroundcolor="\033[42;37m"
# Fonts
error_font="${red_fontcolor}[Error]${default_fontcolor}"
ok_font="${green_fontcolor}[OK]${default_fontcolor}"
}
function check_os(){
clear
echo -e "正在检测当前是否为ROOT用户..."
if [[ $EUID -ne 0 ]]; then
clear
echo -e "${error_font}当前并非ROOT用户,请先切换到ROOT用户后再使用本脚本。"
exit 1
else
clear
echo -e "${ok_font}检测到当前为Root用户。"
fi
clear
echo -e "正在检测此OS是否被支持..."
if [ ! -z "$(cat /etc/issue | grep Debian)" ];then
OS='debian'
clear
echo -e "${ok_font}该脚本支持您的系统。"
elif [ ! -z "$(cat /etc/issue | grep Ubuntu)" ];then
OS='ubuntu'
clear
echo -e "${ok_font}该脚本支持您的系统。"
else
clear
echo -e "${error_font}目前暂不支持您使用的操作系统,请切换至Debian/Ubuntu。"
exit 1
fi
}
function check_install_status(){
install_type=$(cat /etc/v2ray/install_type.txt)
if [[ ${install_type} = "" ]]; then
install_status="${red_fontcolor}未安装${default_fontcolor}"
now_vmess_link="${red_fontcolor}未安装${default_fontcolor}"
else
install_status="${green_fontcolor}已安装${default_fontcolor}"
now_vmess_link="${green_backgroundcolor}$(cat /etc/v2ray/vmess_link.txt)${default_fontcolor}"
fi
v2ray_config=$(cat /etc/v2ray/config.json)
if [[ ${v2ray_config} = "" ]]; then
v2ray_status="${red_fontcolor}未安装${default_fontcolor}"
else
v2ray_pid=$(ps -ef |grep "v2ray" |grep -v "grep" | grep -v ".sh"| grep -v "init.d" |grep -v "service" |awk '{print $2}')
if [[ ${v2ray_pid} = "" ]]; then
v2ray_status="${red_fontcolor}未运行${default_fontcolor}"
else
v2ray_status="${green_fontcolor}正在运行${default_fontcolor} | ${green_fontcolor}${v2ray_pid}${default_fontcolor}"
fi
fi
caddy_config=$(cat /usr/local/caddy/Caddyfile)
if [[ ${caddy_config} = "" ]]; then
caddy_status="${red_fontcolor}未安装${default_fontcolor}"
else
caddy_pid=$(ps -ef |grep "caddy" |grep -v "grep" | grep -v ".sh"| grep -v "init.d" |grep -v "service" |awk '{print $2}')
if [[ ${caddy_pid} = "" ]]; then
caddy_status="${red_fontcolor}未运行${default_fontcolor}"
else
caddy_status="${green_fontcolor}正在运行${default_fontcolor} | ${green_fontcolor}${caddy_pid}${default_fontcolor}"
fi
fi
}
function echo_install_list(){
clear
echo -e "脚本当前安装状态:${install_status}
--------------------------------------------------------------------------------------------------
安装V2ray:
0.清除V2Ray/Caddy
1.Socks5
2.TCP+HTTP伪装
3.TCP+TLS
4.Mkcp+BT流量伪装
5.Mkcp+DTLS伪装
6.Mkcp+Facetime视频流量伪装+动态端口
7.HTTP/2+TLS
8.Websocket+TLS+网站伪装
--------------------------------------------------------------------------------------------------
V2Ray当前运行状态:${v2ray_status}
Caddy当前运行状态:${caddy_status}
9.更新脚本
10.更新程序
11.卸载程序
12.启动程序
13.关闭程序
14.重启程序
--------------------------------------------------------------------------------------------------
Vmess链接:${now_vmess_link}
--------------------------------------------------------------------------------------------------"
stty erase '^H' && read -p "请输入序号:" determine_type
if [[ ${determine_type} = "" ]]; then
clear
echo -e "${error_font}请输入序号!"
exit 1
elif [[ ${determine_type} -lt 0 ]]; then
clear
echo -e "${error_font}请输入正确的序号!"
exit 1
elif [[ ${determine_type} -gt 14 ]]; then
clear
echo -e "${error_font}请输入正确的序号!"
exit 1
else
data_processing
fi
}
function data_processing(){
clear
echo -e "正在处理请求中..."
if [[ ${determine_type} = "0" ]]; then
uninstall_old
elif [[ ${determine_type} = "9" ]]; then
upgrade_shell_script
elif [[ ${determine_type} = "10" ]]; then
prevent_uninstall_check
upgrade_program
restart_service
elif [[ ${determine_type} = "11" ]]; then
prevent_uninstall_check
uninstall_program
elif [[ ${determine_type} = "12" ]]; then
prevent_uninstall_check
start_service
elif [[ ${determine_type} = "13" ]]; then
prevent_uninstall_check
stop_service
elif [[ ${determine_type} = "14" ]]; then
prevent_uninstall_check
restart_service
else
prevent_install_check
os_update
check_time
generate_base_config
clear
echo -e "安装V2Ray主程序中..."
bash <(curl https://install.direct/go.sh)
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}V2Ray安装成功。"
else
clear
echo -e "${error_font}V2Ray安装失败!"
exit 1
fi
fi
if [[ ${determine_type} = "1" ]]; then
wget -O "/etc/v2ray/config.json" "https://raw.githubusercontent.com/1715173329/v2ray-onekey/master/configs/socks5.json"
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}Socks5 配置文件下载成功。"
else
clear
echo -e "${error_font}Socks5 配置文件下载失败!"
clear_install
exit 1
fi
input_port
stty erase '^H' && read -p "请输入Socks用户名(默认:username):" install_socks_username
if [[ ${install_socks_username} = "" ]]; then
install_socks_username="username"
else
sed -i "s/username/${install_socks_username}/g" "/etc/v2ray/config.json"
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}Socks用户名配置成功。"
else
clear
echo -e "${error_font}Socks用户名配置失败!"
clear_install
exit 1
fi
fi
stty erase '^H' && read -p "请输入Socks密码(默认:passwd):" install_socks_password
if [[ ${install_socks_password} = "" ]]; then
install_socks_password="passwd"
else
sed -i "s/passwd/${install_socks_password}/g" "/etc/v2ray/config.json"
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}Socks密码配置成功。"
else
clear
echo -e "${error_font}Socks密码配置失败!"
clear_install
exit 1
fi
fi
echo "1" > /etc/v2ray/install_type.txt
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}写入安装信息成功。"
else
clear
echo -e "${error_font}写入安装信息失败!"
clear_install
exit 1
fi
restart_service
echo_v2ray_config
elif [[ ${determine_type} = "2" ]]; then
wget -O "/etc/v2ray/config.json" "https://raw.githubusercontent.com/1715173329/v2ray-onekey/master/configs/tcp-http.json"
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}V2Ray 配置文件下载成功。"
else
clear
echo -e "${error_font}V2Ray 配置文件下载失败!"
clear_install
exit 1
fi
clear
install_port="80"
check_port
sed -i "s/UserUUID/${UUID}/g" "/etc/v2ray/config.json"
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}V2Ray UUID配置成功。"
else
clear
echo -e "${error_font}V2Ray UUID配置失败!"
clear_install
exit 1
fi
clear
stty erase '^H' && read -p "请输入伪装域名,多个域名请使用英文逗号\",\"隔开(默认:cache.m.iqiyi.com):" false_domain
if [[ ${false_domain} = "" ]]; then
false_domain="cache.m.iqiyi.com"
else
sed -i "s/cache.m.iqiyi.com/${false_domain}/g" "/etc/v2ray/config.json"
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}V2Ray 伪装域名配置成功。"
else
clear
echo -e "${error_font}V2Ray 伪装域名配置失败!"
clear_install
exit 1
fi
fi
echo "2" > /etc/v2ray/install_type.txt
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}写入安装信息成功。"
else
clear
echo -e "${error_font}写入安装信息失败!"
clear_install
exit 1
fi
restart_service
echo_v2ray_config
elif [[ ${determine_type} = "3" ]]; then
clear
echo -e "正在安装acme.sh中..."
curl https://get.acme.sh | sh
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}acme.sh 安装成功。"
else
clear
echo -e "${error_font}acme.sh 安装失败,请检查相关依赖是否正确安装。"
clear_install
exit 1
fi
wget -O "/etc/v2ray/config.json" "https://raw.githubusercontent.com/1715173329/v2ray-onekey/master/configs/tcp-tls.json"
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}V2Ray 配置文件下载成功。"
else
clear
echo -e "${error_font}V2Ray 配置文件下载失败!"
clear_install
exit 1
fi
clear
stty erase '^H' && read -p "请输入监听端口(默认监听443端口):" install_port
if [[ ${install_port} = "" ]]; then
install_port="443"
fi
check_port
sed -i "s/443/${install_port}/g" "/etc/v2ray/config.json"
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}V2Ray端口配置成功。"
else
clear
echo -e "${error_font}V2Ray端口配置失败!"
clear_install
exit 1
fi
clear
sed -i "s/UserUUID/${UUID}/g" "/etc/v2ray/config.json"
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}V2Ray UUID配置成功。"
else
clear
echo -e "${error_font}V2Ray UUID配置失败!"
clear_install
exit 1
fi
clear
stty erase '^H' && read -p "请输入您的域名:" install_domain
if [[ ${install_domain} = "" ]]; then
clear
echo -e "${error_font}请输入您的域名。"
clear_linstall
exit 1
else
clear
echo -e "正在签发证书中..."
bash ~/.acme.sh/acme.sh --issue -d ${install_domain} --standalone -k ec-256 --force
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}证书生成成功。"
bash ~/.acme.sh/acme.sh --installcert -d ${install_domain} --fullchainpath /etc/v2ray/pem.pem --keypath /etc/v2ray/key.key --ecc
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}证书配置成功。"
else
clear
echo -e "${error_font}证书配置失败!"
clear_install
exit 1
fi
else
clear
echo -e "${error_font}证书生成失败!"
clear_install
exit 1
fi
sed -i "s/V2rayAddress/${install_domain}/g" "/etc/v2ray/config.json"
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}V2Ray 域名配置成功。"
else
clear
echo -e "${error_font}V2Ray 域名配置失败!"
clear_install
exit 1
fi
echo "${install_domain}" > /etc/v2ray/full_domain.txt
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}V2Ray 域名写入成功。"
else
clear
echo -e "${error_font}V2Ray 域名写入失败!"
clear_install
exit 1
fi
fi
echo "3" > /etc/v2ray/install_type.txt
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}写入安装信息成功。"
else
clear
echo -e "${error_font}写入安装信息失败!"
clear_install
exit 1
fi
restart_service
echo_v2ray_config
elif [[ ${determine_type} = "4" ]]; then
wget -O "/etc/v2ray/config.json" "https://raw.githubusercontent.com/1715173329/v2ray-onekey/master/configs/mkcp-utp.json"
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}V2Ray 配置文件下载成功。"
else
clear
echo -e "${error_font}V2Ray 配置文件下载失败!"
clear_install
exit 1
fi
clear
input_port
sed -i "s/UserUUID/${UUID}/g" "/etc/v2ray/config.json"
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}V2Ray UUID配置成功。"
else
clear
echo -e "${error_font}V2Ray UUID配置失败!"
clear_install
exit 1
fi
echo "4" > /etc/v2ray/install_type.txt
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}写入安装信息成功。"
else
clear
echo -e "${error_font}写入安装信息失败!"
clear_install
exit 1
fi
restart_service
echo_v2ray_config
elif [[ ${determine_type} = "5" ]]; then
wget -O "/etc/v2ray/config.json" "https://raw.githubusercontent.com/1715173329/v2ray-onekey/master/configs/mkcp-dtls.json"
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}V2Ray 配置文件下载成功。"
else
clear
echo -e "${error_font}V2Ray 配置文件下载失败!"
clear_install
exit 1
fi
clear
input_port
sed -i "s/UserUUID/${UUID}/g" "/etc/v2ray/config.json"
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}V2Ray UUID配置成功。"
else
clear
echo -e "${error_font}V2Ray UUID配置失败!"
clear_install
exit 1
fi
echo "5" > /etc/v2ray/install_type.txt
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}写入安装信息成功。"
else
clear
echo -e "${error_font}写入安装信息失败!"
clear_install
exit 1
fi
restart_service
echo_v2ray_config
elif [[ ${determine_type} = "6" ]]; then
wget -O "/etc/v2ray/config.json" "https://raw.githubusercontent.com/1715173329/v2ray-onekey/master/configs/mkcp-srtp-dynport.json"
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}V2Ray 配置文件下载成功。"
else
clear
echo -e "${error_font}V2Ray 配置文件下载失败!"
clear_install
exit 1
fi
clear
input_port
sed -i "s/UserUUID/${UUID}/g" "/etc/v2ray/config.json"
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}V2Ray UUID配置成功。"
else
clear
echo -e "${error_font}V2Ray UUID配置失败!"
clear_install
exit 1
fi
stty erase '^H' && read -p "请输入动态端口范围(默认范围:60000-61315):" install_dynport
if [[ ${install_dynport} = "" ]]; then
install_dynport="60000-61315"
else
sed -i "s/60000-61315/${install_dynport}/g" "/etc/v2ray/config.json"
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}V2Ray 动态端口配置成功。"
else
clear
echo -e "${error_font}V2Ray 动态端口配置失败!"
clear_install
exit 1
fi
fi
echo "6" > /etc/v2ray/install_type.txt
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}写入安装信息成功。"
else
clear
echo -e "${error_font}写入安装信息失败!"
clear_install
exit 1
fi
restart_service
echo_v2ray_config
elif [[ ${determine_type} = "7" ]]; then
clear
echo -e "正在安装acme.sh中..."
curl https://get.acme.sh | sh
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}acme.sh 安装成功。"
else
clear
echo -e "${error_font}acme.sh 安装失败,请检查相关依赖是否正确安装。"
clear_install
exit 1
fi
wget -O "/etc/v2ray/config.json" "https://raw.githubusercontent.com/1715173329/v2ray-onekey/master/configs/h2-path.json"
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}V2Ray 配置文件下载成功。"
else
clear
echo -e "${error_font}V2Ray 配置文件下载失败!"
clear_install
exit 1
fi
clear
stty erase '^H' && read -p "请输入监听端口(默认监听443端口):" install_port
if [[ ${install_port} = "" ]]; then
install_port="443"
fi
check_port
sed -i "s/443/${install_port}/g" "/etc/v2ray/config.json"
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}V2Ray端口配置成功。"
else
clear
echo -e "${error_font}V2Ray端口配置失败!"
clear_install
exit 1
fi
sed -i "s/UserUUID/${UUID}/g" "/etc/v2ray/config.json"
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}V2Ray UUID配置成功。"
else
clear
echo -e "${error_font}V2Ray UUID配置失败!"
clear_install
exit 1
fi
clear
stty erase '^H' && read -p "请输入您的域名:" install_domain
if [[ ${install_domain} = "" ]]; then
clear
echo -e "${error_font}请输入您的域名。"
clear_install
exit 1
else
clear
echo -e "正在签发证书中..."
bash ~/.acme.sh/acme.sh --issue -d ${install_domain} --standalone -k ec-256 --force
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}证书生成成功。"
bash ~/.acme.sh/acme.sh --installcert -d ${install_domain} --fullchainpath /etc/v2ray/pem.pem --keypath /etc/v2ray/key.key --ecc
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}证书配置成功。"
else
clear
echo -e "${error_font}证书配置失败!"
clear_install
exit 1
fi
else
clear
echo -e "${error_font}证书生成失败!"
clear_install
exit 1
fi
sed -i "s/V2rayAddress/${install_domain}/g" "/etc/v2ray/config.json"
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}V2Ray 域名配置成功。"
else
clear
echo -e "${error_font}V2Ray 域名配置失败!"
clear_install
exit 1
fi
echo "${install_domain}" > /etc/v2ray/full_domain.txt
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}V2Ray 域名写入成功。"
else
clear
echo -e "${error_font}V2Ray 域名写入失败!"
clear_install
exit 1
fi
sed -i "s/PathUUID/${UUID2}/g" "/etc/v2ray/config.json"
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}V2Ray UUID配置成功。"
else
clear
echo -e "${error_font}V2Ray UUID配置失败!"
clear_install
exit 1
fi
fi
echo "7" > /etc/v2ray/install_type.txt
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}写入安装信息成功。"
else
clear
echo -e "${error_font}写入安装信息失败!"
clear_install
exit 1
fi
restart_service
echo_v2ray_config
elif [[ ${determine_type} = "8" ]]; then
clear
echo -e "正在安装acme.sh中..."
curl https://get.acme.sh | sh
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}acme.sh 安装成功。"
else
clear
echo -e "${error_font}acme.sh 安装失败,请检查相关依赖是否正确安装。"
clear_install
exit 1
fi
bash <(curl https://raw.githubusercontent.com/ToyoDAdoubi/doubi/master/caddy_install.sh)
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}Caddy 安装成功。"
else
clear
echo -e "${error_font}Caddy 安装失败,请检查相关依赖是否正确安装。"
clear_install
exit 1
fi
wget -O "/etc/v2ray/config.json" "https://raw.githubusercontent.com/1715173329/v2ray-onekey/master/configs/websocket-tls-website-path.json"
wget -O "/usr/local/caddy/Caddyfile" "https://raw.githubusercontent.com/1715173329/v2ray-onekey/master/configs/websocket-tls-website-path.Caddyfile"
clear
install_port="80"
check_port
clear
install_port="443"
check_port
sed -i "s/UserUUID/${UUID}/g" "/etc/v2ray/config.json"
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}V2Ray UUID配置成功。"
else
clear
echo -e "${error_font}V2Ray UUID配置失败!"
clear_install
exit 1
fi
clear
stty erase '^H' && read -p "请输入您的域名:" install_domain
if [[ ${install_domain} = "" ]]; then
clear
echo -e "${error_font}请输入您的域名。"
clear_install
exit 1
else
clear
echo -e "正在签发证书中..."
bash ~/.acme.sh/acme.sh --issue -d ${install_domain} --standalone -k ec-256 --force
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}证书生成成功。"
bash ~/.acme.sh/acme.sh --installcert -d ${install_domain} --fullchainpath /etc/v2ray/pem.pem --keypath /etc/v2ray/key.key --ecc
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}证书配置成功。"
else
clear
echo -e "${error_font}证书配置失败!"
clear_install
exit 1
fi
else
clear
echo -e "${error_font}证书生成失败!"
clear_install
exit 1
fi
sed -i "s/V2rayAddress/${install_domain}/g" "/etc/v2ray/config.json"
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}V2Ray 域名配置成功。"
else
clear
echo -e "${error_font}V2Ray 域名配置失败!"
clear_install
exit 1
fi
echo "${install_domain}" > /etc/v2ray/full_domain.txt
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}V2Ray 域名写入成功。"
else
clear
echo -e "${error_font}V2Ray 域名写入失败!"
clear_install
exit 1
fi
sed -i "s/PathUUID/${UUID2}/g" "/etc/v2ray/config.json"
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}V2Ray UUID配置成功。"
else
clear
echo -e "${error_font}V2Ray UUID配置失败!"
clear_install
exit 1
fi
sed -i "s/PathUUID/${UUID2}/g" "/usr/local/caddy/Caddyfile"
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}Caddy UUID配置成功。"
else
clear
echo -e "${error_font}Caddy UUID配置失败!"
clear_install
exit 1
fi
sed -i "s/V2rayAddress/${install_domain}/g" "/usr/local/caddy/Caddyfile"
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}Caddy 域名配置成功。"
else
clear
echo -e "${error_font}Caddy 域名配置失败!"
clear_install
exit 1
fi
sed -i "s/V2RayListenPort/${v2_listen_port}/g" "/etc/v2ray/config.json"
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}V2Ray 监听端口配置成功。"
else
clear
echo -e "${error_font}V2Ray 监听端口配置失败!"
clear_install
exit 1
fi
sed -i "s/V2RayListenPort/${v2_listen_port}/g" "/usr/local/caddy/Caddyfile"
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}Caddy 监听端口配置成功。"
else
clear
echo -e "${error_font}Caddy 监听端口配置失败!"
clear_install
exit 1
fi
mkdir /etc/v2ray/pages
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}创建文件夹成功。"
else
clear
echo -e "${error_font}创建文件夹失败!"
clear_install
exit 1
fi
cd /etc/v2ray/pages
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}进入文件夹成功。"
else
clear
echo -e "${error_font}进入文件夹失败!"
clear_install
exit 1
fi
wget -O "/etc/v2ray/pages/v2ray-page.zip" "https://github.com/1715173329/v2ray-onekey/blob/master/pages/v2ray-page.zip?raw=true"
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}下载网页文件压缩包成功。"
else
clear
echo -e "${error_font}下载网页文件压缩包失败!"
clear_install
exit 1
fi
unzip /etc/v2ray/pages/v2ray-page.zip
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}解压网页文件成功。"
else
clear
echo -e "${error_font}解压网页文件失败!"
clear_install
exit 1
fi
rm -rf /etc/v2ray/pages/v2ray-page.zip
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}删除网页文件压缩包成功。"
else
clear
echo -e "${error_font}删除网页文件压缩包失败!"
clear_install
exit 1
fi
sed -i "s/HTML_NUMBER/${html_number}/g" "/etc/v2ray/pages/index.html"
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}配置网页电话号成功。"
else
clear
echo -e "${error_font}配置网页电话号失败!"
clear_install
exit 1
fi
sed -i "s/V2rayAddress/${install_domain}/g" "/etc/v2ray/pages/index.html"
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}配置网页域名成功。"
else
clear
echo -e "${error_font}配置网页域名失败!"
clear_install
exit 1
fi
fi
echo "8" > /etc/v2ray/install_type.txt
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}写入安装信息成功。"
else
clear
echo -e "${error_font}写入安装信息失败!"
clear_install
exit 1
fi
cd /root/
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}返回root文件夹成功。"
else
clear
echo -e "${error_font}返回root文件夹失败!"
clear_install
exit 1
fi
restart_service
echo_v2ray_config
fi
echo -e "\n${ok_font}请求处理完毕。"
}
function uninstall_old(){
clear
echo -e "正在检查安装信息中..."
clear
if [[ ${v2ray_status} = "${red_fontcolor}未安装${default_fontcolor}" ]]; then
clear
echo -e "${error_font}您未安装V2Ray。"
else
service v2ray stop
update-rc.d -f v2ray remove
systemctl disable v2ray.service
rm -rf /etc/init.d/v2ray
rm -rf /lib/systemd/system/v2ray.service
rm -rf /etc/systemd/system/v2ray.service
rm -rf /etc/v2ray
rm -rf /usr/bin/v2ray
rm -rf /var/log/v2ray
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}V2Ray卸载成功。"
else
clear
echo -e "${error_font}V2Ray卸载失败!"
fi
fi
clear
stty erase '^H' && read -p "您是否需要卸载Caddy?[Y/N,Default:N]" uninstall_caddy_right
if [[ ${uninstall_caddy_right} == [Yy] ]]; then
if [[ ${caddy_status} = "${red_fontcolor}未安装${default_fontcolor}" ]]; then
clear
echo -e "${error_font}您未安装Caddy。"
else
service caddy stop
update-rc.d -f caddy remove
rm -rf /etc/init.d/caddy
rm -rf /root/.caddy
rm -rf /usr/local/caddy
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}Caddy卸载成功。"
else
clear
echo -e "${error_font}Caddy卸载失败!"
fi
fi
else
clear
echo -e "${ok_font}取消卸载Caddy成功。"
fi
}
function upgrade_shell_script(){
clear
echo -e "正在更新脚本中..."
filepath=$(cd "$(dirname "$0")"; pwd)
filename=$(echo -e "${filepath}"|awk -F "$0" '{print $1}')
curl -O https://raw.githubusercontent.com/1715173329/v2ray-onekey/master/v2ray-go.sh
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}脚本更新成功,脚本位置:\"${green_backgroundcolor}${filename}/v2ray-go.sh${default_fontcolor}\",使用:\"${green_backgroundcolor}bash ${filename}/v2ray-go.sh${default_fontcolor}\"。"
else
clear
echo -e "${error_font}脚本更新失败!"
fi
}
function prevent_uninstall_check(){
clear
echo -e "正在检查安装状态中..."
install_type=$(cat /etc/v2ray/install_type.txt)
if [ "${install_type}" = "" ]; then
clear
echo -e "${error_font}您未安装本程序。"
exit 1
else
echo -e "${ok_font}您已安装本程序,正在执行相关命令中..."
fi
}
function start_service(){
clear
echo -e "正在启动服务中..."
install_type=$(cat /etc/v2ray/install_type.txt)
if [ "${install_type}" -lt "8" ]; then
if [[ ${v2ray_pid} -eq 0 ]]; then
service v2ray start
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}V2Ray 启动成功。"
exit 0
else
clear
echo -e "${error_font}V2Ray 启动失败!"
exit 1
fi
else
clear
echo -e "${error_font}V2Ray 正在运行。"
exit 1
fi
else
if [[ ${v2ray_pid} -eq 0 ]]; then
service v2ray start
if [[ $? -eq 0 ]];then
clear
echo -e "${ok_font}V2Ray 启动成功。"
else
clear
echo -e "${error_font}V2Ray 启动失败!"
fi
else
clear
echo -e "${error_font}V2Ray 正在运行。"
fi
if [[ ${caddy_pid} -eq 0 ]]; then
service caddy start
if [[ $? -eq 0 ]];then
echo -e "${ok_font}Caddy 启动成功。"
exit 0
else
echo -e "${error_font}Caddy 启动失败!"
exit 1
fi
else
echo -e "${error_font}Caddy 正在运行。"
exit 1
fi
fi
}
function stop_service(){
clear
echo -e "正在停止服务中..."
install_type=$(cat /etc/v2ray/install_type.txt)
if [ "${install_type}" -lt "8" ]; then