forked from loyess/Shell
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ss-plugins.sh
1360 lines (1171 loc) · 43.7 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.0.0"
# ====================
# current path
CUR_DIR=$( pwd )
usage() {
cat >&1 <<-EOF
请使用: ./ss-plugins.sh [options1...] [options2...] [args...]
选项<options1>包括:
-o|-O, Online 在线安装(默认)
-l|-L, Local git clone 本地安装
-h|-H, help 打印帮助信息并退出
选项<options2>包括:
install 安装
uninstall 卸载
update 升级
start 启动
stop 关闭
restart 重启
status 查看状态
show 显示可视化配置
uid 为cloak添加一个新的uid用户
link 用新添加的uid生成一个新的SS://链接
scan 用ss://链接在当前终端上生成一个可供扫描的二维码
[注意] “选项2”中的uid和link选项仅在cloak-v1.1.2版本中使用,使用“选项2”时必须指定“选项1”是Online还是Local安装.
EOF
exit $1
}
# install methods
methods=${1:-"Online"}
if [ ${methods} == "-O" ] || [ ${methods} == "-o" ]; then
methods="Online"
elif [ ${methods} == "-L" ] || [ ${methods} == "-l" ]; then
fds=$(ls -d */ | sed 's/\///g')
if [ ${#fds[n]} -eq 51 ]; then
methods="Local"
else
methods="help"
fi
elif [ ${methods} == "-H" ] || [ ${methods} == "-h" ]; then
methods="help"
fi
case ${methods} in
Online)
# BASE_URL="https://github.com/loyess/Shell/raw/test"
BASE_URL="https://github.com/loyess/Shell/raw/master"
;;
Local)
BASE_URL="."
;;
help)
usage 0
;;
*)
usage 1
;;
esac
# bbr
BBR_SCRIPT_URL="https://git.io/vbUk0"
# Humanization config PATH
HUMAN_CONFIG="/etc/shadowsocks-libev/human-config"
# shadowsocklibev-libev config and init
SHADOWSOCKS_LIBEV_INSTALL_PATH="/usr/local/bin"
SHADOWSOCKS_LIBEV_INIT="/etc/init.d/shadowsocks-libev"
SHADOWSOCKS_LIBEV_CONFIG="/etc/shadowsocks-libev/config.json"
SHADOWSOCKS_LIBEV_CENTOS="${BASE_URL}/service/shadowsocks-libev_centos.sh"
SHADOWSOCKS_LIBEV_DEBIAN="${BASE_URL}/service/shadowsocks-libev_debian.sh"
# shadowsocklibev-libev dependencies
LIBSODIUM_FILE="libsodium-1.0.17"
LIBSODIUM_URL="https://github.com/jedisct1/libsodium/releases/download/1.0.17/libsodium-1.0.17.tar.gz"
MBEDTLS_FILE="mbedtls-2.16.0"
MBEDTLS_URL="https://tls.mbed.org/download/mbedtls-2.16.0-gpl.tgz"
# kcptun
KCPTUN_INSTALL_DIR="/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"
# cloak
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/db"
CK_CLIENT_CONFIG="/etc/cloak/ckclient.json"
CK_SERVER_CONFIG="/etc/cloak/ckserver.json"
# caddy
CADDY_CONF_FILE="/usr/local/caddy/Caddyfile"
CADDY_INSTALL_SCRIPT_URL="https://git.io/fjuAR"
# shadowsocklibev-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
)
# ipv4 and ipv6 Re
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])$"
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
disable_selinux(){
if [ -s /etc/selinux/config ] && grep '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_pid(){
PID=`ps -ef |grep -v grep | grep ss-server |awk '{print $2}'`
}
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_ss_libev_version(){
if [[ -e '/usr/local/bin/ss-server' ]]; then
curr_ver=$(ss-server -v | grep shadowsocks-libev | cut -d\ -f2)
latest_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')
if version_gt ${latest_ver} ${curr_ver}; then
return 0
else
return 1
fi
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_ver(){
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
simple_obfs_ver=$(wget --no-check-certificate -qO- https://api.github.com/repos/shadowsocks/simple-obfs/releases | grep -o '"tag_name": ".*"' | head -n 1| sed 's/"//g;s/v//g' | sed 's/tag_name: //g')
[ -z ${simple_obfs_ver} ] && echo -e "${Error} 获取 simple-obfs 最新版本失败." && exit 1
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
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
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
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
}
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
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; 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
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_files(){
cd ${CUR_DIR}
# Download Shadowsocks-libev
get_ver
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}"
if check_sys packageManager yum; then
if [[ ${methods} == "Online" ]]; then
download "${SHADOWSOCKS_LIBEV_INIT}" "${SHADOWSOCKS_LIBEV_CENTOS}"
else
cp ./service/shadowsocks-libev_centos.sh "$(dirname ${SHADOWSOCKS_LIBEV_INIT})"
mv "$(dirname ${SHADOWSOCKS_LIBEV_INIT})/shadowsocks-libev_centos.sh" "${SHADOWSOCKS_LIBEV_INIT}"
fi
elif check_sys packageManager apt; then
if [[ ${methods} == "Online" ]]; then
download "${SHADOWSOCKS_LIBEV_INIT}" "${SHADOWSOCKS_LIBEV_DEBIAN}"
else
cp ./service/shadowsocks-libev_debian.sh "$(dirname ${SHADOWSOCKS_LIBEV_INIT})"
mv "$(dirname ${SHADOWSOCKS_LIBEV_INIT})/shadowsocks-libev_debian.sh" "${SHADOWSOCKS_LIBEV_INIT}"
fi
fi
if [[ "${plugin_num}" == "1" ]]; then
# Download v2ray-plugin
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_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}"
if check_sys packageManager yum; then
if [[ ${methods} == "Online" ]]; then
download "${KCPTUN_INIT}" "${KCPTUN_CENTOS}"
else
cp ./service/kcptun_centos.sh "$(dirname ${KCPTUN_INIT})"
mv "$(dirname ${KCPTUN_INIT})/kcptun_centos.sh" "${KCPTUN_INIT}"
fi
elif check_sys packageManager apt; then
if [[ ${methods} == "Online" ]]; then
download "${KCPTUN_INIT}" "${KCPTUN_DEBIAN}"
else
cp ./service/kcptun_debian.sh "$(dirname ${KCPTUN_INIT})"
mv "$(dirname ${KCPTUN_INIT})/kcptun_debian.sh" "${KCPTUN_INIT}"
fi
fi
elif [[ "${plugin_num}" == "4" ]]; then
# Download goquiet
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
if [ "${ck_install_ver}" == "n" ] || [ "${ck_install_ver}" == "N" ]; then
cloak_ver="1.1.2"
# Download cloak server
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}"
else
# Download cloak server
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}"
if check_sys packageManager yum; then
if [[ ${methods} == "Online" ]]; then
download "${CLOAK_INIT}" "${CLOAK_CENTOS}"
else
cp ./service/cloak_centos.sh "$(dirname ${CLOAK_INIT})"
mv "$(dirname ${CLOAK_INIT})/cloak_centos.sh" "${CLOAK_INIT}"
fi
elif check_sys packageManager apt; then
if [[ ${methods} == "Online" ]]; then
download "${CLOAK_INIT}" "${CLOAK_DEBIAN}"
else
cp ./service/cloak_debian.sh "$(dirname ${CLOAK_INIT})"
mv "$(dirname ${CLOAK_INIT})/cloak_debian.sh" "${CLOAK_INIT}"
fi
fi
fi
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 wget 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 wget 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
# server_value="[\"[::0]\",\"0.0.0.0\"]"
server_value="\"0.0.0.0\""
fi
if [ ! -d "$(dirname ${SHADOWSOCKS_LIBEV_CONFIG})" ]; then
mkdir -p $(dirname ${SHADOWSOCKS_LIBEV_CONFIG})
fi
# start wriet config
if [[ ${methods} == "Online" ]]; then
source <(curl -sL ${BASE_URL}/templates/write_config.sh)
else
source ${BASE_URL}/templates/write_config.sh
fi
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
caddy_config_none_cdn
elif [[ ${libev_v2ray} == "5" ]]; then
ss_v2ray_ws_tls_web_cdn_config
caddy_config_with_cdn
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 [ "${ck_install_ver}" == "n" ] || [ "${ck_install_ver}" == "N" ]; then
ss_cloak_server_config
if [ ! -d "$(dirname ${CK_CLIENT_CONFIG})" ]; then
mkdir -p $(dirname ${CK_CLIENT_CONFIG})
fi
cloak_client_config
else
if [ ! -d "$(dirname ${CK_SERVER_CONFIG})" ]; then
mkdir -p $(dirname ${CK_SERVER_CONFIG})
fi
ss_config_standalone
cloak2_server_config
cloak2_client_config
fi
else
ss_config_standalone
fi
}
gen_ss_links(){
if [[ ${methods} == "Online" ]]; then
source <(curl -sL ${BASE_URL}/templates/group_sslink.sh)
else
source ${BASE_URL}/templates/group_sslink.sh
fi
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
elif [[ ${libev_v2ray} == "3" ]]; then
ss_v2ray_quic_tls_cdn_link
elif [[ ${libev_v2ray} == "4" ]]; then
ss_v2ray_ws_tls_web_link
elif [[ ${libev_v2ray} == "5" ]]; then
ss_v2ray_ws_tls_web_cdn_link
fi
elif [[ ${plugin_num} == "2" ]]; then
ss_kcptun_link
elif [[ ${plugin_num} == "3" ]]; then
if [[ ${libev_obfs} == "1" ]]; then
ss_obfs_http_link
elif [[ ${libev_obfs} == "2" ]]; then
ss_obfs_tls_link
fi
elif [[ ${plugin_num} == "4" ]]; then
ss_goquiet_link
elif [[ ${plugin_num} == "5" ]]; then
if [ "${ck_install_ver}" == "n" ] || [ "${ck_install_ver}" == "N" ]; then
ss_cloak_link
else
ss_cloak_link_new
fi
else
ss_link
fi
}
install_completed(){
ldconfig
${SHADOWSOCKS_LIBEV_INIT} start > /dev/null 2>&1
if [[ ${methods} == "Online" ]]; then
source <(curl -sL ${BASE_URL}/templates/show_config.sh)
else
source ${BASE_URL}/templates/show_config.sh
fi
clear -x
if [[ ${plugin_num} == "1" ]]; then
if [[ ${libev_v2ray} == "1" ]]; then
ss_v2ray_ws_http_show
elif [[ ${libev_v2ray} == "2" ]]; then
ss_v2ray_ws_tls_cdn_show
elif [[ ${libev_v2ray} == "3" ]]; then
ss_v2ray_quic_tls_cdn_show
elif [[ ${libev_v2ray} == "4" ]]; then
# start caddy
/etc/init.d/caddy start > /dev/null 2>&1
ss_v2ray_ws_tls_web_show
elif [[ ${libev_v2ray} == "5" ]]; then
# cloudflare email & api key
# export CLOUDFLARE_EMAIL="${CF_Email}"
# export CLOUDFLARE_API_KEY="${CF_Key}"
cat > /etc/profile <<-EOF
export CLOUDFLARE_EMAIL="${CF_Email}"
export CLOUDFLARE_API_KEY="${CF_Key}"
EOF
# start caddy
/etc/init.d/caddy start > /dev/null 2>&1
ss_v2ray_ws_tls_web_cdn_show
fi
elif [[ ${plugin_num} == "2" ]]; then
# start kcptun
${KCPTUN_INIT} start > /dev/null 2>&1
ss_kcptun_show
elif [[ ${plugin_num} == "3" ]]; then
if [[ ${libev_obfs} == "1" ]]; then
ss_obfs_http_show
elif [[ ${libev_obfs} == "2" ]]; then
ss_obfs_tls_show
fi
elif [[ ${plugin_num} == "4" ]]; then
ss_goquiet_show
elif [[ ${plugin_num} == "5" ]]; then
if [ "${ck_install_ver}" == "n" ] || [ "${ck_install_ver}" == "N" ]; then
ss_cloak_show
else
# start cloak
${CLOAK_INIT} start > /dev/null 2>&1
ss_cloak_show_new
fi
else
ss_show
fi
}
install_prepare(){
if [[ ${methods} == "Online" ]]; then
source <(curl -sL ${BASE_URL}/prepare/ss_libev_prepare.sh)
else
source ${BASE_URL}/prepare/ss_libev_prepare.sh
fi
install_prepare_port
install_prepare_password
install_prepare_cipher
echo -e "请选择要安装的SS-Plugin
${Green}1.${suffix} v2ray
${Green}2.${suffix} kcptun
${Green}3.${suffix} simple-obfs
${Green}4.${suffix} goquiet (unofficial)
${Green}5.${suffix} cloak (based goquiet)
"
echo && read -e -p "(默认: 不安装):" plugin_num
[[ -z "${plugin_num}" ]] && plugin_num="" && echo -e "\n${Tip} 当前未选择任何插件,仅安装Shadowsocks-libev."
if [[ ${plugin_num} == "1" ]]; then
if [[ ${methods} == "Online" ]]; then
source <(curl -sL ${BASE_URL}/prepare/v2p_prepare.sh)
else
source ${BASE_URL}/prepare/v2p_prepare.sh
fi
install_prepare_libev_v2ray
elif [[ ${plugin_num} == "2" ]]; then
if [[ ${methods} == "Online" ]]; then
source <(curl -sL ${BASE_URL}/prepare/kp_prepare.sh)
else
source ${BASE_URL}/prepare/kp_prepare.sh
fi
install_prepare_libev_kcptun
elif [[ ${plugin_num} == "3" ]]; then
if [[ ${methods} == "Online" ]]; then
source <(curl -sL ${BASE_URL}/prepare/obfs_prepare.sh)
else
source ${BASE_URL}/prepare/obfs_prepare.sh
fi
install_prepare_libev_obfs
elif [[ ${plugin_num} == "4" ]]; then
if [[ ${methods} == "Online" ]]; then
source <(curl -sL ${BASE_URL}/prepare/gq_prepare.sh)
else
source ${BASE_URL}/prepare/gq_prepare.sh
fi
install_prepare_libev_goquiet
elif [[ ${plugin_num} == "5" ]]; then
if [[ ${methods} == "Online" ]]; then
source <(curl -sL ${BASE_URL}/prepare/ck_prepare.sh)
else
source ${BASE_URL}/prepare/ck_prepare.sh
fi
install_prepare_libev_cloak
elif [[ ${plugin_num} == "" ]]; then
:
else
echo -e "${Error} 请输入正确的数字 [1-5]" && exit 1
fi
echo
echo "按任意键开始…或按Ctrl+C取消"
char=`get_char`
}
install_main(){
install_libsodium
if ! ldconfig -p | grep -wq "/usr/lib"; then
echo "/usr/lib" > /etc/ld.so.conf.d/lib.conf
fi
ldconfig
install_mbedtls
if [[ ${methods} == "Online" ]]; then
source <(curl -sL ${BASE_URL}/tools/shadowsocks_libev_install.sh)
else
cd ${CUR_DIR}
source ${BASE_URL}/tools/shadowsocks_libev_install.sh
fi
install_shadowsocks_libev
if [ "${plugin_num}" == "1" ]; then
if [[ ${methods} == "Online" ]]; then
source <(curl -sL ${BASE_URL}/plugins/v2ray_plugin_install.sh)
else
cd ${CUR_DIR}
source ${BASE_URL}/plugins/v2ray_plugin_install.sh
fi
install_v2ray_plugin
plugin_client_name="v2ray"
elif [ "${plugin_num}" == "2" ]; then
if [[ ${methods} == "Online" ]]; then
source <(curl -sL ${BASE_URL}/plugins/kcptun_install.sh)
else
cd ${CUR_DIR}
source ${BASE_URL}/plugins/kcptun_install.sh
fi
install_kcptun
plugin_client_name="kcptun"
elif [ "${plugin_num}" == "3" ]; then
if [[ ${methods} == "Online" ]]; then
source <(curl -sL ${BASE_URL}/plugins/simple_obfs_install.sh)
else
cd ${CUR_DIR}
source ${BASE_URL}/plugins/simple_obfs_install.sh
fi
install_simple_obfs
plugin_client_name="obfs-local"
elif [ "${plugin_num}" == "4" ]; then
if [[ ${methods} == "Online" ]]; then
source <(curl -sL ${BASE_URL}/plugins/goquiet_install.sh)
else
cd ${CUR_DIR}
source ${BASE_URL}/plugins/goquiet_install.sh
fi
install_goquiet
plugin_client_name="gq-client"
elif [ "${plugin_num}" == "5" ]; then
if [[ ${methods} == "Online" ]]; then
source <(curl -sL ${BASE_URL}/plugins/cloak_install.sh)
else
cd ${CUR_DIR}
source ${BASE_URL}/plugins/cloak_install.sh
fi
install_cloak
gen_credentials
plugin_client_name="ck-client"