-
Notifications
You must be signed in to change notification settings - Fork 0
/
kcptun_for_ss_ssr-install.sh
2149 lines (2143 loc) · 91.3 KB
/
kcptun_for_ss_ssr-install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#! /bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
#===============================================================================================
# System Required: CentOS Debian or Ubuntu (32bit/64bit)
# Description: A tool to auto-compile & install KCPTUN for SS/SSR on Linux
# Intro: https://github.com/onekeyshell/kcptun_for_ss_ssr/issues
#===============================================================================================
version="2.0.7"
if [ $(id -u) != "0" ]; then
echo "Error: You must be root to run this script, please use root to install SS/SSR/KCPTUN"
exit 1
fi
shell_update(){
fun_clangcn "clear"
echo "+ Check updates for shell..."
remote_shell_version=`wget --no-check-certificate -qO- ${shell_download_link} | sed -n '/'^version'/p' | cut -d\" -f2`
if [ ! -z ${remote_shell_version} ]; then
if [[ "${version}" != "${remote_shell_version}" ]];then
echo -e "${COLOR_GREEN}Found a new version,update now!!!${COLOR_END}"
echo
echo -n "+ Update shell ..."
if ! wget --no-check-certificate -qO $0 ${shell_download_link}; then
echo -e " [${COLOR_RED}failed${COLOR_END}]"
echo
exit 1
else
echo -e " [${COLOR_GREEN}OK${COLOR_END}]"
echo
echo -e "${COLOR_GREEN}Please Re-run${COLOR_END} ${COLOR_PINK}$0 ${clang_action}${COLOR_END}"
echo
exit 1
fi
exit 1
fi
fi
}
shell_download_link="https://raw.githubusercontent.com/onekeyshell/kcptun_for_ss_ssr/master/kcptun_for_ss_ssr-install.sh"
program_version_link="https://raw.githubusercontent.com/onekeyshell/kcptun_for_ss_ssr/master/version.sh"
ss_libev_config="/etc/shadowsocks-libev/config.json"
ssr_config="/usr/local/shadowsocksR/shadowsocksR.json"
ssrr_config="/usr/local/shadowsocksrr/user-config.json"
kcptun_config="/usr/local/kcptun/config.json"
# Check if user is root
contact_us="https://github.com/onekeyshell/kcptun_for_ss_ssr/issues"
fun_clangcn(){
local clear_flag=""
clear_flag=$1
if [[ ${clear_flag} == "clear" ]]; then
clear
fi
echo ""
echo "+----------------------------------------------------------------+"
echo "| KCPTUN for SS/SSR on Linux Server |"
echo "+----------------------------------------------------------------+"
echo "| A tool to auto-compile & install KCPTUN for SS/SSR on Linux |"
echo "+----------------------------------------------------------------+"
echo "| Intro: ${contact_us} |"
echo "+----------------------------------------------------------------+"
echo ""
}
fun_set_text_color(){
COLOR_RED='\E[1;31m'
COLOR_GREEN='\E[1;32m'
COLOR_YELOW='\E[1;33m'
COLOR_BLUE='\E[1;34m'
COLOR_PINK='\E[1;35m'
COLOR_PINKBACK_WHITEFONT='\033[45;37m'
COLOR_GREEN_LIGHTNING='\033[32m \033[05m'
COLOR_END='\E[0m'
}
# Check OS
Get_Dist_Name(){
release=''
systemPackage=''
DISTRO=''
if grep -Eqi "CentOS" /etc/issue || grep -Eq "CentOS" /etc/*-release; then
DISTRO='CentOS'
release="centos"
systemPackage='yum'
elif grep -Eqi "centos|red hat|redhat" /etc/issue || grep -Eqi "centos|red hat|redhat" /etc/*-release; then
DISTRO='RHEL'
release="centos"
systemPackage='yum'
elif grep -Eqi "Aliyun" /etc/issue || grep -Eq "Aliyun" /etc/*-release; then
DISTRO='Aliyun'
release="centos"
systemPackage='yum'
elif grep -Eqi "Fedora" /etc/issue || grep -Eq "Fedora" /etc/*-release; then
DISTRO='Fedora'
release="centos"
systemPackage='yum'
elif grep -Eqi "Debian" /etc/issue || grep -Eq "Debian" /etc/*-release; then
DISTRO='Debian'
release="debian"
systemPackage='apt'
elif grep -Eqi "Ubuntu" /etc/issue || grep -Eq "Ubuntu" /etc/*-release; then
DISTRO='Ubuntu'
release="ubuntu"
systemPackage='apt'
elif grep -Eqi "Raspbian" /etc/issue || grep -Eq "Raspbian" /etc/*-release; then
DISTRO='Raspbian'
release="debian"
systemPackage='apt'
elif grep -Eqi "Deepin" /etc/issue || grep -Eq "Deepin" /etc/*-release; then
DISTRO='Deepin'
release="debian"
systemPackage='apt'
else
release='unknow'
fi
Get_OS_Bit
}
# Check OS bit
Get_OS_Bit(){
ARCHS=""
if [[ `getconf WORD_BIT` = '32' && `getconf LONG_BIT` = '64' ]] ; then
Is_64bit='y'
ARCHS="amd64"
else
Is_64bit='n'
ARCHS="386"
fi
}
# Check system
check_sys(){
local checkType=$1
local value=$2
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
}
# Get version
getversion(){
if [[ -s /etc/redhat-release ]]; then
grep -oE "[0-9.]+" /etc/redhat-release
else
grep -oE "[0-9.]+" /etc/issue
fi
}
# CentOS version
centosversion(){
if check_sys sysRelease centos; then
local code=$1
local version="$(getversion)"
local main_ver=${version%%.*}
if [ "$main_ver" == "$code" ]; then
return 0
else
return 1
fi
else
return 1
fi
}
get_opsy(){
[ -f /etc/redhat-release ] && awk '{print ($1,$3~/^[0-9]/?$3:$4)}' /etc/redhat-release && return
[ -f /etc/os-release ] && awk -F'[= "]' '/PRETTY_NAME/{print $3,$4,$5}' /etc/os-release && return
[ -f /etc/lsb-release ] && awk -F'[="]+' '/DESCRIPTION/{print $2}' /etc/lsb-release && return
}
debianversion(){
if check_sys sysRelease debian;then
local version=$( get_opsy )
local code=${1}
local main_ver=$( echo ${version} | sed 's/[^0-9]//g')
if [ "${main_ver}" == "${code}" ];then
return 0
else
return 1
fi
else
return 1
fi
}
Check_OS_support(){
# Check OS system
if [ "${release}" == "unknow" ]; then
echo
echo -e "${COLOR_RED}Error: Unable to get Linux distribution name, or do NOT support the current distribution.${COLOR_END}"
echo
exit 1
elif [ "${DISTRO}" == "CentOS" ]; then
if centosversion 5; then
echo
echo -e "${COLOR_RED}Not support CentOS 5, please change to CentOS 6 or 7 and try again.${COLOR_END}"
echo
exit 1
fi
fi
}
Press_Install(){
echo ""
echo -e "${COLOR_GREEN}Press any key to install...or Press Ctrl+c to cancel${COLOR_END}"
OLDCONFIG=`stty -g`
stty -icanon -echo min 1 time 0
dd count=1 2>/dev/null
stty ${OLDCONFIG}
}
Press_Start(){
echo ""
echo -e "${COLOR_GREEN}Press any key to continue...or Press Ctrl+c to cancel${COLOR_END}"
OLDCONFIG=`stty -g`
stty -icanon -echo min 1 time 0
dd count=1 2>/dev/null
stty ${OLDCONFIG}
}
Press_Exit(){
echo ""
echo -e "${COLOR_GREEN}Press any key to Exit...or Press Ctrl+c${COLOR_END}"
OLDCONFIG=`stty -g`
stty -icanon -echo min 1 time 0
dd count=1 2>/dev/null
stty ${OLDCONFIG}
}
Print_Sys_Info(){
cat /etc/issue
cat /etc/*-release
uname -a
MemTotal=`free -m | grep Mem | awk '{print $2}'`
echo "Memory is: ${MemTotal} MB "
df -h
}
Disable_Selinux(){
if [ -s /etc/selinux/config ]; then
sed -i 's/^SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config
fi
}
pre_install_packs(){
local wget_flag=''
local killall_flag=''
local netstat_flag=''
wget --version > /dev/null 2>&1
wget_flag=$?
killall -V >/dev/null 2>&1
killall_flag=$?
netstat --version >/dev/null 2>&1
netstat_flag=$?
if [[ ${wget_flag} -gt 1 ]] || [[ ${killall_flag} -gt 1 ]] || [[ ${netstat_flag} -gt 6 ]];then
echo -e "${COLOR_GREEN} Install support packs...${COLOR_END}"
if check_sys packageManager yum; then
yum install -y wget psmisc net-tools
elif check_sys packageManager apt; then
apt-get -y update && apt-get -y install wget psmisc net-tools
fi
fi
}
# Random password
fun_randstr(){
index=0
strRandomPass=""
for i in {a..z}; do arr[index]=$i; index=`expr ${index} + 1`; done
for i in {A..Z}; do arr[index]=$i; index=`expr ${index} + 1`; done
for i in {0..9}; do arr[index]=$i; index=`expr ${index} + 1`; done
for i in {1..16}; do strRandomPass="$strRandomPass${arr[$RANDOM%$index]}"; done
echo $strRandomPass
}
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 ip.clang.cn | sed -r 's/\r//')
[ -z ${IP} ] && IP=$(wget -qO- -t1 -T2 ipv4.icanhazip.com | sed -r 's/\r//')
[ ! -z ${IP} ] && echo ${IP} || echo
}
Dispaly_Selection(){
def_Install_Select="7"
echo -e "${COLOR_YELOW}You have 7 options for your kcptun/ss/ssr install.${COLOR_END}"
echo "1: Install Shadowsocks-libev"
echo "2: Install ShadowsocksR(python)"
echo "3: Install KCPTUN"
echo "4: Install Shadowsocks-libev + KCPTUN"
echo "5: Install ShadowsocksR(python) + KCPTUN"
echo "6: Install Shadowsocksrr(python)"
echo "7: Install Shadowsocksrr(python) + KCPTUN [default]"
read -p "Enter your choice (1, 2, 3, 4, 5, 6, 7 or exit. default [${def_Install_Select}]): " Install_Select
case "${Install_Select}" in
1)
echo
echo -e "${COLOR_PINK}You will install Shadowsocks-libev ${SS_LIBEV_VER}${COLOR_END}"
;;
2)
echo
echo -e "${COLOR_PINK}You will install ShadowsocksR(python) ${SSR_VER}${COLOR_END}"
;;
3)
echo
echo -e "${COLOR_PINK}You will install KCPTUN ${KCPTUN_VER}${COLOR_END}"
;;
4)
echo
echo -e "${COLOR_PINK}You will Install Shadowsocks-libev ${SS_LIBEV_VER} + KCPTUN ${KCPTUN_VER}${COLOR_END}"
;;
5)
echo
echo -e "${COLOR_PINK}You will install ShadowsocksR(python) ${SSR_VER} + KCPTUN ${KCPTUN_VER}${COLOR_END}"
;;
6)
echo
echo -e "${COLOR_PINK}You will install Shadowsocksrr(python) ${SSRR_VER}${COLOR_END}"
;;
7)
echo
echo -e "${COLOR_PINK}You will install Shadowsocksrr(python) ${SSRR_VER} + KCPTUN ${KCPTUN_VER}${COLOR_END}"
;;
[eE][xX][iI][tT])
echo -e "${COLOR_PINK}You select <Exit>, shell exit now!${COLOR_END}"
exit 1
;;
*)
echo
echo -e "${COLOR_PINK}No input,You will install Shadowsocksrr(python) + KCPTUN${COLOR_END}"
Install_Select="${def_Install_Select}"
esac
}
# Install cleanup
install_cleanup(){
cd ${cur_dir}
rm -rf .version.sh shadowsocks-libev-* manyuser.zip shadowsocksr-manyuser shadowsocks-manyuser kcptun-linux-* libsodium-* mbedtls-* shadowsocksr-akkariiin-master ssrr.zip
}
check_kcptun_for_ss_ssr_installed(){
ss_libev_installed_flag=""
ssr_installed_flag=""
ssrr_installed_flag=""
kcptun_installed_flag=""
kcptun_install_flag=""
ss_libev_install_flag=""
ssr_install_flag=""
ssrr_install_flag=""
if [ "${Install_Select}" == "1" ] || [ "${Install_Select}" == "4" ] || [ "${Update_Select}" == "1" ] || [ "${Update_Select}" == "5" ] || [ "${Uninstall_Select}" == "1" ] || [ "${Uninstall_Select}" == "5" ]; then
if [[ "$(command -v "ss-server")" ]] || [[ "$(command -v "/usr/local/bin/ss-server")" ]]; then
ss_libev_installed_flag="true"
else
ss_libev_installed_flag="false"
fi
fi
if [ "${Install_Select}" == "2" ] || [ "${Install_Select}" == "5" ] || [ "${Update_Select}" == "2" ] || [ "${Update_Select}" == "5" ] || [ "${Uninstall_Select}" == "2" ] || [ "${Uninstall_Select}" == "5" ]; then
if [[ -x /usr/local/shadowsocksR/shadowsocks/server.py ]] && [[ -s /usr/local/shadowsocksR/shadowsocks/__init__.py ]]; then
ssr_installed_flag="true"
else
ssr_installed_flag="false"
fi
fi
if [ "${Install_Select}" == "6" ] || [ "${Install_Select}" == "7" ] || [ "${Update_Select}" == "4" ] || [ "${Update_Select}" == "5" ] || [ "${Uninstall_Select}" == "4" ] || [ "${Uninstall_Select}" == "5" ]; then
if [[ -x /usr/local/shadowsocksrr/shadowsocks/server.py ]] && [[ -s /usr/local/shadowsocksrr/shadowsocks/__init__.py ]]; then
ssrr_installed_flag="true"
else
ssrr_installed_flag="false"
fi
fi
if [ "${Install_Select}" == "3" ] || [ "${Install_Select}" == "4" ] || [ "${Install_Select}" == "5" ] || [ "${Install_Select}" == "7" ] || [ "${Update_Select}" == "3" ] || [ "${Update_Select}" == "5" ] || [ "${Uninstall_Select}" == "3" ] || [ "${Uninstall_Select}" == "5" ]; then
if [[ "$(command -v "/usr/local/kcptun/kcptun")" ]] || [[ "$(command -v "kcptun")" ]]; then
kcptun_installed_flag="true"
else
kcptun_installed_flag="false"
fi
fi
}
get_install_version(){
rm -f ${cur_dir}/.version.sh
if ! wget --no-check-certificate -qO ${cur_dir}/.version.sh ${program_version_link}; then
echo -e "${COLOR_RED}Failed to download version.sh${COLOR_END}"
fi
if [ -s ${cur_dir}/.version.sh ]; then
[ -x ${cur_dir}/.version.sh ] && chmod +x ${cur_dir}/.version.sh
. ${cur_dir}/.version.sh
fi
if [ -z ${LIBSODIUM_VER} ] || [ -z ${MBEDTLS_VER} ] || [ -z ${SS_LIBEV_VER} ] || [ -z ${SSR_VER} ] || [ -z ${SSRR_VER} ] || [ -z ${KCPTUN_VER} ]; then
echo -e "${COLOR_RED}Error: ${COLOR_END}Get Program version failed!"
exit 1
fi
}
get_latest_version(){
rm -f ${cur_dir}/.api_*.txt
if [[ "${ss_libev_installed_flag}" == "false" && "${clang_action}" =~ ^[Ii]|[Ii][Nn]|[Ii][Nn][Ss][Tt][Aa][Ll][Ll]|-[Ii]|--[Ii]$ ]] || [[ "${ss_libev_installed_flag}" == "true" && "${clang_action}" =~ ^[Uu]|[Uu][Pp][Dd][Aa][Tt][Ee]|-[Uu]|--[Uu]|[Uu][Pp]|-[Uu][Pp]|--[Uu][Pp]$ ]]; then
echo -e "Loading SS-libev version, please wait..."
if check_sys packageManager yum; then
ss_libev_init_link="${SS_LIBEV_YUM_INIT}"
elif check_sys packageManager apt; then
ss_libev_init_link="${SS_LIBEV_APT_INIT}"
fi
shadowsocks_libev_ver="shadowsocks-libev-${SS_LIBEV_VER}"
if [[ "${ss_libev_installed_flag}" == "false" && "${clang_action}" =~ ^[Ii]|[Ii][Nn]|[Ii][Nn][Ss][Tt][Aa][Ll][Ll]|-[Ii]|--[Ii]$ ]]; then
echo -e "Get the ss-libev version:${COLOR_GREEN} ${SS_LIBEV_VER}${COLOR_END}"
fi
fi
if [ ! -f /usr/lib/libsodium.a ] && [ ! -L /usr/local/lib/libsodium.so ]; then
#echo -e "Loading libsodium version, please wait..."
libsodium_laster_ver="libsodium-${LIBSODIUM_VER}"
if [ "${libsodium_laster_ver}" == "" ] || [ "${LIBSODIUM_LINK}" == "" ]; then
echo -e "${COLOR_RED}Error: Get libsodium version failed${COLOR_END}"
exit 1
fi
#echo -e "Get the libsodium version:${COLOR_GREEN} ${LIBSODIUM_VER}${COLOR_END}"
fi
if [ ! -f /usr/lib/libmbedtls.a ] && [ ! -f /usr/include/mbedtls/version.h ]; then
#echo -e "Loading mbedtls version, please wait..."
mbedtls_laster_ver="mbedtls-${MBEDTLS_VER}"
if [ "${mbedtls_laster_ver}" == "" ] || [ "${MBEDTLS_LINK}" == "" ]; then
echo -e "${COLOR_RED}Error: Get mbedtls version failed${COLOR_END}"
exit 1
fi
#echo -e "Get the mbedtls version:${COLOR_GREEN} ${MBEDTLS_VER}${COLOR_END}"
fi
if [[ "${ssr_installed_flag}" == "false" && "${clang_action}" =~ ^[Ii]|[Ii][Nn]|[Ii][Nn][Ss][Tt][Aa][Ll][Ll]|-[Ii]|--[Ii]$ ]] || [[ "${ssr_installed_flag}" == "true" && "${clang_action}" =~ ^[Uu]|[Uu][Pp][Dd][Aa][Tt][Ee]|-[Uu]|--[Uu]|[Uu][Pp]|-[Uu][Pp]|--[Uu][Pp]$ ]]; then
echo -e "Loading ShadowsocksR version, please wait..."
ssr_download_link="${SSR_LINK}"
ssr_latest_ver="${SSR_VER}"
if check_sys packageManager yum; then
ssr_init_link="${SSR_YUM_INIT}"
elif check_sys packageManager apt; then
ssr_init_link="${SSR_APT_INIT}"
fi
if [[ "${ssr_installed_flag}" == "false" && "${clang_action}" =~ ^[Ii]|[Ii][Nn]|[Ii][Nn][Ss][Tt][Aa][Ll][Ll]|-[Ii]|--[Ii]$ ]]; then
echo -e "Get the ShadowsocksR version:${COLOR_GREEN} ${SSR_VER}${COLOR_END}"
fi
fi
if [[ "${ssrr_installed_flag}" == "false" && "${clang_action}" =~ ^[Ii]|[Ii][Nn]|[Ii][Nn][Ss][Tt][Aa][Ll][Ll]|-[Ii]|--[Ii]$ ]] || [[ "${ssrr_installed_flag}" == "true" && "${clang_action}" =~ ^[Uu]|[Uu][Pp][Dd][Aa][Tt][Ee]|-[Uu]|--[Uu]|[Uu][Pp]|-[Uu][Pp]|--[Uu][Pp]$ ]]; then
echo -e "Loading Shadowsocksrr version, please wait..."
ssrr_download_link="${SSRR_LINK}"
ssrr_latest_ver="${SSRR_VER}"
if check_sys packageManager yum; then
ssrr_init_link="${SSRR_YUM_INIT}"
elif check_sys packageManager apt; then
ssrr_init_link="${SSRR_APT_INIT}"
fi
if [[ "${ssrr_installed_flag}" == "false" && "${clang_action}" =~ ^[Ii]|[Ii][Nn]|[Ii][Nn][Ss][Tt][Aa][Ll][Ll]|-[Ii]|--[Ii]$ ]]; then
echo -e "Get the Shadowsocksrr version:${COLOR_GREEN} ${SSRR_VER}${COLOR_END}"
fi
fi
if [[ "${kcptun_installed_flag}" == "false" && "${clang_action}" =~ ^[Ii]|[Ii][Nn]|[Ii][Nn][Ss][Tt][Aa][Ll][Ll]|-[Ii]|--[Ii]$ ]] || [[ "${kcptun_installed_flag}" == "true" && "${clang_action}" =~ ^[Uu]|[Uu][Pp][Dd][Aa][Tt][Ee]|-[Uu]|--[Uu]|[Uu][Pp]|-[Uu][Pp]|--[Uu][Pp]$ ]]; then
echo -e "Loading kcptun version, please wait..."
kcptun_init_link="${KCPTUN_INIT}"
kcptun_latest_file="kcptun-linux-${ARCHS}-${KCPTUN_VER}.tar.gz"
if [[ `getconf WORD_BIT` = '32' && `getconf LONG_BIT` = '64' ]] ; then
kcptun_download_link="${KCPTUN_AMD64_LINK}"
else
kcptun_download_link="${KCPTUN_386_LINK}"
fi
if [[ "${kcptun_init_link}" == "" || "${kcptun_download_link}" == "" ]]; then
echo -e "${COLOR_RED}Error: Get kcptun version failed${COLOR_END}"
exit 1
fi
if [[ "${kcptun_installed_flag}" == "false" && "${clang_action}" =~ ^[Ii]|[Ii][Nn]|[Ii][Nn][Ss][Tt][Aa][Ll][Ll]|-[Ii]|--[Ii]$ ]]; then
echo -e "Get the kcptun version:${COLOR_GREEN} ${kcptun_latest_file}${COLOR_END}"
fi
fi
}
# Download latest
down_kcptun_for_ss_ssr(){
if [ ! -f /usr/lib/libsodium.a ] && [ ! -L /usr/local/lib/libsodium.so ]; then
if [ -f ${libsodium_laster_ver}.tar.gz ]; then
echo "${libsodium_laster_ver}.tar.gz [found]"
else
if ! wget --no-check-certificate -O ${libsodium_laster_ver}.tar.gz ${LIBSODIUM_LINK}; then
echo -e "${COLOR_RED}Failed to download ${libsodium_laster_ver}.tar.gz${COLOR_END}"
exit 1
fi
fi
fi
if [[ "${ss_libev_installed_flag}" == "false" && "${clang_action}" =~ ^[Ii]|[Ii][Nn]|[Ii][Nn][Ss][Tt][Aa][Ll][Ll]|-[Ii]|--[Ii]$ ]] || [[ "${ss_libev_installed_flag}" == "true" && "${ss_libev_update_flag}" == "true" && "${clang_action}" =~ ^[Uu]|[Uu][Pp][Dd][Aa][Tt][Ee]|-[Uu]|--[Uu]|[Uu][Pp]|-[Uu][Pp]|--[Uu][Pp]$ ]]; then
if [ -f ${shadowsocks_libev_ver}.tar.gz ]; then
echo "${shadowsocks_libev_ver}.tar.gz [found]"
else
if ! wget --no-check-certificate -O ${shadowsocks_libev_ver}.tar.gz ${SS_LIBEV_LINK}; then
echo -e "${COLOR_RED}Failed to download ${shadowsocks_libev_ver}.tar.gz${COLOR_END}"
exit 1
fi
fi
# Download init script
if ! wget --no-check-certificate -O /etc/init.d/shadowsocks ${ss_libev_init_link}; then
echo -e "${COLOR_RED}Failed to download shadowsocks-libev init script!${COLOR_END}"
exit 1
fi
if [ ! -f /usr/lib/libmbedtls.a ] && [ ! -f /usr/include/mbedtls/version.h ]; then
if [ -f ${mbedtls_laster_ver}-gpl.tgz ]; then
echo "${mbedtls_laster_ver}-gpl.tgz [found]"
else
if ! wget --no-check-certificate -O ${mbedtls_laster_ver}-gpl.tgz ${MBEDTLS_LINK}; then
echo -e "${COLOR_RED}Failed to download ${mbedtls_laster_ver}-gpl.tgz${COLOR_END}"
exit 1
fi
fi
fi
fi
if [[ "${ssr_installed_flag}" == "false" && "${clang_action}" =~ ^[Ii]|[Ii][Nn]|[Ii][Nn][Ss][Tt][Aa][Ll][Ll]|-[Ii]|--[Ii]$ ]] || [[ "${ssr_installed_flag}" == "true" && "${ssr_update_flag}" == "true" && "${clang_action}" =~ ^[Uu]|[Uu][Pp][Dd][Aa][Tt][Ee]|-[Uu]|--[Uu]|[Uu][Pp]|-[Uu][Pp]|--[Uu][Pp]$ ]]; then
if [ -f manyuser.zip ]; then
echo "manyuser.zip [found]"
else
if ! wget --no-check-certificate -O manyuser.zip ${ssr_download_link}; then
echo -e "${COLOR_RED}Failed to download ShadowsocksR file!${COLOR_END}"
exit 1
fi
fi
if ! wget --no-check-certificate -O /etc/init.d/ssr ${ssr_init_link}; then
echo -e "${COLOR_RED}Failed to download ShadowsocksR init script!${COLOR_END}"
exit 1
fi
fi
if [[ "${ssrr_installed_flag}" == "false" && "${clang_action}" =~ ^[Ii]|[Ii][Nn]|[Ii][Nn][Ss][Tt][Aa][Ll][Ll]|-[Ii]|--[Ii]$ ]] || [[ "${ssrr_installed_flag}" == "true" && "${ssrr_update_flag}" == "true" && "${clang_action}" =~ ^[Uu]|[Uu][Pp][Dd][Aa][Tt][Ee]|-[Uu]|--[Uu]|[Uu][Pp]|-[Uu][Pp]|--[Uu][Pp]$ ]]; then
if [ -f ssrr.zip ]; then
echo "ssrr.zip [found]"
else
if ! wget --no-check-certificate -O ssrr.zip ${ssrr_download_link}; then
echo -e "${COLOR_RED}Failed to download Shadowsocksrr file!${COLOR_END}"
exit 1
fi
fi
if ! wget --no-check-certificate -O /etc/init.d/ssrr ${ssrr_init_link}; then
echo -e "${COLOR_RED}Failed to download Shadowsocksrr init script!${COLOR_END}"
exit 1
fi
fi
if [[ "${kcptun_installed_flag}" == "false" && "${clang_action}" =~ ^[Ii]|[Ii][Nn]|[Ii][Nn][Ss][Tt][Aa][Ll][Ll]|-[Ii]|--[Ii]$ ]] || [[ "${kcptun_installed_flag}" == "true" && "${kcptun_update_flag}" == "true" && "${clang_action}" =~ ^[Uu]|[Uu][Pp][Dd][Aa][Tt][Ee]|-[Uu]|--[Uu]|[Uu][Pp]|-[Uu][Pp]|--[Uu][Pp]$ ]]; then
if [ -f ${kcptun_latest_file} ]; then
echo "${kcptun_latest_file} [found]"
else
if ! wget --no-check-certificate -O ${kcptun_latest_file} ${kcptun_download_link}; then
echo -e "${COLOR_RED}Failed to download ${kcptun_latest_file}${COLOR_END}"
exit 1
fi
fi
if ! wget --no-check-certificate -O /etc/init.d/kcptun ${kcptun_init_link}; then
echo -e "${COLOR_RED}Failed to download kcptun init script!${COLOR_END}"
exit 1
fi
fi
}
config_kcptun_for_ss_ssr(){
if [[ "${ss_libev_installed_flag}" == "false" && "${clang_action}" =~ ^[Ii]|[Ii][Nn]|[Ii][Nn][Ss][Tt][Aa][Ll][Ll]|-[Ii]|--[Ii]$ ]]; then
[ ! -d /etc/shadowsocks-libev ] && mkdir -p /etc/shadowsocks-libev
cat > ${ss_libev_config}<<-EOF
{
"server":"0.0.0.0",
"server_port":${set_ss_libev_port},
"local_address":"127.0.0.1",
"local_port":${ss_libev_local_port},
"password":"${set_ss_libev_pwd}",
"timeout":600,
"method":"${set_ss_libev_method}"
}
EOF
fi
if [[ "${ssr_installed_flag}" == "false" && "${clang_action}" =~ ^[Ii]|[Ii][Nn]|[Ii][Nn][Ss][Tt][Aa][Ll][Ll]|-[Ii]|--[Ii]$ ]]; then
[ ! -d /usr/local/shadowsocksR ] && mkdir -p /usr/local/shadowsocksR
cat > ${ssr_config}<<-EOF
{
"server":"0.0.0.0",
"local_address":"127.0.0.1",
"local_port":${ssr_local_port},
"port_password":{
"${set_ssr_port}":"${set_ssr_pwd}"
},
"timeout":120,
"method":"${set_ssr_method}",
"protocol":"${set_ssr_protocol}",
"protocol_param":"",
"obfs":"${set_ssr_obfs}",
"obfs_param":"",
"redirect":"",
"dns_ipv6":false,
"fast_open":false,
"workers":1
}
EOF
fi
if [[ "${ssrr_installed_flag}" == "false" && "${clang_action}" =~ ^[Ii]|[Ii][Nn]|[Ii][Nn][Ss][Tt][Aa][Ll][Ll]|-[Ii]|--[Ii]$ ]]; then
[ ! -d /usr/local/shadowsocksrr ] && mkdir -p /usr/local/shadowsocksrr
cat > ${ssrr_config}<<-EOF
{
"server":"0.0.0.0",
"server_ipv6":"::",
"local_address":"127.0.0.1",
"local_port":${ssrr_local_port},
"port_password":{
"${set_ssrr_port}":{"protocol":"${set_ssrr_protocol}", "protocol_param":"", "password":"${set_ssrr_pwd}", "obfs":"${set_ssrr_obfs}", "obfs_param":""}
},
"timeout":300,
"method":"${set_ssrr_method}",
"redirect": "",
"dns_ipv6": false,
"fast_open": false,
"workers": 1
}
EOF
fi
if [[ "${kcptun_installed_flag}" == "false" && "${clang_action}" =~ ^[Ii]|[Ii][Nn]|[Ii][Nn][Ss][Tt][Aa][Ll][Ll]|-[Ii]|--[Ii]$ ]]; then
[ ! -d /usr/local/kcptun ] && mkdir -p /usr/local/kcptun
# Config file
cat > ${kcptun_config}<<-EOF
{
"listen": ":${set_kcptun_port}",
"target": "127.0.0.1:${kcptun_target_port}",
"key": "${set_kcptun_pwd}",
"crypt": "${set_kcptun_method}",
"mode": "${set_kcptun_mode}",
"mtu": ${set_kcptun_mtu},
"sndwnd": 1024,
"rcvwnd": 1024,
"nocomp": ${set_kcptun_nocomp}
}
EOF
fi
}
install_kcptun_for_ss_ssr(){
#if [[ "${ss_libev_installed_flag}" == "false" && "${clang_action}" =~ ^[Ii]|[Ii][Nn]|[Ii][Nn][Ss][Tt][Aa][Ll][Ll]|-[Ii]|--[Ii]$ ]] || [[ "${ssr_installed_flag}" == "false" && "${clang_action}" =~ ^[Ii]|[Ii][Nn]|[Ii][Nn][Ss][Tt][Aa][Ll][Ll]|-[Ii]|--[Ii]$ ]] || [[ "${kcptun_installed_flag}" == "false" && "${clang_action}" =~ ^[Ii]|[Ii][Nn]|[Ii][Nn][Ss][Tt][Aa][Ll][Ll]|-[Ii]|--[Ii]$ ]]; then
if check_sys packageManager yum; then
yum install -y epel-release
yum install -y unzip openssl-devel gcc swig autoconf libtool libevent vim automake make psmisc curl curl-devel zlib-devel perl perl-devel cpio expat-devel gettext-devel xmlto asciidoc pcre pcre-devel python python-devel python-setuptools udns-devel libev-devel c-ares-devel mbedtls-devel
if [ $? -gt 1 ]; then
echo
echo -e "${COLOR_RED}Install support packs failed!${COLOR_END}"
exit 1
fi
elif check_sys packageManager apt; then
if debianversion 7; then
grep "jessie" /etc/apt/sources.list > /dev/null 2>&1
if [ $? -ne 0 ] && [ -r /etc/apt/sources.list ]; then
echo "deb http://http.us.debian.org/debian jessie main" >> /etc/apt/sources.list
fi
fi
apt-get -y update && apt-get -y install --no-install-recommends gettext curl wget vim unzip psmisc gcc swig autoconf automake make perl cpio build-essential libtool openssl libssl-dev zlib1g-dev xmlto asciidoc libpcre3 libpcre3-dev python python-dev python-pip python-m2crypto libev-dev libc-ares-dev libudns-dev
if [ $? -gt 1 ]; then
echo
echo -e "${COLOR_RED}Install support packs failed!${COLOR_END}"
exit 1
fi
fi
#fi
if [ ! -f /usr/lib/libsodium.a ] && [ ! -L /usr/local/lib/libsodium.so ]; then
cd ${cur_dir}
echo "+ Install libsodium for SS-Libev/SSR/KCPTUN"
tar xzf ${libsodium_laster_ver}.tar.gz
cd ${libsodium_laster_ver}
./configure --prefix=/usr && make && make install
if [ $? -ne 0 ]; then
install_cleanup
echo -e "${COLOR_RED}libsodium install failed!${COLOR_END}"
exit 1
fi
ldconfig
#echo "/usr/lib" > /etc/ld.so.conf.d/local.conf
fi
if [[ "${ss_libev_installed_flag}" == "false" && "${clang_action}" =~ ^[Ii]|[Ii][Nn]|[Ii][Nn][Ss][Tt][Aa][Ll][Ll]|-[Ii]|--[Ii]$ ]] || [[ "${ss_libev_installed_flag}" == "true" && "${ss_libev_update_flag}" == "true" && "${clang_action}" =~ ^[Uu]|[Uu][Pp][Dd][Aa][Tt][Ee]|-[Uu]|--[Uu]|[Uu][Pp]|-[Uu][Pp]|--[Uu][Pp]$ ]]; then
if check_sys packageManager yum; then
echo "+ Install mbedtls for SS-Liber..."
yum install -y mbedtls-devel
if [ $? -ne 0 ]; then
install_cleanup
echo -e "${COLOR_RED}mbedtls install failed!${COLOR_END}"
exit 1
fi
elif check_sys packageManager apt; then
if [ ! -f /usr/lib/libmbedtls.a ]; then
cd ${cur_dir}
echo "+ Install mbedtls for SS-Liber..."
tar xzf ${mbedtls_laster_ver}-gpl.tgz
cd ${mbedtls_laster_ver}
make SHARED=1 CFLAGS=-fPIC && make DESTDIR=/usr install
if [ $? -ne 0 ]; then
install_cleanup
echo -e "${COLOR_RED}mbedtls install failed!${COLOR_END}"
exit 1
fi
ldconfig
fi
fi
cd ${cur_dir}
tar zxf ${shadowsocks_libev_ver}.tar.gz
cd ${shadowsocks_libev_ver}
./configure
make && make install
if [ $? -eq 0 ]; then
chmod +x /etc/init.d/shadowsocks
if check_sys packageManager yum; then
chkconfig --add shadowsocks
chkconfig shadowsocks on
elif check_sys packageManager apt; then
update-rc.d -f shadowsocks defaults
fi
# Run shadowsocks in the background
/etc/init.d/shadowsocks start
if [ $? -eq 0 ]; then
[ -x /etc/init.d/shadowsocks ] && ln -s /etc/init.d/shadowsocks /usr/bin/shadowsocks
echo -e "${COLOR_GREEN}Shadowsocks-libev start success!${COLOR_END}"
else
echo -e "${COLOR_RED}Shadowsocks-libev start failure!${COLOR_END}"
fi
ss_libev_install_flag="true"
else
install_cleanup
echo
echo -e "${COLOR_RED}Shadowsocks-libev install failed! Please visit ${contact_us} and contact.${COLOR_END}"
exit 1
fi
fi
if [[ "${ssr_installed_flag}" == "false" && "${clang_action}" =~ ^[Ii]|[Ii][Nn]|[Ii][Nn][Ss][Tt][Aa][Ll][Ll]|-[Ii]|--[Ii]$ ]] || [[ "${ssr_installed_flag}" == "true" && "${ssr_update_flag}" == "true" && "${clang_action}" =~ ^[Uu]|[Uu][Pp][Dd][Aa][Tt][Ee]|-[Uu]|--[Uu]|[Uu][Pp]|-[Uu][Pp]|--[Uu][Pp]$ ]]; then
cd ${cur_dir}
unzip -qo manyuser.zip
mv shadowsocksr-manyuser/shadowsocks/ /usr/local/shadowsocksR
if [ -x /usr/local/shadowsocksR/shadowsocks/server.py ] && [ -s /usr/local/shadowsocksR/shadowsocks/__init__.py ]; then
chmod +x /etc/init.d/ssr
if check_sys packageManager yum; then
chkconfig --add ssr
chkconfig ssr on
elif check_sys packageManager apt; then
update-rc.d -f ssr defaults
fi
/etc/init.d/ssr start
if [ $? -eq 0 ]; then
[ -x /etc/init.d/ssr ] && ln -s /etc/init.d/ssr /usr/bin/ssr
echo -e "${COLOR_GREEN}ShadowsocksR start success!${COLOR_END}"
else
echo -e "${COLOR_RED}ShadowsocksR start failure!${COLOR_END}"
fi
ssr_install_flag="true"
else
install_cleanup
echo
echo -e "${COLOR_RED}ShadowsocksR install failed! Please visit ${contact_us} and contact.${COLOR_END}"
exit 1
fi
fi
if [[ "${ssrr_installed_flag}" == "false" && "${clang_action}" =~ ^[Ii]|[Ii][Nn]|[Ii][Nn][Ss][Tt][Aa][Ll][Ll]|-[Ii]|--[Ii]$ ]] || [[ "${ssrr_installed_flag}" == "true" && "${ssrr_update_flag}" == "true" && "${clang_action}" =~ ^[Uu]|[Uu][Pp][Dd][Aa][Tt][Ee]|-[Uu]|--[Uu]|[Uu][Pp]|-[Uu][Pp]|--[Uu][Pp]$ ]]; then
cd ${cur_dir}
unzip -qo ssrr.zip
mv shadowsocksr-akkariiin-master/* /usr/local/shadowsocksrr/
if [ -x /usr/local/shadowsocksrr/shadowsocks/server.py ] && [ -s /usr/local/shadowsocksrr/shadowsocks/__init__.py ]; then
chmod +x /etc/init.d/ssrr
if check_sys packageManager yum; then
chkconfig --add ssrr
chkconfig ssrr on
elif check_sys packageManager apt; then
update-rc.d -f ssrr defaults
fi
/etc/init.d/ssrr start
if [ $? -eq 0 ]; then
[ -x /etc/init.d/ssrr ] && ln -s /etc/init.d/ssrr /usr/bin/ssrr
echo -e "${COLOR_GREEN}Shadowsocksrr start success!${COLOR_END}"
else
echo -e "${COLOR_RED}Shadowsocksrr start failure!${COLOR_END}"
fi
ssrr_install_flag="true"
else
install_cleanup
echo
echo -e "${COLOR_RED}Shadowsocksrr install failed! Please visit ${contact_us} and contact.${COLOR_END}"
exit 1
fi
fi
if [[ "${kcptun_installed_flag}" == "false" && "${clang_action}" =~ ^[Ii]|[Ii][Nn]|[Ii][Nn][Ss][Tt][Aa][Ll][Ll]|-[Ii]|--[Ii]$ ]] || [[ "${kcptun_installed_flag}" == "true" && "${kcptun_update_flag}" == "true" && "${clang_action}" =~ ^[Uu]|[Uu][Pp][Dd][Aa][Tt][Ee]|-[Uu]|--[Uu]|[Uu][Pp]|-[Uu][Pp]|--[Uu][Pp]$ ]]; then
cd ${cur_dir}
tar xzf ${kcptun_latest_file}
[ ! -d /usr/local/kcptun ] && mkdir -p /usr/local/kcptun
mv server_linux_${ARCHS} /usr/local/kcptun/kcptun
rm -f ${kcptun_latest_file} client_linux_${ARCHS}
chown root:root /usr/local/kcptun/*
[ ! -x /usr/local/kcptun/kcptun ] && chmod 755 /usr/local/kcptun/kcptun
/usr/local/kcptun/kcptun --version
if [ $? -eq 0 ]; then
chmod +x /etc/init.d/kcptun
if check_sys packageManager yum; then
chkconfig --add kcptun
chkconfig kcptun on
elif check_sys packageManager apt; then
update-rc.d -f kcptun defaults
fi
/etc/init.d/kcptun start
if [ $? -eq 0 ]; then
[ -x /etc/init.d/kcptun ] && ln -s /etc/init.d/kcptun /usr/bin/kcptun
echo -e "${COLOR_GREEN}kcptun start success!${COLOR_END}"
else
echo -e "${COLOR_RED}kcptun start failure!${COLOR_END}"
fi
kcptun_install_flag="true"
else
install_cleanup
echo
echo -e "${COLOR_RED}kcptun install failed! Please visit ${contact_us} and contact.${COLOR_END}"
exit 1
fi
fi
install_cleanup
}
# Firewall set
firewall_set(){
if [ "${kcptun_install_flag}" == "true" ] || [ "${ss_libev_install_flag}" == "true" ] || [ "${ssr_install_flag}" == "true" ] || [ "${ssrr_install_flag}" == "true" ]; then
echo "+ firewall set start..."
firewall_set_flag="false"
if centosversion 6; then
/etc/init.d/iptables status > /dev/null 2>&1
if [ $? -eq 0 ]; then
if [ "${ss_libev_install_flag}" == "true" ]; then
iptables -L -n | grep -i ${set_ss_libev_port} > /dev/null 2>&1
if [ $? -ne 0 ]; then
iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport ${set_ss_libev_port} -j ACCEPT
iptables -I INPUT -m state --state NEW -m udp -p udp --dport ${set_ss_libev_port} -j ACCEPT
firewall_set_flag="true"
else
echo "+ port ${set_ss_libev_port} has been set up."
fi
fi
if [ "${ssr_install_flag}" == "true" ]; then
iptables -L -n | grep -i ${set_ssr_port} > /dev/null 2>&1
if [ $? -ne 0 ]; then
iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport ${set_ssr_port} -j ACCEPT
iptables -I INPUT -m state --state NEW -m udp -p udp --dport ${set_ssr_port} -j ACCEPT
firewall_set_flag="true"
else
echo "+ port ${set_ssr_port} has been set up."
fi
fi
if [ "${ssrr_install_flag}" == "true" ]; then
iptables -L -n | grep -i ${set_ssrr_port} > /dev/null 2>&1
if [ $? -ne 0 ]; then
iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport ${set_ssrr_port} -j ACCEPT
iptables -I INPUT -m state --state NEW -m udp -p udp --dport ${set_ssrr_port} -j ACCEPT
firewall_set_flag="true"
else
echo "+ port ${set_ssrr_port} has been set up."
fi
fi
if [ "${kcptun_install_flag}" == "true" ]; then
iptables -L -n | grep -i ${set_kcptun_port} > /dev/null 2>&1
if [ $? -ne 0 ]; then
iptables -I INPUT -m state --state NEW -m udp -p udp --dport ${set_kcptun_port} -j ACCEPT
firewall_set_flag="true"
else
echo "+ port ${set_kcptun_port} has been set up."
fi
fi
if [ "${firewall_set_flag}" == "true" ]; then
/etc/init.d/iptables save
/etc/init.d/iptables restart
fi
else
echo "WARNING: iptables looks like shutdown or not installed, please manually set it if necessary."
fi
elif centosversion 7; then
systemctl status firewalld > /dev/null 2>&1
if [ $? -eq 0 ]; then
if [ "${ss_libev_install_flag}" == "true" ]; then
firewall-cmd --permanent --zone=public --add-port=${set_ss_libev_port}/tcp
firewall-cmd --permanent --zone=public --add-port=${set_ss_libev_port}/udp
firewall_set_flag="true"
fi
if [ "${ssr_install_flag}" == "true" ]; then
firewall-cmd --permanent --zone=public --add-port=${set_ssr_port}/tcp
firewall-cmd --permanent --zone=public --add-port=${set_ssr_port}/udp
firewall_set_flag="true"
fi
if [ "${ssrr_install_flag}" == "true" ]; then
firewall-cmd --permanent --zone=public --add-port=${set_ssrr_port}/tcp
firewall-cmd --permanent --zone=public --add-port=${set_ssrr_port}/udp
firewall_set_flag="true"
fi
if [ "${kcptun_install_flag}" == "true" ]; then
firewall-cmd --permanent --zone=public --add-port=${set_kcptun_port}/udp
firewall_set_flag="true"
fi
if [ "${firewall_set_flag}" == "true" ]; then
firewall-cmd --reload
fi
else
echo "+ Firewalld looks like not running, try to start..."
systemctl start firewalld
if [ $? -eq 0 ]; then
if [ "${ss_libev_install_flag}" == "true" ]; then
firewall-cmd --permanent --zone=public --add-port=${set_ss_libev_port}/tcp
firewall-cmd --permanent --zone=public --add-port=${set_ss_libev_port}/udp
firewall_set_flag="true"
fi
if [ "${ssr_install_flag}" == "true" ]; then
firewall-cmd --permanent --zone=public --add-port=${set_ssr_port}/tcp
firewall-cmd --permanent --zone=public --add-port=${set_ssr_port}/udp
firewall_set_flag="true"
fi
if [ "${ssrr_install_flag}" == "true" ]; then
firewall-cmd --permanent --zone=public --add-port=${set_ssrr_port}/tcp
firewall-cmd --permanent --zone=public --add-port=${set_ssrr_port}/udp
firewall_set_flag="true"
fi
if [ "${kcptun_install_flag}" == "true" ]; then
firewall-cmd --permanent --zone=public --add-port=${set_kcptun_port}/udp
firewall_set_flag="true"
fi
if [ "${firewall_set_flag}" == "true" ]; then
firewall-cmd --reload
fi
else
echo "WARNING: Try to start firewalld failed. please enable port manually if necessary."
fi
fi
fi
echo "+ firewall set completed..."
fi
}
show_kcptun_for_ss_ssr(){
echo
if [ "${kcptun_install_flag}" == "true" ] || [ "${ss_libev_install_flag}" == "true" ] || [ "${ssr_install_flag}" == "true" ] || [ "${ssrr_install_flag}" == "true" ]; then
SERVER_IP=$(get_ip)
fun_clangcn
echo "Congratulations, install completed!"
echo -e "========================= Your Server Setting ========================="
echo -e "Your Server IP: ${COLOR_GREEN}${SERVER_IP}${COLOR_END}"
fi
if [ "${ss_libev_install_flag}" == "true" ]; then
echo "-------------------- SS-libev Setting --------------------"
echo -e "SS-libev configure file : ${COLOR_GREEN}${ss_libev_config}${COLOR_END}"
echo -e "SS-libev Server Port : ${COLOR_GREEN}${set_ss_libev_port}${COLOR_END}"
echo -e "SS-libev Password : ${COLOR_GREEN}${set_ss_libev_pwd}${COLOR_END}"
echo -e "SS-libev Encryption Method : ${COLOR_GREEN}${set_ss_libev_method}${COLOR_END}"
#echo -e "SS-libev Local IP : ${COLOR_GREEN}127.0.0.1${COLOR_END}"
#echo -e "SS-libev Local Port : ${COLOR_GREEN}${ss_libev_local_port}${COLOR_END}"
echo "----------------------------------------------------------"
echo -e "SS-libev status manage: ${COLOR_PINK}/etc/init.d/shadowsocks${COLOR_END} {${COLOR_GREEN}start|stop|restart|status|config|version${COLOR_END}}"
echo "=========================================================="
fi
if [ "${ssr_install_flag}" == "true" ]; then
echo "-------------------- ShadowsocksR Setting --------------------"
echo -e "SSR configure file : ${COLOR_GREEN}${ssr_config}${COLOR_END}"
echo -e "SSR Server Port : ${COLOR_GREEN}${set_ssr_port}${COLOR_END}"
echo -e "SSR Password : ${COLOR_GREEN}${set_ssr_pwd}${COLOR_END}"
echo -e "SSR Encryption Method : ${COLOR_GREEN}${set_ssr_method}${COLOR_END}"
echo -e "SSR protocol : ${COLOR_GREEN}${set_ssr_protocol}${COLOR_END}"
echo -e "SSR obfs : ${COLOR_GREEN}${set_ssr_obfs}${COLOR_END}"
#echo -e "SSR Local IP : ${COLOR_GREEN}127.0.0.1${COLOR_END}"
#echo -e "SSR Local Port : ${COLOR_GREEN}${ssr_local_port}${COLOR_END}"
echo "----------------------------------------------------------"
echo -e "SSR status manage: ${COLOR_PINK}/etc/init.d/ssr${COLOR_END} {${COLOR_GREEN}start|stop|restart|status|config|version${COLOR_END}}"
echo "=========================================================="
fi
if [ "${ssrr_install_flag}" == "true" ]; then
echo "-------------------- Shadowsocksrr Setting --------------------"
echo -e "SSRR configure file : ${COLOR_GREEN}${ssrr_config}${COLOR_END}"
echo -e "SSRR Server Port : ${COLOR_GREEN}${set_ssrr_port}${COLOR_END}"
echo -e "SSRR Password : ${COLOR_GREEN}${set_ssrr_pwd}${COLOR_END}"
echo -e "SSRR Encryption Method : ${COLOR_GREEN}${set_ssrr_method}${COLOR_END}"
echo -e "SSRR protocol : ${COLOR_GREEN}${set_ssrr_protocol}${COLOR_END}"
echo -e "SSRR obfs : ${COLOR_GREEN}${set_ssrr_obfs}${COLOR_END}"
#echo -e "SSRR Local IP : ${COLOR_GREEN}127.0.0.1${COLOR_END}"
#echo -e "SSRR Local Port : ${COLOR_GREEN}${ssrr_local_port}${COLOR_END}"
echo "----------------------------------------------------------"
echo -e "SSRR status manage: ${COLOR_PINK}/etc/init.d/ssrr${COLOR_END} {${COLOR_GREEN}start|stop|restart|status|config|version${COLOR_END}}"
echo "=========================================================="
fi
if [ "${kcptun_install_flag}" == "true" ]; then
echo "-------------------- KCPTUN Setting --------------------"
echo -e "Kcptun configure file : ${COLOR_GREEN}${kcptun_config}${COLOR_END}"
echo -e "Kcptun Server Port : ${COLOR_GREEN}${set_kcptun_port}${COLOR_END}"
echo -e "Kcptun Key : ${COLOR_GREEN}${set_kcptun_pwd}${COLOR_END}"
echo -e "Kcptun Crypt mode : ${COLOR_GREEN}${set_kcptun_method}${COLOR_END}"
echo -e "Kcptun Fast mode : ${COLOR_GREEN}${set_kcptun_mode}${COLOR_END}"
echo -e "Kcptun MTU : ${COLOR_GREEN}${set_kcptun_mtu}${COLOR_END}"
echo -e "Kcptun sndwnd : ${COLOR_GREEN}1024${COLOR_END}"
echo -e "Kcptun rcvwnd : ${COLOR_GREEN}1024${COLOR_END}"
echo -e "Kcptun compression : ${COLOR_GREEN}${set_kcptun_compression}${COLOR_END}"
echo "----------------------------------------------------------"
echo -e "${COLOR_PINK}Kcptun config for SS/SSR/Phone:${COLOR_END}"
echo -e "KCP Port : ${COLOR_GREEN}${set_kcptun_port}${COLOR_END}"
echo -e "KCP parameter : ${COLOR_GREEN}--crypt ${set_kcptun_method} --key ${set_kcptun_pwd} --mtu ${set_kcptun_mtu} --sndwnd 128 --rcvwnd 1024 --mode ${set_kcptun_mode}${show_kcptun_nocomp}${COLOR_END}"
echo "----------------------------------------------------------"
echo -e "Kcptun status manage: ${COLOR_PINK}/etc/init.d/kcptun${COLOR_END} {${COLOR_GREEN}start|stop|restart|status|config|version${COLOR_END}}"
echo "=========================================================="
fi
echo
}
pre_install_kcptun_for_ss_ssr(){
fun_clangcn "clear"
get_install_version
Dispaly_Selection
Press_Install
Print_Sys_Info
Disable_Selinux
check_kcptun_for_ss_ssr_installed
cd ${cur_dir}
############################### SS-libev ###############################
if [ "${ss_libev_installed_flag}" == "false" ]; then
echo
echo "=========================================================="
echo -e "${COLOR_PINK}Please input your SS-libev setting:${COLOR_END}"
echo
# Set shadowsocks-libev password
def_ss_libev_pwd=`fun_randstr`
echo "Please input password for shadowsocks-libev"
read -p "(Default password: ${def_ss_libev_pwd}):" set_ss_libev_pwd
[ -z "${set_ss_libev_pwd}" ] && set_ss_libev_pwd="${def_ss_libev_pwd}"
echo