forked from loyess/Shell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathss-plugins.sh
1448 lines (1255 loc) · 46.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.3.3"
# ====================
# current path
CUR_DIR=$( pwd )
# base url
methods="Online"
BASE_URL="https://github.com/loyess/Shell/raw/master"
if [ -e plugins ] && [ -e prepare ] && [ -e service ] && [ -e templates ] && [ -e tools ] && [ -e utils ]; then
methods="Local"
BASE_URL="."
fi
# bbr
TEDDYSUN_BBR_SCRIPT_URL="https://git.io/vbUk0"
CHIAKGE_BBR_SCRIPT_URL="https://git.io/vxJ1I"
# Humanization config PATH
HUMAN_CONFIG="/etc/shadowsocks/humanization.conf"
# ss development language version
SS_DLV=(
ss-libev
ss-rust
)
# 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_CENTOS="${BASE_URL}/service/shadowsocks-libev_centos.sh"
SHADOWSOCKS_LIBEV_DEBIAN="${BASE_URL}/service/shadowsocks-libev_debian.sh"
# shadowsocks-rust config and init
SHADOWSOCKS_RUST_INSTALL_PATH="/usr/local/bin"
SHADOWSOCKS_RUST_BIN_PATH="/usr/local/bin/ssserver"
SHADOWSOCKS_RUST_INIT="/etc/init.d/shadowsocks-rust"
SHADOWSOCKS_RUST_CENTOS="${BASE_URL}/service/shadowsocks-rust_centos.sh"
SHADOWSOCKS_RUST_DEBIAN="${BASE_URL}/service/shadowsocks-rust_debian.sh"
# shadowsocks-libev dependencies
LIBSODIUM_VERSION="1.0.18"
LIBSODIUM_FILE="libsodium-${LIBSODIUM_VERSION}"
LIBSODIUM_URL="https://github.com/jedisct1/libsodium/releases/download/${LIBSODIUM_VERSION}-RELEASE/libsodium-${LIBSODIUM_VERSION}.tar.gz"
MBEDTLS_VERSION="2.16.3"
MBEDTLS_FILE="mbedtls-${MBEDTLS_VERSION}"
MBEDTLS_URL="https://tls.mbed.org/download/mbedtls-${MBEDTLS_VERSION}-gpl.tgz"
# 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_LOG_DIR="/var/log/kcptun-server.log"
KCPTUN_CENTOS="${BASE_URL}/service/kcptun_centos.sh"
KCPTUN_DEBIAN="${BASE_URL}/service/kcptun_debian.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_CENTOS="${BASE_URL}/service/cloak_centos.sh"
CLOAK_DEBIAN="${BASE_URL}/service/cloak_debian.sh"
CK_DB_PATH="/etc/cloak"
CK_CLIENT_CONFIG="/etc/cloak/ckclient.json"
CK_SERVER_CONFIG="/etc/cloak/ckserver.json"
# caddy
CADDY_INSTALL_PATH="/usr/local/caddy"
CADDY_BIN_PATH="/usr/local/caddy/caddy"
CADDY_CONF_FILE="/usr/local/caddy/Caddyfile"
CADDY_BASE_URL="https://caddyserver.com/download/linux/amd64"
CADDY_INIT="/etc/init.d/caddy"
ONLINE_CADDY_CENTOS_INIT_URL="${BASE_URL}/service/caddy_centos.sh"
LOCAL_CADDY_DEBIAN_INIT_PATH="./service/caddy_centos.sh"
ONLINE_CADDY_DEBIAN_INIT_URL="${BASE_URL}/service/caddy_debian.sh"
LOCAL_CADDY_DEBIAN_INIT_PATH="./service/caddy_debian.sh"
# nginx
NGINX_BIN_PATH="/usr/sbin/nginx"
NGINX_CONFIG="/etc/nginx/nginx.conf"
# shadowsocks-libev Ciphers
SHADOWSOCKS_CIPHERS=(
rc4-md5
salsa20
chacha20
chacha20-ietf
aes-256-cfb
aes-192-cfb
aes-128-cfb
aes-256-ctr
aes-192-ctr
aes-128-ctr
bf-cfb
camellia-128-cfb
camellia-192-cfb
camellia-256-cfb
aes-256-gcm
aes-192-gcm
aes-128-gcm
xchacha20-ietf-poly1305
chacha20-ietf-poly1305
)
# kcptun crypt
KCPTUN_CRYPT=(
aes
aes-128
aes-192
salsa20
blowfish
twofish
cast5
3des
tea
xtea
xor
sm4
none
)
# v2ray-plugin Transport mode
V2RAY_PLUGIN_TRANSPORT_MODE=(
ws+http
ws+tls+[cdn]
quic+tls+[cdn]
ws+tls+web
ws+tls+web+cdn
)
# kcptun mode(no manual)
KCPTUN_MODE=(
fast3
fast2
fast
normal
)
# Simple-obfs Obfuscation wrapper
OBFUSCATION_WRAPPER=(
http
tls
)
# 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="——————————————————————————————"
[[ $EUID -ne 0 ]] && echo -e "[${Red}Error${suffix}] This script must be run as root!" && exit 1
usage() {
cat >&1 <<-EOF
请使用: ./ss-plugins.sh [options...] [args...]
选项<options>包括:
install 安装
uninstall 卸载
update 升级
start 启动
stop 关闭
restart 重启
status 查看状态
script 升级脚本
show 显示可视化配置
uid 为cloak添加一个新的uid用户
link 用新添加的uid生成一个新的SS://链接
scan 用ss://链接在当前终端上生成一个可供扫描的二维码
help 打印帮助信息并退出
[注意] uid和link选项仅在搭配安装cloak的情况下使用.
EOF
exit $1
}
menu_status(){
local BIN_PATH=$1
local SS_PID=$2
if [[ -e ${BIN_PATH} ]] && [[ -e ${V2RAY_PLUGIN_BIN_PATH} ]] && [[ -e ${CADDY_BIN_PATH} ]]; then
V2_PID=`ps -ef |grep -v grep | grep v2ray-plugin |awk '{print $2}'`
CADDY_PID=`ps -ef |grep -v grep | grep caddy |awk '{print $2}'`
if [[ ! -z ${SS_PID} ]] && [[ ! -z ${V2_PID} ]] && [[ ! -z ${CADDY_PID} ]]; then
echo -e " 当前状态: ${Green}已安装${suffix} 并 ${Green}已启动${suffix}"
else
echo -e " 当前状态: ${Green}已安装${suffix} 但 ${Red}未启动${suffix}"
fi
elif [[ -e ${BIN_PATH} ]] && [[ -e ${V2RAY_PLUGIN_BIN_PATH} ]] && [[ -e ${NGINX_BIN_PATH} ]]; then
V2_PID=`ps -ef |grep -v grep | grep v2ray-plugin |awk '{print $2}'`
NGINX_PID=`ps -ef |grep -v grep | grep nginx.conf |awk '{print $2}'`
if [[ ! -z ${SS_PID} ]] && [[ ! -z ${V2_PID} ]] && [[ ! -z ${NGINX_PID} ]]; then
echo -e " 当前状态: ${Green}已安装${suffix} 并 ${Green}已启动${suffix}"
else
echo -e " 当前状态: ${Green}已安装${suffix} 但 ${Red}未启动${suffix}"
fi
elif [[ -e ${BIN_PATH} ]] && [[ -e ${V2RAY_PLUGIN_BIN_PATH} ]]; then
V2_PID=`ps -ef |grep -v grep | grep v2ray-plugin |awk '{print $2}'`
if [[ ! -z ${SS_PID} ]] && [[ ! -z ${V2_PID} ]]; then
echo -e " 当前状态: ${Green}已安装${suffix} 并 ${Green}已启动${suffix}"
else
echo -e " 当前状态: ${Green}已安装${suffix} 但 ${Red}未启动${suffix}"
fi
elif [[ -e ${BIN_PATH} ]] && [[ -e ${KCPTUN_BIN_PATH} ]]; then
KP_PID=`ps -ef |grep -v grep | grep kcptun-server |awk '{print $2}'`
if [[ ! -z ${SS_PID} ]] && [[ ! -z ${KP_PID} ]]; then
echo -e " 当前状态: ${Green}已安装${suffix} 并 ${Green}已启动${suffix}"
else
echo -e " 当前状态: ${Green}已安装${suffix} 但 ${Red}未启动${suffix}"
fi
elif [[ -e ${BIN_PATH} ]] && [[ -e ${SIMPLE_OBFS_BIN_PATH} ]]; then
OBFS_PID=`ps -ef |grep -v grep | grep obfs-server |awk '{print $2}'`
if [[ ! -z ${SS_PID} ]] && [[ ! -z ${OBFS_PID} ]]; then
echo -e " 当前状态: ${Green}已安装${suffix} 并 ${Green}已启动${suffix}"
else
echo -e " 当前状态: ${Green}已安装${suffix} 但 ${Red}未启动${suffix}"
fi
elif [[ -e ${BIN_PATH} ]] && [[ -e ${GOQUIET_BIN_PATH} ]]; then
GQ_PID=`ps -ef |grep -v grep | grep gq-server |awk '{print $2}'`
if [[ ! -z ${SS_PID} ]] && [[ ! -z ${GQ_PID} ]]; then
echo -e " 当前状态: ${Green}已安装${suffix} 并 ${Green}已启动${suffix}"
else
echo -e " 当前状态: ${Green}已安装${suffix} 但 ${Red}未启动${suffix}"
fi
elif [[ -e ${BIN_PATH} ]] && [[ -e ${CLOAK_SERVER_BIN_PATH} ]]; then
CK_PID=`ps -ef |grep -v grep | grep ck-server |awk '{print $2}'`
if [[ ! -z ${SS_PID} ]] && [[ ! -z ${CK_PID} ]]; then
echo -e " 当前状态: ${Green}已安装${suffix} 并 ${Green}已启动${suffix}"
else
echo -e " 当前状态: ${Green}已安装${suffix} 但 ${Red}未启动${suffix}"
fi
elif [[ -e ${BIN_PATH} ]]; then
if [[ ! -z ${SS_PID} ]]; then
echo -e " 当前状态: ${Green}已安装${suffix} 并 ${Green}已启动${suffix}"
else
echo -e " 当前状态: ${Green}已安装${suffix} 但 ${Red}未启动${suffix}"
fi
else
echo -e " 当前状态: ${Red}未安装${suffix}"
fi
}
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
}
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 "${Error} 安装 $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 "${Error} 安装 $1 失败."
exit 1
fi
fi
echo -e "${Info} $1 安装完成."
}
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_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_kernel_version(){
local kernel_version=$(uname -r | cut -d- -f1)
if version_gt ${kernel_version} 3.7.0; then
return 0
else
return 1
fi
}
check_kernel_headers(){
if check_sys packageManager yum; then
if rpm -qa | grep -q headers-$(uname -r); then
return 0
else
return 1
fi
elif check_sys packageManager apt; then
if dpkg -s linux-headers-$(uname -r) > /dev/null 2>&1; then
return 0
else
return 1
fi
fi
return 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 PROT=$1
if [ ! "$(command -v lsof)" ]; then
package_install "lsof" > /dev/null 2>&1
fi
if [[ `lsof -i:"${PROT}" | grep -v google_ | grep -v COMMAND | wc -l` -ne 0 ]];then
# Occupied
return 0
else
# Unoccupied
return 1
fi
}
check_script_update(){
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 "${Error} 无法链接到 Github !" && exit 0
if version_gt ${SHELL_VERSION_NEW} ${SHELL_VERSION}; then
echo
echo -e "${Green}当前脚本版本为:${SHELL_VERSION} 检测到有新版本可更新.${suffix}"
echo -e "按任意键开始…或按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
echo
echo -e "${Info} 当前脚本版本为: ${SHELL_VERSION} 未检测到更新版本."
echo
fi
}
check_ss_port(){
local SS_PORT=$1
while true
do
if [[ ${SS_PORT} -ne "443" ]]; then
echo -e "${Tip} SS-libev端口为${Green}${shadowsocksport}${suffix}"
echo
break
fi
gen_random_prot
if check_port_occupy ${ran_prot}; then
continue
fi
shadowsocksport=${ran_prot}
echo -e "${Tip} SS-libev端口已由${Red}443${suffix}重置为${Green}${shadowsocksport}${suffix}"
echo
break
done
}
choose_script_bbr(){
echo
echo -e "请选择BBR的安装脚本"
echo
echo -e " ${Green}1.${suffix} 秋水逸冰-BBR"
echo -e " ${Green}2.${suffix} BBR|BBR魔改|BBRplus|Lotserver版本"
echo && read -e -p "请输入数字 [1-2]:" bbr_menu_num
case "${bbr_menu_num}" in
1)
source <(curl -sL ${TEDDYSUN_BBR_SCRIPT_URL})
;;
2)
source <(curl -sL ${CHIAKGE_BBR_SCRIPT_URL})
;;
*)
echo -e "${Error} 请输入正确的数字 [1-2]"
;;
esac
}
choose_caddy_extension(){
local libev_v2ray=$1
improt_package "tools" "caddy_install.sh"
if [[ ${libev_v2ray} == "4" ]]; then
install_caddy
elif [[ ${libev_v2ray} == "5" ]]; then
install_caddy "tls.dns.cloudflare"
fi
}
add_more_entropy(){
# Ubuntu series is started by default after installation
# Debian series needs to add configuration to start after installation
# CentOS 6 is installed by default but not started. CentOS 7 is not started by default after installation. CentOS 8 is installed and started by default.
local ENTROPY_SIZE_BEFORE=$(cat /proc/sys/kernel/random/entropy_avail)
if [[ ${ENTROPY_SIZE_BEFORE} -lt 1000 ]]; then
echo -e "${Info} 安装rng-tools之前熵池的熵值为${Green}${ENTROPY_SIZE_BEFORE}${suffix}"
if [[ ! $(command -v rngd) ]]; then
package_install "rng-tools"
fi
if centosversion 6; then
chkconfig --add rngd
chkconfig rngd on
service rngd start > /dev/null 2>&1
elif centosversion 7 || centosversion 8; then
systemctl enable rngd
systemctl start rngd > /dev/null 2>&1
elif check_sys sysRelease debian; then
update-rc.d -f rng-tools defaults
sed -i '/^HRNGDEVICE/'d /etc/default/rng-tools
echo "HRNGDEVICE=/dev/urandom" >> /etc/default/rng-tools
systemctl start rng-tools > /dev/null 2>&1
fi
sleep 5
local ENTROPY_SIZE_BEHIND=$(cat /proc/sys/kernel/random/entropy_avail)
echo -e "${Info} 安装rng-tools之后熵池的熵值为${Green}${ENTROPY_SIZE_BEHIND}${suffix}"
else
echo -e "${Info} 当前熵池熵值大于或等于1000,未进行更多添加."
fi
}
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_str_base64_encode(){
echo -n $1 | base64 -w0
}
get_str_replace(){
echo -n $1 | sed 's/:/%3A/g;s/;/%3B/g;s/=/%3D/g;s/\//%2F/g'
}
gen_random_prot(){
ran_prot=$(shuf -i 9000-19999 -n 1)
}
gen_random_str(){
ran_str8=$(head -c 100 /dev/urandom | tr -dc a-z0-9A-Z |head -c 12)
ran_str16=$(head -c 100 /dev/urandom | tr -dc a-z0-9A-Z |head -c 16)
}
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
}
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
}
config_firewall(){
if centosversion 6; then
/etc/init.d/iptables status > /dev/null 2>&1
if [ $? -eq 0 ]; then
iptables -L -n | grep -i ${shadowsocksport} > /dev/null 2>&1
if [ $? -ne 0 ]; then
if [[ ${plugin_num} == "2" ]]; then
iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport ${listen_port} -j ACCEPT
iptables -I INPUT -m state --state NEW -m udp -p udp --dport ${listen_port} -j ACCEPT
elif [[ ${libev_v2ray} = "4" ]] || [[ ${libev_v2ray} = "5" ]] || [[ ${plugin_num} == "5" ]]; then
iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT
iptables -I INPUT -m state --state NEW -m udp -p udp --dport 443 -j ACCEPT
else
iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport ${shadowsocksport} -j ACCEPT
iptables -I INPUT -m state --state NEW -m udp -p udp --dport ${shadowsocksport} -j ACCEPT
fi
/etc/init.d/iptables save
/etc/init.d/iptables restart
else
echo -e "${Info} 端口 ${Green}${shadowsocksport}${suffix} 已经启用"
fi
else
echo -e "${Warning} iptables看起来没有运行或没有安装,请在必要时手动启用端口 ${shadowsocksport}"
fi
elif centosversion 7 || centosversion 8; then
systemctl status firewalld > /dev/null 2>&1
if [ $? -eq 0 ]; then
if [[ ${plugin_num} == "2" ]]; then
firewall-cmd --permanent --zone=public --add-port=${listen_port}/tcp
firewall-cmd --permanent --zone=public --add-port=${listen_port}/udp
elif [[ ${libev_v2ray} = "4" ]] || [[ ${libev_v2ray} = "5" ]] || [[ ${plugin_num} == "5" ]]; then
firewall-cmd --permanent --zone=public --add-port=443/tcp
firewall-cmd --permanent --zone=public --add-port=443/udp
else
firewall-cmd --permanent --zone=public --add-port=${shadowsocksport}/tcp
firewall-cmd --permanent --zone=public --add-port=${shadowsocksport}/udp
fi
firewall-cmd --reload
else
echo -e "${Warning} firewalld看起来没有运行或没有安装,请在必要时手动启用端口 ${shadowsocksport}"
fi
fi
}
download(){
local filename=$(basename $1)
if [ -e ${1} ]; then
echo "${filename} [已存在.]"
else
echo "${filename} 当前目录中不存在, 现在开始下载."
wget --no-check-certificate -c -t3 -T60 -O ${1} ${2}
if [ $? -ne 0 ]; then
echo -e "${Error} 下载 ${filename} 失败."
exit 1
fi
fi
}
download_service_file(){
local filename_path=$1
local online_centos_url=$2
local local_centos_file_path=$3
local online_debian_url=$4
local local_debian_file_path=$5
if check_sys packageManager yum; then
if [[ ${methods} == "Online" ]]; then
download ${filename_path} ${online_centos_url}
else
cp -rf ${local_centos_file_path} ${filename_path}
fi
elif check_sys packageManager apt; then
if [[ ${methods} == "Online" ]]; then
download ${filename_path} ${online_debian_url}
else
cp -rf ${local_debian_file_path} ${filename_path}
fi
fi
}
download_ss_file(){
cd ${CUR_DIR}
if [[ ${SS_VERSION} = "ss-libev" ]]; then
# Download Shadowsocks-libev
libev_ver=$(wget --no-check-certificate -qO- https://api.github.com/repos/shadowsocks/shadowsocks-libev/releases | grep -o '"tag_name": ".*"' | head -n 1| sed 's/"//g;s/v//g' | sed 's/tag_name: //g')
[ -z ${libev_ver} ] && echo -e "${Error} 获取 shadowsocks-libev 最新版本失败." && exit 1
local SS_INIT_CENTOS="./service/shadowsocks-libev_centos.sh"
local SS_INIT_DEBIAN="./service/shadowsocks-libev_debian.sh"
shadowsocks_libev_file="shadowsocks-libev-${libev_ver}"
shadowsocks_libev_url="https://github.com/shadowsocks/shadowsocks-libev/releases/download/v${libev_ver}/shadowsocks-libev-${libev_ver}.tar.gz"
download "${shadowsocks_libev_file}.tar.gz" "${shadowsocks_libev_url}"
download_service_file ${SHADOWSOCKS_LIBEV_INIT} ${SHADOWSOCKS_LIBEV_CENTOS} ${SS_INIT_CENTOS} ${SHADOWSOCKS_LIBEV_DEBIAN} ${SS_INIT_DEBIAN}
elif [[ ${SS_VERSION} = "ss-rust" ]]; then
# Download Shadowsocks-libev
rust_ver=$(wget --no-check-certificate -qO- https://api.github.com/repos/shadowsocks/shadowsocks-rust/releases | grep -o '"tag_name": ".*"' | head -n 1| sed 's/"//g;s/v//g' | sed 's/tag_name: //g')
[ -z ${rust_ver} ] && echo -e "${Error} 获取 shadowsocks-rust 最新版本失败." && exit 1
local SS_INIT_CENTOS="./service/shadowsocks-rust_centos.sh"
local SS_INIT_DEBIAN="./service/shadowsocks-rust_debian.sh"
shadowsocks_rust_file="shadowsocks-v${rust_ver}-stable.x86_64-unknown-linux-musl"
shadowsocks_rust_url="https://github.com/shadowsocks/shadowsocks-rust/releases/download/v${rust_ver}/shadowsocks-v${rust_ver}-stable.x86_64-unknown-linux-musl.tar.xz"
download "${shadowsocks_rust_file}.tar.xz" "${shadowsocks_rust_url}"
download_service_file ${SHADOWSOCKS_RUST_INIT} ${SHADOWSOCKS_RUST_CENTOS} ${SS_INIT_CENTOS} ${SHADOWSOCKS_RUST_DEBIAN} ${SS_INIT_DEBIAN}
fi
}
download_plugins_file(){
cd ${CUR_DIR}
if [[ "${plugin_num}" == "1" ]]; then
# Download v2ray-plugin
v2ray_plugin_ver=$(wget --no-check-certificate -qO- https://api.github.com/repos/shadowsocks/v2ray-plugin/releases | grep -o '"tag_name": ".*"' |head -n 1| sed 's/"//g;s/v//g' | sed 's/tag_name: //g')
[ -z ${v2ray_plugin_ver} ] && echo -e "${Error} 获取 v2ray-plugin 最新版本失败." && exit 1
v2ray_plugin_file="v2ray-plugin-linux-amd64-v${v2ray_plugin_ver}"
v2ray_plugin_url="https://github.com/shadowsocks/v2ray-plugin/releases/download/v${v2ray_plugin_ver}/v2ray-plugin-linux-amd64-v${v2ray_plugin_ver}.tar.gz"
download "${v2ray_plugin_file}.tar.gz" "${v2ray_plugin_url}"
elif [[ "${plugin_num}" == "2" ]]; then
# Download kcptun
kcptun_ver=$(wget --no-check-certificate -qO- https://api.github.com/repos/xtaci/kcptun/releases | grep -o '"tag_name": ".*"' |head -n 1| sed 's/"//g;s/v//g' | sed 's/tag_name: //g')
[ -z ${kcptun_ver} ] && echo -e "${Error} 获取 kcptun 最新版本失败." && exit 1
kcptun_file="kcptun-linux-amd64-${kcptun_ver}"
kcptun_url="https://github.com/xtaci/kcptun/releases/download/v${kcptun_ver}/kcptun-linux-amd64-${kcptun_ver}.tar.gz"
download "${kcptun_file}.tar.gz" "${kcptun_url}"
download_service_file ${KCPTUN_INIT} ${KCPTUN_CENTOS} "./service/kcptun_centos.sh" ${KCPTUN_DEBIAN} "./service/kcptun_debian.sh"
elif [[ "${plugin_num}" == "4" ]]; then
# Download goquiet
goquiet_ver=$(wget --no-check-certificate -qO- https://api.github.com/repos/cbeuw/GoQuiet/releases | grep -o '"tag_name": ".*"' |head -n 1| sed 's/"//g;s/v//g' | sed 's/tag_name: //g')
[ -z ${goquiet_ver} ] && echo -e "${Error} 获取 goquiet 最新版本失败." && exit 1
goquiet_file="gq-server-linux-amd64-${goquiet_ver}"
goquiet_url="https://github.com/cbeuw/GoQuiet/releases/download/v${goquiet_ver}/gq-server-linux-amd64-${goquiet_ver}"
download "${goquiet_file}" "${goquiet_url}"
elif [[ "${plugin_num}" == "5" ]]; then
# Download cloak server
cloak_ver=$(wget --no-check-certificate -qO- https://api.github.com/repos/cbeuw/Cloak/releases | grep -o '"tag_name": ".*"' |head -n 1| sed 's/"//g;s/v//g' | sed 's/tag_name: //g')
[ -z ${cloak_ver} ] && echo -e "${Error} 获取 cloak 最新版本失败." && exit 1
# cloak_ver="2.1.1"
cloak_file="ck-server-linux-amd64-${cloak_ver}"
cloak_url="https://github.com/cbeuw/Cloak/releases/download/v${cloak_ver}/ck-server-linux-amd64-${cloak_ver}"
download "${cloak_file}" "${cloak_url}"
download_service_file ${CLOAK_INIT} ${CLOAK_CENTOS} "./service/cloak_centos.sh" ${CLOAK_DEBIAN} "./service/cloak_debian.sh"
fi
}
error_detect_depends(){
local command=$1
local depend=`echo "${command}" | awk '{print $4}'`
echo -e "${Info} 开始安装依赖包 ${depend}"
${command} > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo -e "${Error} 依赖包${Red}${depend}${suffix}安装失败,请检查. "
echo "Checking the error message and run the script again."
exit 1
fi
}
install_dependencies(){
if check_sys packageManager yum; then
echo -e "${Info} 检查EPEL存储库."
if [ ! -f /etc/yum.repos.d/epel.repo ]; then
yum install -y epel-release > /dev/null 2>&1
fi
[ ! -f /etc/yum.repos.d/epel.repo ] && echo -e "${Error} 安装EPEL存储库失败,请检查它。" && exit 1
[ ! "$(command -v yum-config-manager)" ] && yum install -y yum-utils > /dev/null 2>&1
[ x"$(yum-config-manager epel | grep -w enabled | awk '{print $3}')" != x"True" ] && yum-config-manager --enable epel > /dev/null 2>&1
echo -e "${Info} EPEL存储库检查完成."
yum_depends=(
gettext gcc pcre pcre-devel autoconf libtool automake make asciidoc xmlto c-ares-devel libev-devel zlib-devel openssl-devel git qrencode jq
)
for depend in ${yum_depends[@]}; do
error_detect_depends "yum -y install ${depend}"
done
elif check_sys packageManager apt; then
apt_depends=(
gettext gcc build-essential autoconf libtool libpcre3-dev asciidoc xmlto libev-dev libc-ares-dev automake libssl-dev git qrencode jq
)
apt-get -y update
for depend in ${apt_depends[@]}; do
error_detect_depends "apt-get -y install ${depend}"
done
fi
}
install_libsodium(){
if [ ! -f /usr/lib/libsodium.a ]; then
cd ${CUR_DIR}
echo -e "${Info} 下载${LIBSODIUM_FILE}."
download "${LIBSODIUM_FILE}.tar.gz" "${LIBSODIUM_URL}"
echo -e "${Info} 解压${LIBSODIUM_FILE}."
tar zxf ${LIBSODIUM_FILE}.tar.gz && cd ${LIBSODIUM_FILE}
echo -e "${Info} 编译安装${LIBSODIUM_FILE}."
./configure --prefix=/usr && make && make install
if [ $? -ne 0 ]; then
echo -e "${Error} ${LIBSODIUM_FILE} 安装失败 !"
install_cleanup
exit 1
fi
echo -e "${Info} ${LIBSODIUM_FILE} 安装成功 !"
else
echo -e "${Info} ${LIBSODIUM_FILE} 已经安装."
fi
}
install_mbedtls(){
if [ ! -f /usr/lib/libmbedtls.a ]; then
cd ${CUR_DIR}
echo -e "${Info} 下载${MBEDTLS_FILE}."
download "${MBEDTLS_FILE}-gpl.tgz" "${MBEDTLS_URL}"
echo -e "${Info} 解压${MBEDTLS_FILE}."
tar xf ${MBEDTLS_FILE}-gpl.tgz
cd ${MBEDTLS_FILE}
echo -e "${Info} 编译安装${MBEDTLS_FILE}."
make SHARED=1 CFLAGS=-fPIC
make DESTDIR=/usr install
if [ $? -ne 0 ]; then
echo -e "${Error} ${MBEDTLS_FILE} 安装失败."
install_cleanup
exit 1
fi
echo -e "${Info} ${MBEDTLS_FILE} 安装成功 !"
else
echo -e "${Info} ${MBEDTLS_FILE} 已经安装."
fi
}
autoconf_version(){
if [ ! "$(command -v autoconf)" ]; then
echo -e "${Info} 开始安装autoconf 软件包."
if check_sys packageManager yum; then
yum install -y autoconf > /dev/null 2>&1 || echo -e "${Error} 安装autoconf失败."
elif check_sys packageManager apt; then
apt-get -y update > /dev/null 2>&1
apt-get -y install autoconf > /dev/null 2>&1 || echo -e "${Error} 安装autoconf失败."
fi
echo -e "${Info} autoconf 安装完成."
fi
local autoconf_ver=$(autoconf --version | grep autoconf | grep -oE "[0-9.]+")
if version_ge ${autoconf_ver} 2.67; then
return 0
else
return 1
fi
}
config_ss(){
if check_kernel_version && check_kernel_headers; then
fast_open="true"
else
fast_open="false"
fi
local server_value="\"0.0.0.0\""
if get_ipv6; then
local V=${SS_VERSION}
local N=${plugin_num}
if [[ ${V} = "ss-libev" ]] && [[ ${N} = "2" ]] || [[ ${N} = "3" ]] || [[ ${N} == "5" ]] || [[ -z ${N} ]]; then
server_value="[\"[::0]\",\"0.0.0.0\"]"
fi
fi
if [ ! -d "$(dirname ${SHADOWSOCKS_CONFIG})" ]; then
mkdir -p $(dirname ${SHADOWSOCKS_CONFIG})
fi
# start wriet config
improt_package "templates" "config_file_templates.sh"
if [[ ${plugin_num} == "1" ]]; then
if [[ ${libev_v2ray} == "1" ]]; then
ss_v2ray_ws_http_config
elif [[ ${libev_v2ray} == "2" ]]; then
ss_v2ray_ws_tls_cdn_config
elif [[ ${libev_v2ray} == "3" ]]; then
ss_v2ray_quic_tls_cdn_config
elif [[ ${libev_v2ray} == "4" ]]; then
ss_v2ray_ws_tls_web_config
if [[ ${web_flag} = "1" ]]; then
caddy_config_none_cdn
elif [[ ${web_flag} = "2" ]]; then
mirror_domain=$(echo ${mirror_site} | sed 's/https:\/\///g')
nginx_config
fi
elif [[ ${libev_v2ray} == "5" ]]; then
ss_v2ray_ws_tls_web_cdn_config
if [[ ${web_flag} = "1" ]]; then
caddy_config_with_cdn
elif [[ ${web_flag} = "2" ]]; then
mirror_domain=$(echo ${mirror_site} | sed 's/https:\/\///g')
nginx_config
fi
fi
elif [[ ${plugin_num} == "2" ]]; then
if [ ! -d "$(dirname ${KCPTUN_CONFIG})" ]; then
mkdir -p $(dirname ${KCPTUN_CONFIG})
fi
ss_config_standalone
kcptun_config_standalone
elif [[ ${plugin_num} == "3" ]]; then
if [[ ${libev_obfs} == "1" ]]; then
ss_obfs_http_config
elif [[ ${libev_obfs} == "2" ]]; then
ss_obfs_tls_config
fi
elif [[ ${plugin_num} == "4" ]]; then
ss_goquiet_config
elif [[ ${plugin_num} == "5" ]]; then
if [ ! -d "$(dirname ${CK_SERVER_CONFIG})" ]; then
mkdir -p $(dirname ${CK_SERVER_CONFIG})
fi
ss_config_standalone
cloak2_server_config
cloak2_client_config
else
ss_config_standalone
fi
}
gen_ss_links(){
improt_package "templates" "sip002_url_templates.sh"
if [[ ${plugin_num} == "1" ]]; then
if [[ ${libev_v2ray} == "1" ]]; then
ss_v2ray_ws_http_link
elif [[ ${libev_v2ray} == "2" ]]; then
ss_v2ray_ws_tls_cdn_link