-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdeploy.sh
1401 lines (1300 loc) · 44.9 KB
/
deploy.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
#
# System Required: CentOS 6,7, Debian, Ubuntu
# Description: One click ShadowsocksR Server
#
# Thanks: @teddysun <https://github.com/teddysun>
# Reference URL:
# https://github.com/ssrpanel/shadowsocksr
# Author: QuNiu
#
# PATH
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
# libsodium
libsodium_file="libsodium-1.0.18"
libsodium_url="https://github.com/jedisct1/libsodium/releases/download/1.0.18-RELEASE/libsodium-1.0.18.tar.gz"
# shadowsocksr
shadowsocksr_name="shadowsocksr"
shadowsocksr_file="shadowsocksr"
shadowsocksr_url="https://github.com/quniu/${shadowsocksr_file}.git"
shadowsocksr_service_yum="https://raw.githubusercontent.com/quniu/ssrpanel-deploy/master/service/${shadowsocksr_name}"
shadowsocksr_service_apt="https://raw.githubusercontent.com/quniu/ssrpanel-deploy/master/service/${shadowsocksr_name}-debian"
# v2ray
ssrpanel_v2ray_name="ssrpanel-v2ray"
v2ray_init_name="v2ray"
v2ray_service_yum="https://raw.githubusercontent.com/quniu/ssrpanel-deploy/master/service/${v2ray_init_name}"
v2ray_service_apt="https://raw.githubusercontent.com/quniu/ssrpanel-deploy/master/service/${v2ray_init_name}-debian"
# Current folder
cur_dir=`pwd`
# Stream Ciphers
ciphers=(
none
aes-256-cfb
aes-192-cfb
aes-128-cfb
aes-256-cfb8
aes-192-cfb8
aes-128-cfb8
aes-256-ctr
aes-192-ctr
aes-128-ctr
chacha20-ietf
chacha20-ietf-poly1305
aes-256-gcm
aes-192-gcm
aes-128-gcm
chacha20
salsa20
xchacha20
xsalsa20
rc4-md5
)
# Reference URL:
# https://github.com/shadowsocksr-rm/shadowsocks-rss/blob/master/ssr.md
# https://github.com/shadowsocksrr/shadowsocksr/commit/a3cf0254508992b7126ab1151df0c2f10bf82680
# Protocol
protocols=(
origin
auth_chain_a
auth_chain_b
auth_chain_c
auth_chain_d
auth_chain_e
auth_chain_f
auth_sha1_v4
auth_sha1_v4_compatible
auth_aes128_md5
auth_aes128_sha1
verify_deflate
)
# obfs
obfs=(
plain
http_simple
http_simple_compatible
http_post
http_post_compatible
tls1.2_ticket_auth
tls1.2_ticket_auth_compatible
tls1.2_ticket_fastauth
tls1.2_ticket_fastauth_compatible
)
# interfaces
interfaces=(
ssrpanel
mudbjson
sspanelv2
sspanelv3
sspanelv3ssr
glzjinmod
legendsockssr
)
# v2ray ciphers
v2ray_ciphers=(
none
aes-128-cfb
aes-128-gcm
chacha20-poly1305
)
# v2ray system
v2ray_system=(
linux
windows
)
# v2ray arch
v2ray_arch=(
32
64
)
# Color
red='\033[0;31m'
green='\033[0;32m'
yellow='\033[0;33m'
plain='\033[0m'
# Make sure only root can run our script
[[ $EUID -ne 0 ]] && echo -e "[${red}Error${plain}] This script must be run as root!" && exit 1
# Disable selinux
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
}
# Check system
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
}
# 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 public IP address
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 )
[ ! -z ${IP} ] && echo ${IP} || echo
}
# Modify time zone
modify_time(){
# set time zone
if check_sys packageManager yum; then
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
elif check_sys packageManager apt; then
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
fi
# status info
if [ $? -eq 0 ]; then
echo -e "[${green}Info${plain}] Modify the time zone success!"
else
echo -e "[${yellow}Warning${plain}] Modify the time zone failure!"
fi
}
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
}
# Pre-installation settings
install_prepare(){
if check_sys packageManager yum || check_sys packageManager apt; then
# Not support CentOS 5
if centosversion 5; then
echo -e "$[{red}Error${plain}] Not supported CentOS 5, please change to CentOS 6+/Debian 7+/Ubuntu 12+ and try again!"
exit 1
fi
else
echo -e "[${red}Error${plain}] Your OS is not supported. please change OS to CentOS/Debian/Ubuntu and try again!"
exit 1
fi
# Set ShadowsocksR config password
echo "Please enter password for ShadowsocksR:"
read -p "(Default password: abc123456):" shadowsocksrpwd
[ -z "${shadowsocksrpwd}" ] && shadowsocksrpwd="abc123456"
echo
echo "---------------------------"
echo "password = ${shadowsocksrpwd}"
echo "---------------------------"
echo
# Set ShadowsocksR config port
while true
do
echo -e "Please enter a port for ShadowsocksR [1-65535]:"
read -p "(Default port: 8989):" shadowsocksrport
[ -z "${shadowsocksrport}" ] && shadowsocksrport="8989"
expr ${shadowsocksrport} + 1 &>/dev/null
if [ $? -eq 0 ]; then
if [ ${shadowsocksrport} -ge 1 ] && [ ${shadowsocksrport} -le 65535 ] && [ ${shadowsocksrport:0:1} != 0 ]; then
echo
echo "---------------------------"
echo "port = ${shadowsocksrport}"
echo "---------------------------"
echo
break
fi
fi
echo -e "[${red}Error${plain}] Please enter a correct number [1-65535]"
done
# Set shadowsocksR config stream ciphers
while true
do
echo -e "Please select stream cipher for ShadowsocksR:"
for ((i=1;i<=${#ciphers[@]};i++ )); do
hint="${ciphers[$i-1]}"
echo -e "${green}${i}${plain}) ${hint}"
done
read -p "Which cipher you'd select(Default: ${ciphers[1]}):" pick
[ -z "$pick" ] && pick=2
expr ${pick} + 1 &>/dev/null
if [ $? -ne 0 ]; then
echo -e "[${red}Error${plain}] Please enter a number"
continue
fi
if [[ "$pick" -lt 1 || "$pick" -gt ${#ciphers[@]} ]]; then
echo -e "[${red}Error${plain}] Please enter a number between 1 and ${#ciphers[@]}"
continue
fi
shadowsocksrcipher=${ciphers[$pick-1]}
echo
echo "---------------------------"
echo "cipher = ${shadowsocksrcipher}"
echo "---------------------------"
echo
break
done
# Set shadowsocksR config protocol
while true
do
echo -e "Please select protocol for ShadowsocksR:"
for ((i=1;i<=${#protocols[@]};i++ )); do
hint="${protocols[$i-1]}"
echo -e "${green}${i}${plain}) ${hint}"
done
read -p "Which protocol you'd select(Default: ${protocols[8]}):" protocol
[ -z "$protocol" ] && protocol=9
expr ${protocol} + 1 &>/dev/null
if [ $? -ne 0 ]; then
echo -e "[${red}Error${plain}] Input error, please input a number"
continue
fi
if [[ "$protocol" -lt 1 || "$protocol" -gt ${#protocols[@]} ]]; then
echo -e "[${red}Error${plain}] Input error, please input a number between 1 and ${#protocols[@]}"
continue
fi
shadowsocksrprotocol=${protocols[$protocol-1]}
echo
echo "---------------------------"
echo "protocol = ${shadowsocksrprotocol}"
echo "---------------------------"
echo
break
done
# Set shadowsocksR config obfs
while true
do
echo -e "Please select obfs for ShadowsocksR:"
for ((i=1;i<=${#obfs[@]};i++ )); do
hint="${obfs[$i-1]}"
echo -e "${green}${i}${plain}) ${hint}"
done
read -p "Which obfs you'd select(Default: ${obfs[6]}):" r_obfs
[ -z "$r_obfs" ] && r_obfs=7
expr ${r_obfs} + 1 &>/dev/null
if [ $? -ne 0 ]; then
echo -e "[${red}Error${plain}] Input error, please input a number"
continue
fi
if [[ "$r_obfs" -lt 1 || "$r_obfs" -gt ${#obfs[@]} ]]; then
echo -e "[${red}Error${plain}] Input error, please input a number between 1 and ${#obfs[@]}"
continue
fi
shadowsocksrobfs=${obfs[$r_obfs-1]}
echo
echo "---------------------------"
echo "obfs = ${shadowsocksrobfs}"
echo "---------------------------"
echo
break
done
}
# Download files
download_files(){
# Clean install package
install_cleanup
# Download libsodium
if ! wget --no-check-certificate -O ${libsodium_file}.tar.gz ${libsodium_url}; then
echo -e "[${red}Error${plain}] Failed to download ${libsodium_file}.tar.gz!"
exit 1
fi
# Download ShadowsocksR
if ! git clone ${shadowsocksr_url}; then
echo -e "[${red}Error${plain}] Failed to download ShadowsocksR file!"
exit 1
fi
# Download ShadowsocksR service script
if check_sys packageManager yum; then
if ! wget --no-check-certificate ${shadowsocksr_service_yum} -O /etc/init.d/${shadowsocksr_name}; then
echo -e "[${red}Error${plain}] Failed to download ShadowsocksR chkconfig file!"
exit 1
fi
elif check_sys packageManager apt; then
if ! wget --no-check-certificate ${shadowsocksr_service_apt} -O /etc/init.d/${shadowsocksr_name}; then
echo -e "[${red}Error${plain}] Failed to download ShadowsocksR chkconfig file!"
exit 1
fi
fi
}
# Firewall set
firewall_set(){
echo -e "[${green}Info${plain}] firewall set start..."
if centosversion 6; then
/etc/init.d/iptables status > /dev/null 2>&1
if [ $? -eq 0 ]; then
iptables -L -n | grep -i ${shadowsocksrport} > /dev/null 2>&1
if [ $? -ne 0 ]; then
iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport ${shadowsocksrport} -j ACCEPT
iptables -I INPUT -m state --state NEW -m udp -p udp --dport ${shadowsocksrport} -j ACCEPT
/etc/init.d/iptables save
/etc/init.d/iptables restart
else
echo -e "[${green}Info${plain}] port ${shadowsocksrport} has been set up!"
fi
else
echo -e "[${yellow}Warning${plain}] 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
firewall-cmd --permanent --zone=public --add-port=${shadowsocksrport}/tcp
firewall-cmd --permanent --zone=public --add-port=${shadowsocksrport}/udp
firewall-cmd --reload
else
echo -e "[${yellow}Warning${plain}] firewalld looks like not running or not installed, please enable port ${shadowsocksrport} manually if necessary!"
fi
fi
echo -e "[${green}Info${plain}] firewall set completed..."
}
# Set userapiconfig.py
config_userapi(){
cat > /usr/local/${shadowsocksr_name}/userapiconfig.py<<-EOF
API_INTERFACE = '${shadowsocksrinterface}'
UPDATE_TIME = 60
SERVER_PUB_ADDR = '127.0.0.1'
MUDB_FILE = 'mudb.json'
MYSQL_CONFIG = 'usermysql.json'
MUAPI_CONFIG = 'usermuapi.json'
EOF
}
# Config user-config.json
config_userjson(){
cat > /usr/local/${shadowsocksr_name}/user-config.json<<-EOF
{
"server":"0.0.0.0",
"server_ipv6": "::",
"server_port":${shadowsocksrport},
"local_address":"127.0.0.1",
"local_port":1080,
"password":"${shadowsocksrpwd}",
"method":"${shadowsocksrcipher}",
"protocol":"${shadowsocksrprotocol}",
"protocol_param":"",
"obfs":"${shadowsocksrobfs}",
"obfs_param":"",
"speed_limit_per_con": 0,
"speed_limit_per_user": 0,
"additional_ports" : {},
"additional_ports_only" : false,
"connect_verbose_info": 1,
"timeout":120,
"udp_timeout": 60,
"dns_ipv6": false,
"redirect": ["www.baidu.com", "image.baidu.com", "m.baidu.com", "map.baidu.com", "zhidao.baidu.com"],
"fast_open":false
}
EOF
}
# Config usermysql.json
config_usermysql(){
cat > /usr/local/${shadowsocksr_name}/usermysql.json<<-EOF
{
"host": "${mysql_ip_address}",
"port": ${mysql_ip_port},
"user": "${mysql_user_name}",
"password": "${mysql_db_password}",
"db": "${mysql_db_name}",
"node_id": ${mysql_nodeid},
"transfer_mul": ${mysql_ratio},
"ssl_enable": 0,
"ssl_ca": "",
"ssl_cert": "",
"ssl_key": ""
}
EOF
}
# Deploy config
deploy_config(){
while true
do
# Set api_interface.py
echo -e "Please select interface for ShadowsocksR:"
for ((i=1;i<=${#interfaces[@]};i++ )); do
hint="${interfaces[$i-1]}"
echo -e "${green}${i}${plain}) ${hint}"
done
read -p "Which interface you'd select(Default: ${interfaces[0]}):" interface
[ -z "$interface" ] && interface=1
expr ${interface} + 1 &>/dev/null
if [ $? -ne 0 ]; then
echo -e "[${red}Error${plain}] Input error, please input a number"
continue
fi
if [[ "$interface" -lt 1 || "$interface" -gt ${#interfaces[@]} ]]; then
echo -e "[${red}Error${plain}] Input error, please input a number between 1 and ${#interfaces[@]}"
continue
fi
shadowsocksrinterface=${interfaces[$interface-1]}
echo
echo "---------------------------"
echo "api_interface = ${shadowsocksrinterface}"
echo "---------------------------"
echo
break
done
# Set usermysql.json
while true
do
#ip
echo -e "Please enter the MySQL ip address:"
read -p "(Default address: 127.0.0.1):" mysql_ip_address
[ -z "${mysql_ip_address}" ] && mysql_ip_address="127.0.0.1"
expr ${mysql_ip_address} + 1 &>/dev/null
#port
echo -e "Please enter the MySQL port:"
read -p "(Default port: 3306):" mysql_ip_port
[ -z "${mysql_ip_port}" ] && mysql_ip_port="3306"
expr ${mysql_ip_port} + 1 &>/dev/null
#db_name
echo -e "Please enter the MySQL database name:"
read -p "(Default name: ssrpanel):" mysql_db_name
[ -z "${mysql_db_name}" ] && mysql_db_name="ssrpanel"
expr ${mysql_db_name} + 1 &>/dev/null
#user_name
echo -e "Please enter the MySQL database user_name:"
read -p "(Default user: ssrpanel):" mysql_user_name
[ -z "${mysql_user_name}" ] && mysql_user_name="ssrpanel"
expr ${mysql_user_name} + 1 &>/dev/null
#db_password
echo -e "Please enter the MySQL database password:"
read -p "(Default password: password):" mysql_db_password
[ -z "${mysql_db_password}" ] && mysql_db_password="password"
expr ${mysql_db_password} + 1 &>/dev/null
#nodeid
echo -e "Please enter the Node ID:"
read -p "(Default ID: 1):" mysql_nodeid
[ -z "${mysql_nodeid}" ] && mysql_nodeid="1"
expr ${mysql_nodeid} + 1 &>/dev/null
#ratio
echo -e "Please enter the ratio of this node:"
read -p "(Default ratio: 1.0):" mysql_ratio
[ -z "${mysql_ratio}" ] && mysql_ratio="1.0"
expr ${mysql_ratio} + 1 &>/dev/null
echo
echo -e "-----------------------------------------------------"
echo -e "The usermysql.json Configuration has been completed! "
echo -e "-----------------------------------------------------"
echo -e "Your MySQL IP : ${mysql_ip_address} "
echo -e "Your MySQL Port : ${mysql_ip_port} "
echo -e "Your MySQL User : ${mysql_user_name} "
echo -e "Your MySQL Password : ${mysql_db_password} "
echo -e "Your MySQL DBname : ${mysql_db_name} "
echo -e "Your Node ID : ${mysql_nodeid} "
echo -e "Your Transfer_mul : ${mysql_ratio} "
echo -e "-----------------------------------------------------"
break
done
echo "Press any key to start install ShadowsocksR or Press Ctrl+C to cancel. Please continue!"
char=`get_char`
# Install necessary dependencies
if check_sys packageManager yum; then
yum update -y
yum install -y epel-release
yum install -y yum-utils
yum-config-manager --enable epel > /dev/null 2>&1
yum install -y python python-devel python-pip python-setuptools openssl openssl-devel curl unzip gcc automake autoconf make libtool wget git
elif check_sys packageManager apt; then
apt-get -y update
apt-get -y install python python-dev python-pip python-setuptools openssl libssl-dev curl unzip gcc automake autoconf make libtool wget git
fi
cd ${cur_dir}
}
# Deploy ShadowsocksR
deploy_shadowsocksr(){
cd ${cur_dir}
mv ${shadowsocksr_file} /usr/local/${shadowsocksr_name}
cd /usr/local/${shadowsocksr_name}
pip install --upgrade setuptools
pip install -r requestment.txt
config_userapi
config_userjson
config_usermysql
cd ${cur_dir}
}
# Install libsodium
install_libsodium(){
if [ ! -f /usr/lib/libsodium.a ]; then
cd ${cur_dir}
tar zxf ${libsodium_file}.tar.gz
cd ${libsodium_file}
./configure --prefix=/usr && make && make install
if [ $? -ne 0 ]; then
echo -e "[${red}Error${plain}] libsodium install failed!"
install_cleanup
exit 1
fi
fi
ldconfig
}
# Starts shadowsocksr service
start_service(){
if [ -f /usr/local/${shadowsocksr_name}/server.py ]; then
if [ $? -eq 0 ]; then
chmod +x /etc/init.d/${shadowsocksr_name}
if check_sys packageManager yum; then
chkconfig --add ${shadowsocksr_name}
chkconfig ${shadowsocksr_name} on
elif check_sys packageManager apt; then
cd /etc/init.d
update-rc.d -f ${shadowsocksr_name} defaults 90
fi
/etc/init.d/${shadowsocksr_name} start
if [ $? -eq 0 ]; then
echo -e "[${green}Info${plain}] ShadowsocksR start success!"
else
echo -e "[${yellow}Warning${plain}] ShadowsocksR start failure!"
fi
echo
echo -e "-------------------------------------------------"
echo -e "Congratulations, ShadowsocksR deploy completed!"
echo -e "-------------------------------------------------"
echo -e " Config Info "
echo -e "Your Server IP : $(get_ip) "
echo -e "Your Server Port : ${shadowsocksrport} "
echo -e "Your Password : ${shadowsocksrpwd} "
echo -e "Your Encryption Method: ${shadowsocksrcipher} "
echo -e "Your Protocol : ${shadowsocksrprotocol} "
echo -e "Your Obfs : ${shadowsocksrobfs} "
echo -e "Your Connect Info : 1 "
echo -e " Deploy Info "
echo -e "Your Api Interface : ${shadowsocksrinterface} "
echo -e "Your MySQL IP : ${mysql_ip_address} "
echo -e "Your MySQL Port : ${mysql_ip_port} "
echo -e "Your MySQL User : ${mysql_user_name} "
echo -e "Your MySQL Password : ${mysql_db_password} "
echo -e "Your MySQL DBname : ${mysql_db_name} "
echo -e "Your Node ID : ${mysql_nodeid} "
echo -e "Your Transfer_mul : ${mysql_ratio} "
echo -e "-------------------------------------------------"
echo -e " Enjoy it! "
echo -e "-------------------------------------------------"
else
echo
echo -e "[${red}Error${plain}] Could not find server.py file, failed to start service!"
exit 1
fi
else
echo
echo -e "[${red}Error${plain}] ShadowsocksR install failed!"
exit 1
fi
}
# Clean install
install_cleanup(){
cd ${cur_dir}
rm -rf ${libsodium_file}.tar.gz
rm -rf ${libsodium_file}
rm -rf ${shadowsocksr_file}
}
# Install ShadowsocksR
install_shadowsocksr(){
if [ -d "/usr/local/${shadowsocksr_name}" ]; then
printf "ShadowsocksR has been installed, Do you want to uninstall it? (y/n)"
printf "\n"
read -p "(Default: y):" install_answer
[ -z ${install_answer} ] && install_answer="y"
if [ "${install_answer}" == "y" ] || [ "${install_answer}" == "Y" ]; then
cd ${cur_dir}
uninstall_shadowsocksr
else
echo
echo "uninstall cancelled, nothing to do..."
echo
fi
else
modify_time
disable_selinux
install_prepare
deploy_config
download_files
install_libsodium
deploy_shadowsocksr
if check_sys packageManager yum; then
firewall_set
fi
start_service
install_cleanup
exit 0
fi
}
# Uninstall ShadowsocksR
uninstall_shadowsocksr(){
printf "Are you sure uninstall ShadowsocksR? (y/n)"
printf "\n"
read -p "(Default: n):" answer
[ -z ${answer} ] && answer="n"
if [ "${answer}" == "y" ] || [ "${answer}" == "Y" ]; then
if [ -d "/usr/local/${shadowsocksr_name}" ]; then
/etc/init.d/${shadowsocksr_name} status > /dev/null 2>&1
if [ $? -eq 0 ]; then
/etc/init.d/${shadowsocksr_name} stop
fi
if check_sys packageManager yum; then
chkconfig --del ${shadowsocksr_name}
elif check_sys packageManager apt; then
update-rc.d -f ${shadowsocksr_name} remove
fi
install_cleanup
rm -f /etc/init.d/${shadowsocksr_name}
rm -f ./${shadowsocksr_name}.log
rm -rf /usr/local/${shadowsocksr_name}
echo "ShadowsocksR uninstall success!"
else
echo
echo "Your ShadowsocksR is not installed!"
echo
fi
else
echo
echo "uninstall cancelled, nothing to do..."
echo
fi
}
# Auto Reboot System
auto_reboot_system(){
cd ${cur_dir}
# Modify time zone
modify_time
#hour
echo -e "Please enter the hour now(0-23):"
read -p "(Default hour: 5):" auto_hour
[ -z "${auto_hour}" ] && auto_hour="5"
expr ${auto_hour} + 1 &>/dev/null
#minute
echo -e "Please enter the minute now(0-59):"
read -p "(Default hour: 10):" auto_minute
[ -z "${auto_minute}" ] && auto_minute="10"
expr ${auto_minute} + 1 &>/dev/null
echo -e "[${green}Info${plain}] The time has been set, then install crontab!"
# Install crontabs
if check_sys packageManager yum; then
yum install -y vixie-cron cronie
elif check_sys packageManager apt; then
apt-get -y update
apt-get -y install cron
fi
echo "$auto_minute $auto_hour * * * root /sbin/reboot" >> /etc/crontab
# start crontabs
if check_sys packageManager yum; then
chkconfig crond on
service crond restart
elif check_sys packageManager apt; then
/etc/init.d/cron restart
fi
if [ $? -eq 0 ]; then
echo -e "[${green}Info${plain}] crontab start success!"
else
echo -e "[${yellow}Warning${plain}] crontab start failed!"
exit 1
fi
echo -e "[${green}Info${plain}] Has been installed successfully!"
echo -e "-----------------------------------------------------"
echo -e "The time for automatic restart has been set! "
echo -e "-----------------------------------------------------"
echo -e "hour : ${auto_hour} "
echo -e "minute : ${auto_minute} "
echo -e "Restart the system at ${auto_hour}:${auto_minute} every day"
echo -e "-----------------------------------------------------"
}
######################################################## V2RAY START ########################################################
# ssrpanel-v2ray version
get_ssrpanel_v2ray_ver(){
ssrpanel_v2ray_ver=$(wget --no-check-certificate -qO- https://api.github.com/repos/aiyahacke/ssrpanel-v2ray/releases/latest | grep 'tag_name' | cut -d\" -f4)
[ -z ${ssrpanel_v2ray_ver} ] && echo -e "[${red}Error${plain}] Get ssrpanel-v2ray latest version failed" && exit 1
}
# v2ray-core version
get_v2ray_core_ver(){
v2ray_core_ver=$(wget --no-check-certificate -qO- https://api.github.com/repos/v2ray/v2ray-core/releases/latest | grep 'tag_name' | cut -d\" -f4)
[ -z ${v2ray_core_ver} ] && echo -e "[${red}Error${plain}] Get v2ray-core latest version failed" && exit 1
}
# download file
download(){
local filename=$(basename $1)
if [ -f ${1} ]; then
echo "${filename} [found]"
else
echo "${filename} not found, download now..."
wget --no-check-certificate -c -t3 -T60 -O ${1} ${2}
if [ $? -ne 0 ]; then
echo -e "[${red}Error${plain}] Download ${filename} failed."
exit 1
fi
fi
}
# v2ray Pre-installation settings
v2ray_install_prepare(){
if check_sys packageManager yum || check_sys packageManager apt; then
# Not support CentOS 5
if centosversion 5; then
echo -e "$[{red}Error${plain}] Not supported CentOS 5, please change to CentOS 6+/Debian 7+/Ubuntu 12+ and try again!"
exit 1
fi
else
echo -e "[${red}Error${plain}] Your OS is not supported. please change OS to CentOS/Debian/Ubuntu and try again!"
exit 1
fi
# Set v2ray.grpc port
while true
do
echo -e "Please enter a port for v2ray.grpc [1-65535]:"
read -p "(Default port: 52088):" v2ray_grpc_port
[ -z "${v2ray_grpc_port}" ] && v2ray_grpc_port="52088"
expr ${v2ray_grpc_port} + 1 &>/dev/null
if [ $? -eq 0 ]; then
if [ ${v2ray_grpc_port} -ge 1 ] && [ ${v2ray_grpc_port} -le 65535 ] && [ ${v2ray_grpc_port:0:1} != 0 ]; then
echo
echo "---------------------------"
echo "v2ray grpc port = ${v2ray_grpc_port}"
echo "---------------------------"
echo
break
fi
fi
echo -e "[${red}Error${plain}] Please enter a correct number [1-65535]"
done
# Set v2ray vmess port
while true
do
echo -e "Please enter a port for v2ray vmess(v2ray port of panel) [1-65535]:"
read -p "(Default port: 52099):" v2ray_vmess_port
[ -z "${v2ray_vmess_port}" ] && v2ray_vmess_port="52099"
expr ${v2ray_vmess_port} + 1 &>/dev/null
if [ $? -eq 0 ]; then
if [ ${v2ray_vmess_port} -ge 1 ] && [ ${v2ray_vmess_port} -le 65535 ] && [ ${v2ray_vmess_port:0:1} != 0 ]; then
echo
echo "---------------------------"
echo "v2ray vmess port = ${v2ray_vmess_port}"
echo "---------------------------"
echo
break
fi
fi
echo -e "[${red}Error${plain}] Please enter a correct number [1-65535]"
done
# Set v2ray system
while true
do
echo -e "Please select system for v2ray:"
for ((i=1;i<=${#v2ray_system[@]};i++ )); do
hint="${v2ray_system[$i-1]}"
echo -e "${green}${i}${plain}) ${hint}"
done
read -p "Which system you'd select(Default: ${v2ray_system[0]}):" v2sys
[ -z "$v2sys" ] && v2sys=1
expr ${v2sys} + 1 &>/dev/null
if [ $? -ne 0 ]; then
echo -e "[${red}Error${plain}] Input error, please input a number"
continue
fi
if [[ "$v2sys" -lt 1 || "$v2sys" -gt ${#v2ray_system[@]} ]]; then
echo -e "[${red}Error${plain}] Input error, please input a number between 1 and ${#v2ray_system[@]}"
continue
fi
v2ray_sys=${v2ray_system[$v2sys-1]}
echo
echo "---------------------------"
echo "v2ray system = ${v2ray_sys}"
echo "---------------------------"
echo
break
done
# Set v2ray system arch
while true
do
echo -e "Please select system arch for v2ray:"
for ((i=1;i<=${#v2ray_arch[@]};i++ )); do
hint="${v2ray_arch[$i-1]}"
echo -e "${green}${i}${plain}) ${hint}"
done
read -p "Which interface you'd select(Default: ${v2ray_arch[1]}):" v2arch
[ -z "$v2arch" ] && v2arch=2
expr ${v2arch} + 1 &>/dev/null
if [ $? -ne 0 ]; then
echo -e "[${red}Error${plain}] Input error, please input a number"
continue
fi
if [[ "$v2arch" -lt 1 || "$v2arch" -gt ${#v2ray_arch[@]} ]]; then
echo -e "[${red}Error${plain}] Input error, please input a number between 1 and ${#v2ray_arch[@]}"
continue
fi
v2ray_arc=${v2ray_arch[$v2arch-1]}
echo
echo "---------------------------"
echo "v2ray system arch = ${v2ray_arc}"
echo "---------------------------"
echo
break
done
# Set DB config
while true
do
#ip
echo -e "Please enter the MySQL ip address:"
read -p "(Default address: 127.0.0.1):" v2ray_mysql_ip_address
[ -z "${v2ray_mysql_ip_address}" ] && v2ray_mysql_ip_address="127.0.0.1"
expr ${v2ray_mysql_ip_address} + 1 &>/dev/null
#port
echo -e "Please enter the MySQL port:"
read -p "(Default port: 3306):" v2ray_mysql_ip_port
[ -z "${v2ray_mysql_ip_port}" ] && v2ray_mysql_ip_port="3306"
expr ${v2ray_mysql_ip_port} + 1 &>/dev/null
#db_name
echo -e "Please enter the MySQL database name:"
read -p "(Default name: ssrpanel):" v2ray_mysql_db_name
[ -z "${v2ray_mysql_db_name}" ] && v2ray_mysql_db_name="ssrpanel"
expr ${v2ray_mysql_db_name} + 1 &>/dev/null
#user_name
echo -e "Please enter the MySQL user_name:"
read -p "(Default user: ssrpanel):" v2ray_mysql_user_name
[ -z "${v2ray_mysql_user_name}" ] && v2ray_mysql_user_name="ssrpanel"
expr ${v2ray_mysql_user_name} + 1 &>/dev/null
#db_password
echo -e "Please enter the MySQL database password:"
read -p "(Default password: password):" v2ray_mysql_db_password
[ -z "${v2ray_mysql_db_password}" ] && v2ray_mysql_db_password="password"
expr ${v2ray_mysql_db_password} + 1 &>/dev/null
#alter-id
echo -e "Please enter the Alter-ID:"
read -p "(Default ID: 16):" v2ray_mysql_alter_id
[ -z "${v2ray_mysql_alter_id}" ] && v2ray_mysql_alter_id="16"
expr ${v2ray_mysql_alter_id} + 1 &>/dev/null
#nodeid
echo -e "Please enter the Node ID:"
read -p "(Default ID: 1):" v2ray_mysql_nodeid
[ -z "${v2ray_mysql_nodeid}" ] && v2ray_mysql_nodeid="1"
expr ${v2ray_mysql_nodeid} + 1 &>/dev/null
#ratio
echo -e "Please enter the ratio of this node:"
read -p "(Default ratio: 1.0):" v2ray_mysql_ratio
[ -z "${v2ray_mysql_ratio}" ] && v2ray_mysql_ratio="1.0"
expr ${v2ray_mysql_ratio} + 1 &>/dev/null
echo
echo -e "-----------------------------------------------------"
echo -e "The usermysql.json Configuration has been completed! "
echo -e "-----------------------------------------------------"
echo -e "Your MySQL IP : ${v2ray_mysql_ip_address} "
echo -e "Your MySQL Port : ${v2ray_mysql_ip_port} "
echo -e "Your MySQL DBname : ${v2ray_mysql_db_name} "