-
Notifications
You must be signed in to change notification settings - Fork 360
/
ss-plugins.sh
1584 lines (1406 loc) · 42.4 KB
/
ss-plugins.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
#!/usr/bin/env bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
# shell version
# ====================
SHELL_VERSION="2.8.4"
# ====================
# current path
CUR_DIR=$( pwd )
# base url
methods="Online"
BASE_URL="https://github.com/loyess/Shell/raw/master"
if [ -e install ] && [ -e prepare ] && [ -e service ] && [ -e templates ] && [ -e utils ] && [ -e webServer ]; then
methods="Local"
BASE_URL="${CUR_DIR}"
fi
# bbr
TEDDYSUN_BBR_SCRIPT_URL="https://raw.githubusercontent.com/teddysun/across/master/bbr.sh"
# Humanization config PATH
HUMAN_CONFIG="/etc/shadowsocks/humanization.conf"
# script env dir
SS_PLUGINS_SCRIPT_ENV_DIR="/root/.ssPluginsScriptEnv"
SS_PLUGINS_SCRIPT_ENV_VARIABLES_FILE="${SS_PLUGINS_SCRIPT_ENV_DIR}/env.info"
# shadowsocks config
SHADOWSOCKS_CONFIG="/etc/shadowsocks/config.json"
# shadowsocks-libev config and init
SHADOWSOCKS_LIBEV_INSTALL_PATH="/usr/local/bin"
SHADOWSOCKS_LIBEV_BIN_PATH="/usr/local/bin/ss-server"
SHADOWSOCKS_LIBEV_INIT="/etc/init.d/shadowsocks-libev"
SHADOWSOCKS_LIBEV_INIT_LOCAL="./service/shadowsocks-libev.sh"
SHADOWSOCKS_LIBEV_INIT_ONLINE="${BASE_URL}/service/shadowsocks-libev.sh"
# shadowsocks-rust config and init
SHADOWSOCKS_RUST_INSTALL_PATH="/usr/local/bin"
SHADOWSOCKS_RUST_BIN_PATH="/usr/local/bin/ssservice"
SHADOWSOCKS_RUST_INIT="/etc/init.d/shadowsocks-rust"
SHADOWSOCKS_RUST_INIT_LOCAL="./service/shadowsocks-rust.sh"
SHADOWSOCKS_RUST_INIT_ONLINE="${BASE_URL}/service/shadowsocks-rust.sh"
# go-shadowsocks2 config and init
GO_SHADOWSOCKS2_INSTALL_PATH="/usr/local/bin"
GO_SHADOWSOCKS2_BIN_PATH="/usr/local/bin/go-shadowsocks2"
GO_SHADOWSOCKS2_INIT="/etc/init.d/go-shadowsocks2"
GO_SHADOWSOCKS2_INIT_LOCAL="./service/go-shadowsocks2.sh"
GO_SHADOWSOCKS2_INIT_ONLINE="${BASE_URL}/service/go-shadowsocks2.sh"
GO_SHADOWSOCKS2_VERSION_FILE="/etc/shadowsocks/go-shadowsocks2.v"
# v2ray-plugin
V2RAY_PLUGIN_INSTALL_PATH="/usr/local/bin"
V2RAY_PLUGIN_BIN_PATH="/usr/local/bin/v2ray-plugin"
# kcptun
KCPTUN_INSTALL_PATH="/usr/local/kcptun"
KCPTUN_BIN_PATH="/usr/local/kcptun/kcptun-server"
KCPTUN_INIT="/etc/init.d/kcptun"
KCPTUN_CONFIG="/etc/kcptun/config.json"
KCPTUN_INIT_LOCAL="./service/kcptun.sh"
KCPTUN_INIT_ONLINE="${BASE_URL}/service/kcptun.sh"
# simple-obfs
SIMPLE_OBFS_INSTALL_PATH="/usr/local/bin"
SIMPLE_OBFS_BIN_PATH="/usr/local/bin/obfs-server"
# goquiet
GOQUIET_INSTALL_PATH="/usr/local/bin"
GOQUIET_BIN_PATH="/usr/local/bin/gq-server"
# cloak
CLOAK_INSTALL_PATH="/usr/local/bin"
CLOAK_SERVER_BIN_PATH="/usr/local/bin/ck-server"
CLOAK_CLIENT_BIN_PATH="/usr/local/bin/ck-client"
CLOAK_INIT="/etc/init.d/cloak"
CLOAK_INIT_LOCAL="./service/cloak.sh"
CLOAK_INIT_ONLINE="${BASE_URL}/service/cloak.sh"
CK_DB_PATH="/etc/cloak"
CK_CLIENT_CONFIG="/etc/cloak/ckclient.json"
CK_SERVER_CONFIG="/etc/cloak/ckserver.json"
# mos-tls-tunnel
MTT_VERSION_FILE="/etc/shadowsocks/mtt.v"
MTT_INSTALL_PATH="/usr/local/bin"
MTT_BIN_PATH="/usr/local/bin/mtt-server"
# rabbit-tcp
RABBIT_INSTALL_PATH="/usr/local/bin"
RABBIT_BIN_PATH="/usr/local/bin/rabbit-tcp"
RABBIT_INIT="/etc/init.d/rabbit-tcp"
RABBIT_CONFIG="/etc/rabbit-tcp/config.json"
RABBIT_VERSION_FILE="/etc/rabbit-tcp/rabbit-tcp.v"
RABBIT_INIT_LOCAL="./service/rabbit-tcp.sh"
RABBIT_INIT_ONLINE="${BASE_URL}/service/rabbit-tcp.sh"
# simple-tls
SIMPLE_TLS_INSTALL_PATH="/usr/local/bin"
SIMPLE_TLS_BIN_PATH="/usr/local/bin/simple-tls"
SIMPLE_TLS_VERSION_FILE="/etc/shadowsocks/simple-tls.v"
# gost-plugin
GOST_PLUGIN_INSTALL_PATH="/usr/local/bin"
GOST_PLUGIN_BIN_PATH="/usr/local/bin/gost-plugin"
GOST_PLUGIN_VERSION_FILE="/etc/shadowsocks/gost-plugin.v"
# xray-plugin
XRAY_PLUGIN_INSTALL_PATH="/usr/local/bin"
XRAY_PLUGIN_BIN_PATH="/usr/local/bin/xray-plugin"
XRAY_PLUGIN_VERSION_FILE="/etc/shadowsocks/xray-plugin.v"
# qtun
QTUN_INSTALL_PATH="/usr/local/bin"
QTUN_BIN_PATH="/usr/local/bin/qtun-server"
QTUN_VERSION_FILE="/etc/shadowsocks/qtun.v"
# gun
GUN_INSTALL_PATH="/usr/local/bin"
GUN_BIN_PATH="/usr/local/bin/gun-server"
GUN_VERSION_FILE="/etc/shadowsocks/gun.v"
SS_PLUGINS_NAME=(
v2ray-plugin
kcptun
simple-obfs
goquiet
cloak
mos-tls-tunnel
rabbit-tcp
simple-tls
gost-plugin
xray-plugin
qtun
gun
)
# file exist:install
WEB_INSTALL_MARK="/root/.WebInstallMark"
# caddy
CADDY_INSTALL_PATH="/usr/local/caddy"
CADDY_BIN_PATH="/usr/local/caddy/caddy"
CADDY_CONF_FILE="/usr/local/caddy/Caddyfile"
CADDY_VERSION_FILE="/usr/local/caddy/caddy.v"
CADDY_INIT="/etc/init.d/caddy"
CADDY_INIT_LOCAL="./service/caddy.sh"
CADDY_INIT_ONLINE="${BASE_URL}/service/caddy.sh"
CADDY_V2_INIT_LOCAL="./service/caddy2.sh"
CADDY_V2_INIT_ONLINE="${BASE_URL}/service/caddy2.sh"
# nginx
NGINX_BIN_PATH="/usr/sbin/nginx"
NGINX_CONFIG="/etc/nginx/nginx.conf"
# RE
EMAIL_RE="^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}$"
DOMAIN_RE="^(www\.)?[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+(:\d+)*(\/\w+\.\w+)*$"
IPV4_RE="^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])$"
IPV4_PORT_RE="^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\:443$"
HTTPS_DOMAIN_RE="^(https:\/\/)?(www\.)?[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+(:\d+)*(\/\w+\.\w+)*$"
IPV6_RE="^\s*((([0-9A-Fa-f]{1,4}:){7}(([0-9A-Fa-f]{1,4})|:))|(([0-9A-Fa-f]{1,4}:){6}(:|((25[0-5]|2[0-4]\d|[01]?\d{1,2})(\.(25[0-5]|2[0-4]\d|[01]?\d{1,2})){3})|(:[0-9A-Fa-f]{1,4})))|(([0-9A-Fa-f]{1,4}:){5}((:((25[0-5]|2[0-4]\d|[01]?\d{1,2})(\.(25[0-5]|2[0-4]\d|[01]?\d{1,2})){3})?)|((:[0-9A-Fa-f]{1,4}){1,2})))|(([0-9A-Fa-f]{1,4}:){4}(:[0-9A-Fa-f]{1,4}){0,1}((:((25[0-5]|2[0-4]\d|[01]?\d{1,2})(\.(25[0-5]|2[0-4]\d|[01]?\d{1,2})){3})?)|((:[0-9A-Fa-f]{1,4}){1,2})))|(([0-9A-Fa-f]{1,4}:){3}(:[0-9A-Fa-f]{1,4}){0,2}((:((25[0-5]|2[0-4]\d|[01]?\d{1,2})(\.(25[0-5]|2[0-4]\d|[01]?\d{1,2})){3})?)|((:[0-9A-Fa-f]{1,4}){1,2})))|(([0-9A-Fa-f]{1,4}:){2}(:[0-9A-Fa-f]{1,4}){0,3}((:((25[0-5]|2[0-4]\d|[01]?\d{1,2})(\.(25[0-5]|2[0-4]\d|[01]?\d{1,2})){3})?)|((:[0-9A-Fa-f]{1,4}){1,2})))|(([0-9A-Fa-f]{1,4}:)(:[0-9A-Fa-f]{1,4}){0,4}((:((25[0-5]|2[0-4]\d|[01]?\d{1,2})(\.(25[0-5]|2[0-4]\d|[01]?\d{1,2})){3})?)|((:[0-9A-Fa-f]{1,4}){1,2})))|(:(:[0-9A-Fa-f]{1,4}){0,5}((:((25[0-5]|2[0-4]\d|[01]?\d{1,2})(\.(25[0-5]|2[0-4]\d|[01]?\d{1,2})){3})?)|((:[0-9A-Fa-f]{1,4}){1,2})))|(((25[0-5]|2[0-4]\d|[01]?\d{1,2})(\.(25[0-5]|2[0-4]\d|[01]?\d{1,2})){3})))(%.+)?\s*$"
# Font color and background color
Green="\033[32m" && Red="\033[31m" && Yellow="\033[0;33m" && Green_background_prefix="\033[42;37m" && Red_background_prefix="\033[41;37m" && suffix="\033[0m"
Info="${Green}[信息]${suffix}"
Error="${Red}[错误]${suffix}"
Point="${Red}[提示]${suffix}"
Tip="${Green}[注意]${suffix}"
Warning="${Yellow}[警告]${suffix}"
Separator_1="——————————————————————————————"
# Root permission
[ $EUID -ne 0 ] && echo -e "[${Red}Error${suffix}] This script must be run as root!" && exit 1
usage() {
echo "Usage:"
echo " ./ss-plugins.sh [options...] [args...]"
echo
echo "Available Options:"
echo " install 安装"
echo " uninstall 卸载"
echo " update 升级"
echo " start 启动"
echo " stop 关闭"
echo " restart 重启"
echo " status 查看状态"
echo " script 升级脚本"
echo " show 可视化配置"
echo " log 查看日志文件"
echo " catcfg 查看原始配置文件"
echo " uid 添加一个新的uid用户(Cloak)"
echo " cert 为.cf .ga .gq .ml .tk申请证书(90天)"
echo " link 用新添加的uid生成一个新的SS://链接(Cloak)"
echo " scan 用ss://链接在当前终端上生成一个可供扫描的二维码"
echo " help 打印帮助信息并退出"
exit $1
}
_echo(){
case $1 in
-u|upon)
echo
echo -e "${2}"
;;
-d|down)
echo -e "${2}"
echo
;;
-r|red)
echo
echo -e "${Red}${2}${suffix}"
echo
;;
-g|green)
echo
echo -e "${Green}${2}${suffix}"
echo
;;
-i|info)
echo -e "${Info} ${2}"
;;
-e|error)
echo -e "${Error} ${2}"
;;
-t|tip)
echo
echo -e "${Tip} ${2}"
echo
;;
-w|warning)
echo -e "${Warning} ${2}"
;;
*)
echo
echo -e "${1}"
echo
;;
esac
}
_read(){
case $1 in
-u|upon)
echo
read -e -p "${2}" inputInfo
;;
-d|down)
read -e -p "${2}" inputInfo
echo
;;
*)
echo
read -e -p "${1}" inputInfo
echo
;;
esac
}
status_init(){
if [ -e "${SHADOWSOCKS_LIBEV_BIN_PATH}" ]; then
ssName="Shadowsocks-libev"
ssPath="${SHADOWSOCKS_LIBEV_BIN_PATH}"
ssPid=`ps -ef | grep -v grep | grep $SHADOWSOCKS_LIBEV_BIN_PATH | awk '{print $2}'`
elif [ -e "${SHADOWSOCKS_RUST_BIN_PATH}" ]; then
ssName="Shadowsocks-rust"
ssPath="${SHADOWSOCKS_RUST_BIN_PATH}"
ssPid=`ps -ef | grep -v grep | grep $SHADOWSOCKS_RUST_BIN_PATH | awk '{print $2}'`
elif [ -e "${GO_SHADOWSOCKS2_BIN_PATH}" ]; then
ssName="Go-shadowsocks2"
ssPath="${GO_SHADOWSOCKS2_BIN_PATH}"
ssPid=`ps -ef | grep -v grep | grep $GO_SHADOWSOCKS2_BIN_PATH | awk '{print $2}'`
fi
if [ -e "${V2RAY_PLUGIN_BIN_PATH}" ]; then
pluginName="V2ray-plugin"
pluginPath="${V2RAY_PLUGIN_BIN_PATH}"
pluginPid=`ps -ef | grep -vE 'grep|-plugin-opts' | grep v2ray-plugin | awk '{print $2}'`
elif [ -e "${KCPTUN_BIN_PATH}" ]; then
pluginName="KcpTun"
pluginPath="${KCPTUN_BIN_PATH}"
pluginPid=`ps -ef | grep -vE 'grep|-plugin-opts' | grep kcptun-server | awk '{print $2}'`
elif [ -e "${SIMPLE_OBFS_BIN_PATH}" ]; then
pluginName="Simple-obfs"
pluginPath="${SIMPLE_OBFS_BIN_PATH}"
pluginPid=`ps -ef | grep -vE 'grep|-plugin-opts' | grep obfs-server | awk '{print $2}'`
elif [ -e "${GOQUIET_BIN_PATH}" ]; then
pluginName="GoQuiet"
pluginPath="${GOQUIET_BIN_PATH}"
pluginPid=`ps -ef | grep -vE 'grep|-plugin-opts' | grep gq-server | awk '{print $2}'`
elif [ -e "${CLOAK_SERVER_BIN_PATH}" ]; then
pluginName="Cloak"
pluginPath="${CLOAK_SERVER_BIN_PATH}"
pluginPid=`ps -ef | grep -vE 'grep|-plugin-opts' | grep ck-server | awk '{print $2}'`
elif [ -e "${MTT_BIN_PATH}" ]; then
pluginName="Mos-tls-tunnel"
pluginPath="${MTT_BIN_PATH}"
pluginPid=`ps -ef | grep -vE 'grep|-plugin-opts' | grep mtt-server | awk '{print $2}'`
elif [ -e "${RABBIT_BIN_PATH}" ]; then
pluginName="Rabbit-Tcp"
pluginPath="${RABBIT_BIN_PATH}"
pluginPid=`ps -ef | grep -vE 'grep|-plugin-opts' | grep rabbit-tcp | awk '{print $2}'`
elif [ -e "${SIMPLE_TLS_BIN_PATH}" ]; then
pluginName="Simple-tls"
pluginPath="${SIMPLE_TLS_BIN_PATH}"
pluginPid=`ps -ef | grep -vE 'grep|-plugin-opts' | grep simple-tls | awk '{print $2}'`
elif [ -e "${GOST_PLUGIN_BIN_PATH}" ]; then
pluginName="Gost-plugin"
pluginPath="${GOST_PLUGIN_BIN_PATH}"
pluginPid=`ps -ef | grep -vE 'grep|-plugin-opts' | grep gost-plugin | awk '{print $2}'`
elif [ -e "${XRAY_PLUGIN_BIN_PATH}" ]; then
pluginName="Xray-plugin"
pluginPath="${XRAY_PLUGIN_BIN_PATH}"
pluginPid=`ps -ef | grep -vE 'grep|-plugin-opts' | grep xray-plugin | awk '{print $2}'`
elif [ -e "${QTUN_BIN_PATH}" ]; then
pluginName="qtun"
pluginPath="${QTUN_BIN_PATH}"
pluginPid=`ps -ef | grep -vE 'grep|-plugin-opts' | grep qtun-server | awk '{print $2}'`
elif [ -e "${GUN_BIN_PATH}" ]; then
pluginName="gun"
pluginPath="${GUN_BIN_PATH}"
pluginPid=`ps -ef | grep -vE 'grep|-plugin-opts' | grep gun-server | awk '{print $2}'`
fi
if [ -e "${CADDY_BIN_PATH}" ] && [ -e "${WEB_INSTALL_MARK}" ]; then
webName="Caddy"
webPath="${CADDY_BIN_PATH}"
webPid=`ps -ef | grep -vE 'grep|-plugin-opts' | grep caddy | awk '{print $2}'`
elif [ -e "${NGINX_BIN_PATH}" ] && [ -e "${WEB_INSTALL_MARK}" ]; then
webName="Nginx"
webPath="${NGINX_BIN_PATH}"
webPid=`ps -ef | grep -vE 'grep|-plugin-opts' | grep nginx.conf | awk '{print $2}'`
fi
}
status_menu(){
local NoInstall=" 当前状态: ${Red}未安装${suffix}"
local InstallStart=" 当前状态: ${Green}已安装${suffix} 并 ${Green}已启动${suffix}"
local InstallNoStart=" 当前状态: ${Green}已安装${suffix} 但 ${Red}未启动${suffix}"
status_init
if [ -e "${ssPath}" ] && [ -e "${pluginPath}" ] && [ -e "${webPath}" ]; then
if [ -n "${ssPid}" ] && [ -n "${pluginPid}" ] && [ -n "${webPid}" ]; then
echo -e "${InstallStart}"
else
echo -e "${InstallNoStart}"
fi
elif [ -e "${ssPath}" ] && [ -e "${pluginPath}" ]; then
if [ -n "${ssPid}" ] && [ -n "${pluginPid}" ]; then
echo -e "${InstallStart}"
else
echo -e "${InstallNoStart}"
fi
elif [ -e "${ssPath}" ]; then
if [ -n "${ssPid}" ]; then
echo -e "${InstallStart}"
else
echo -e "${InstallNoStart}"
fi
else
echo -e "${NoInstall}"
fi
}
check_sys(){
local checkType=$1
local value=$2
local release=''
local systemPackage=''
if [ -f /etc/redhat-release ]; then
release="centos"
systemPackage="yum"
elif grep -Eqi "debian|raspbian" /etc/issue; then
release="debian"
systemPackage="apt"
elif grep -Eqi "ubuntu" /etc/issue; then
release="ubuntu"
systemPackage="apt"
elif grep -Eqi "centos|red hat|redhat" /etc/issue; then
release="centos"
systemPackage="yum"
elif grep -Eqi "debian|raspbian" /proc/version; then
release="debian"
systemPackage="apt"
elif grep -Eqi "ubuntu" /proc/version; then
release="ubuntu"
systemPackage="apt"
elif grep -Eqi "centos|red hat|redhat" /proc/version; then
release="centos"
systemPackage="yum"
fi
if [ "${checkType}" == "sysRelease" ]; then
if [ "${value}" == "${release}" ]; then
return 0
else
return 1
fi
elif [ "${checkType}" == "packageManager" ]; then
if [ "${value}" == "${systemPackage}" ]; then
return 0
else
return 1
fi
fi
}
check_arch(){
case "$(uname -m)" in
'amd64' | 'x86_64')
ARCH='amd64'
;;
'armv8' | 'aarch64')
ARCH='arm64'
;;
*)
echo "[${Red}Error${suffix}] The architecture is not supported."
exit 1
;;
esac
}
package_install(){
local package_name=$1
if check_sys packageManager yum; then
yum install -y $1 > /dev/null 2>&1
if [ $? -ne 0 ]; then
_echo -e "安装 $1 失败."
exit 1
fi
elif check_sys packageManager apt; then
apt-get -y update > /dev/null 2>&1
apt-get -y install $1 > /dev/null 2>&1
if [ $? -ne 0 ]; then
_echo -e "安装 $1 失败."
exit 1
fi
fi
_echo -i "$1 安装完成."
}
improt_package(){
local package=$1
local sh_file=$2
if [ ! "$(command -v curl)" ]; then
package_install "curl" > /dev/null 2>&1
fi
if [ "${methods}" = "Online" ]; then
source <(curl -sL "${BASE_URL}/${package}/${sh_file}")
else
cd "${CUR_DIR}"
source "${BASE_URL}/${package}/${sh_file}"
fi
}
disable_selinux(){
if [ -s /etc/selinux/config ] && grep -q 'SELINUX=enforcing' /etc/selinux/config; then
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
fi
}
install_check(){
if check_sys packageManager yum || check_sys packageManager apt; then
if centosversion 5; then
return 1
fi
return 0
else
return 1
fi
}
is_ipv4_or_ipv6(){
ip=$1
if [ -n "$(echo $ip | grep -E $IPV4_RE)" ] || [ -n "$(echo $ip | grep -E $IPV6_RE)" ]; then
return 0
else
return 1
fi
}
version_ge(){
test "$(echo "$@" | tr " " "\n" | sort -rV | head -n 1)" == "$1"
}
version_gt(){
test "$(echo "$@" | tr " " "\n" | sort -V | head -n 1)" != "$1"
}
check_latest_version(){
local current_v=$1
local latest_v=$2
if version_gt "${latest_v}" "${current_v}"; then
return 0
else
return 1
fi
}
check_port_occupy(){
local port=$1
if [ ! "$(command -v lsof)" ]; then
package_install "lsof" > /dev/null 2>&1
fi
if [ `lsof -i:"${port}" | grep -v google_ | grep -v COMMAND | wc -l` -ne 0 ];then
# Occupied
return 0
else
# Unoccupied
return 1
fi
}
kill_process_if_port_occupy(){
local port=$1
while true
do
if ! check_port_occupy "${port}"; then
break
fi
_echo -g "占用${port}端口的进程信息如下: "
lsof -i:"${port}"
_read "检测到${port}端口被占用,是否kill此进程(默认: n) [y/n]: "
local yn="${inputInfo}"
[ -z "${yn}" ] && yn="N"
case "${yn:0:1}" in
y|Y)
lsof -i:"${port}" | grep -v grep | grep "${port}" | awk '{print $2}' | xargs kill -9 > /dev/null 2>&1
_echo -t "占用${port}端口的进程已被杀死."
break
;;
n|N)
_echo -e "端口${port}被占用,终止运行."
exit 1
;;
*)
_echo -e "输入有误,请重新输入!"
continue
;;
esac
done
}
reset_if_ss_port_is_443(){
while true
do
if [ "${shadowsocksport}" -ne 443 ]; then
break
fi
gen_random_prot
if check_port_occupy "${ran_prot}"; then
continue
fi
shadowsocksport="${ran_prot}"
break
done
}
check_script_update(){
local isShow="${1:-"show"}"
SHELL_VERSION_NEW=$(wget --no-check-certificate -qO- "https://git.io/fjlbl"|grep 'SHELL_VERSION="'|awk -F "=" '{print $NF}'|sed 's/\"//g'|head -1)
[ -z "${SHELL_VERSION_NEW}" ] && _echo -e "无法链接到 Github !" && exit 0
if version_gt "${SHELL_VERSION_NEW}" "${SHELL_VERSION}"; then
_echo -u "${Green}当前脚本版本为:${SHELL_VERSION} 检测到有新版本可更新.${suffix}"
_echo -d "按任意键开始…或按Ctrl+C取消"
char=`get_char`
wget -N --no-check-certificate -O ss-plugins.sh "https://git.io/fjlbl" && chmod +x ss-plugins.sh
echo -e "脚本已更新为最新版本[ ${SHELL_VERSION_NEW} ] !(注意:因为更新方式为直接覆盖当前运行的脚本,所以可能下面会提示一些报错,无视即可)" && exit 0
else
if [ "${isShow}" = "show" ]; then
_echo -i "当前脚本版本为: ${SHELL_VERSION} 未检测到更新版本."
fi
fi
}
url_encode() {
local length="${#1}"
for (( i = 0; i < length; i++ )); do
local c="${1:i:1}"
case $c in
[a-zA-Z0-9.~_-])
printf "%s" "$c"
;;
*)
printf "%%%02X" "'$c"
;;
esac
done
}
get_ip(){
local IP=$( ip addr | egrep -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | egrep -v "^192\.168|^172\.1[6-9]\.|^172\.2[0-9]\.|^172\.3[0-2]\.|^10\.|^127\.|^255\.|^0\." | head -n 1 )
[ -z "${IP}" ] && IP=$( wget -qO- -t1 -T2 ipv4.icanhazip.com )
[ -z "${IP}" ] && IP=$( wget -qO- -t1 -T2 ipinfo.io/ip )
echo "${IP}"
}
get_ipv6(){
local ipv6=$(wget -qO- -t1 -T2 ipv6.icanhazip.com)
[ -z "${ipv6}" ] && return 1 || return 0
}
get_char(){
SAVEDSTTY=$(stty -g)
stty -echo
stty cbreak
dd if=/dev/tty bs=1 count=1 2> /dev/null
stty -raw
stty echo
stty $SAVEDSTTY
}
get_domain_ip(){
local domain=$1
local ipv4Re="((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])"
if [ ! "$(command -v nslookup)" ]; then
if check_sys packageManager yum; then
package_install "bind-utils" > /dev/null 2>&1
elif check_sys packageManager apt; then
package_install "dnsutils" > /dev/null 2>&1
fi
fi
domain_ip=`nslookup ${domain} | grep -E 'Name:' -A 1 | grep -oE $ipv4Re | tail -1`
if [ -n "${domain_ip}" ]; then
return 0
else
return 1
fi
}
get_str_base64_encode(){
echo -n $1 | base64 -w0
}
gen_random_prot(){
ran_prot="$(shuf -i 9000-19999 -n 1)"
}
gen_random_str(){
ran_str5="$(head -c 100 /dev/urandom | tr -dc a-z0-9A-Z | head -c 5)"
ran_str12="$(head -c 100 /dev/urandom | tr -dc a-z0-9A-Z | head -c 12)"
}
gen_credentials(){
while true
do
ckauid=$(ck-server -u)
IFS=, read ckpub ckpv <<< $(ck-server -k)
# filter "+" from ckauid and ckpub
if [[ $(echo ${ckauid} | grep "+") || $(echo ${ckpub} | grep "+") ]]; then
continue
fi
break
done
}
get_version(){
if [ -s /etc/redhat-release ]; then
grep -oE "[0-9.]+" /etc/redhat-release
else
grep -oE "[0-9.]+" /etc/issue
fi
}
get_env_variable(){
local varName=$1
local keyValuePair
if [ -e "${SS_PLUGINS_SCRIPT_ENV_VARIABLES_FILE}" ]; then
keyValuePair=$(grep "${varName}" "${SS_PLUGINS_SCRIPT_ENV_VARIABLES_FILE}")
[ -n "${keyValuePair}" ] && export "${keyValuePair}" && return 0
else
return 1
fi
}
write_env_variable(){
local keyValuePairText=$1
[ ! -e "${SS_PLUGINS_SCRIPT_ENV_DIR}" ] && mkdir -p "${SS_PLUGINS_SCRIPT_ENV_DIR}"
echo "${keyValuePairText}" >> "${SS_PLUGINS_SCRIPT_ENV_VARIABLES_FILE}"
}
centosversion(){
if check_sys sysRelease centos; then
local code=$1
local version="$(get_version)"
local main_ver="${version%%.*}"
if [ "$main_ver" == "$code" ]; then
return 0
else
return 1
fi
else
return 1
fi
}
judge_is_num(){
local aNum=$1
expr "${aNum}" + 1 &>/dev/null
if [ $? -ne 0 ]; then
return 1
else
return 0
fi
}
judge_is_zero_begin_num(){
local aNum=$1
if [ "${aNum:0:1}" = 0 ]; then
return 0
else
return 1
fi
}
judge_is_equal_num(){
local numOne=$1
local numTwo=$2
if [ "${numOne}" -eq "${numTwo}" ]; then
return 0
else
return 1
fi
}
judge_num_in_range(){
local aNum=$1
local maxNum=$2
if [ "${aNum}" -lt 1 ] || [ "${aNum}" -gt "${maxNum}" ]; then
return 1
else
return 0
fi
}
judge_is_nul_str(){
local str=$1
if [ -z "${str}" ]; then
return 0
else
return 1
fi
}
judge_is_domain(){
local domain=$1
if [ -z "$(echo ${domain} | grep -E ${DOMAIN_RE})" ]; then
return 1
else
return 0
fi
}
judge_is_valid_domain(){
local domain=$1
if judge_is_https_begin_site "${domain}"; then
domain=$(echo ${domain} | sed 's/https:\/\///g')
fi
if get_domain_ip "${domain}"; then
return 0
else
return 1
fi
}
judge_is_ip_colon_port_format(){
# Match: ip:443 format
local ipColonPort=$1
if [ -z "$(echo ${ipColonPort} | grep -E ${IPV4_PORT_RE})" ]; then
return 1
else
return 0
fi
}
judge_is_path(){
local path=$1
if [ -z "$(echo ${path} | grep -E '^\/(\w+\/?)+$')" ]; then
return 1
else
return 0
fi
}
judge_is_https_begin_site(){
local domainWithProtocolHeader=$1
if [ -z "$(echo ${domainWithProtocolHeader} | grep -E ${HTTPS_DOMAIN_RE})" ]; then
return 1
else
return 0
fi
}
judge_domain_type(){
local ip=$1
if is_cdn_proxied "${ip}"; then
echo "CDN"
elif is_dns_only "${ip}"; then
echo "DNS-Only"
else
echo "Other"
fi
}
generate_menu(){
local aArray=($1)
local num=$2
local hint
for ((i=1;i<="${#aArray[@]}";i++ )); do
hint="${aArray[$i-1]}"
if [ "${i}" -le 9 ]; then
echo -e "${Green} ${i}.${suffix} ${hint}"
else
echo -e "${Green} ${i}.${suffix} ${hint}"
fi
done
_read "(默认: ${aArray[${num}-1]}):"
}
generate_menu_logic(){
# global var: inputInfo, optionValue
local aArray=($1)
local tipText=$2
local defualtOptNum=$3
local arrayLong="${#aArray[@]}"
while true
do
_echo "请选择${tipText}:"
generate_menu "${aArray[*]}" "${defualtOptNum}"
[ -z "${inputInfo}" ] && inputInfo="${defualtOptNum}"
if ! judge_is_num "${inputInfo}"; then
_echo -e "请输入一个数字."
continue
fi
if ! judge_num_in_range "${inputInfo}" "${arrayLong}"; then
_echo -e "请输入一个数字在 [1-${arrayLong}] 之间"
continue
fi
optionValue="${aArray[$inputInfo-1]}"
_echo -r " selected = ${optionValue}"
break
done
}
config_ss(){
local ipv6First="false"
local server_value="\"0.0.0.0\""
if get_ipv6; then
local ssVer="${SS_VERSION}"
local pluginNum="${plugin_num}"
if [ "${ssVer}" = "ss-libev" ]; then
server_value="[\"[::0]\",\"0.0.0.0\"]"
case "${pluginNum}" in
8|9|12)
server_value="\"0.0.0.0\""
;;
esac
elif [ "${ssVer}" = "ss-rust" ]; then
server_value="\"::\""
case "${pluginNum}" in
3)
server_value="\"0.0.0.0\""
;;
esac
fi
case "${pluginNum}" in
4|6|7)
server_value="\"0.0.0.0\""
;;
esac
if [ "${server_value}" != "\"0.0.0.0\"" ]; then
ipv6First="true"
fi
fi
if [ ! -d "$(dirname ${SHADOWSOCKS_CONFIG})" ]; then
mkdir -p $(dirname ${SHADOWSOCKS_CONFIG})
fi
case "${plugin_num}" in
1)
improt_package "templates/config" "v2ray_plugin_config.sh"
config_ss_v2ray_plugin
;;
2)
improt_package "templates/config" "kcptun_config.sh"
config_ss_kcptun
;;
3)
improt_package "templates/config" "simple_obfs_config.sh"
config_ss_simple_obfs
;;
4)
improt_package "templates/config" "goquiet_config.sh"
config_ss_goquiet
;;
5)
improt_package "templates/config" "cloak_config.sh"
config_ss_cloak
;;
6)
improt_package "templates/config" "mos_tls_tunnel_config.sh"
config_ss_mos_tls_tunnel
;;
7)
improt_package "templates/config" "rabbit_tcp_config.sh"
config_ss_rabbit_tcp
;;
8)
improt_package "templates/config" "simple_tls_config.sh"
config_ss_simple_tls
;;
9)
improt_package "templates/config" "gost_plugin_config.sh"
config_ss_gost_plugin
;;
10)
improt_package "templates/config" "xray_plugin_config.sh"
config_ss_xray_plugin
;;
11)
improt_package "templates/config" "qtun_config.sh"
config_ss_qtun
;;
12)
improt_package "templates/config" "gun_config.sh"
config_ss_gun
;;
*)
ss_server_config
;;
esac
}
config_webserver(){
case "${web_flag}" in
1)
improt_package "webServer" "caddy_config.sh"