9
9
# Intro: https://shadowsocks.be/10.html
10
10
#
11
11
12
+ cur_dir=` pwd`
13
+
12
14
[[ $EUID -ne 0 ]] && echo " Error: This script must be run as root!" && exit 1
13
15
14
16
clear
20
22
echo " #############################################################"
21
23
echo
22
24
23
- checkos (){
24
- if [[ -f /etc/redhat-release ]]; then
25
- OS=" centos"
25
+ check_sys () {
26
+ local checkType=$1
27
+ local value=$2
28
+
29
+ local release=' '
30
+ local systemPackage=' '
31
+
32
+ if [ -f /etc/redhat-release ]; then
33
+ release=" centos"
34
+ systemPackage=" yum"
26
35
elif cat /etc/issue | grep -Eqi " debian" ; then
27
- OS=" debian"
36
+ release=" debian"
37
+ systemPackage=" apt"
28
38
elif cat /etc/issue | grep -Eqi " ubuntu" ; then
29
- OS=" ubuntu"
39
+ release=" ubuntu"
40
+ systemPackage=" apt"
30
41
elif cat /etc/issue | grep -Eqi " centos|red hat|redhat" ; then
31
- OS=" centos"
42
+ release=" centos"
43
+ systemPackage=" yum"
32
44
elif cat /proc/version | grep -Eqi " debian" ; then
33
- OS=" debian"
45
+ release=" debian"
46
+ systemPackage=" apt"
34
47
elif cat /proc/version | grep -Eqi " ubuntu" ; then
35
- OS=" ubuntu"
48
+ release=" ubuntu"
49
+ systemPackage=" apt"
36
50
elif cat /proc/version | grep -Eqi " centos|red hat|redhat" ; then
37
- OS=" centos"
51
+ release=" centos"
52
+ systemPackage=" yum"
53
+ fi
54
+
55
+ if [ ${checkType} == " sysRelease" ]; then
56
+ if [ " $value " == " $release " ]; then
57
+ return 0
58
+ else
59
+ return 1
60
+ fi
61
+ elif [ ${checkType} == " packageManager" ]; then
62
+ if [ " $value " == " $systemPackage " ]; then
63
+ return 0
64
+ else
65
+ return 1
66
+ fi
67
+ fi
68
+ }
69
+
70
+ install_check () {
71
+ if check_sys packageManager yum || check_sys packageManager apt; then
72
+ return 0
38
73
else
39
- echo " Not supported OS, Please reinstall OS and try again."
40
- exit 1
74
+ return 1
41
75
fi
42
76
}
43
77
@@ -81,8 +115,14 @@ get_char(){
81
115
82
116
# Pre-installation settings
83
117
pre_install (){
118
+ if ! install_check; then
119
+ echo " Your OS is not supported to run it."
120
+ echo " Please change to CentOS 6+/Debian 7+/Ubuntu 12+ and try again."
121
+ exit 1
122
+ fi
123
+
84
124
# Set haproxy config port
85
- while :
125
+ while true
86
126
do
87
127
echo -e " Please enter a port for haproxy and Shadowsocks server [1-65535]"
88
128
read -p " (Default port: 8989):" haproxyport
@@ -169,29 +209,29 @@ EOF
169
209
170
210
install (){
171
211
# Install haproxy
172
- if [ " ${OS} " == " centos " ] ; then
212
+ if check_sys packageManager yum ; then
173
213
yum install -y haproxy
174
- else
214
+ elif check_sys packageManager apt ; then
175
215
apt-get -y update
176
216
apt-get install -y haproxy
177
217
fi
178
218
179
219
if [ -d /etc/haproxy ]; then
180
- echo " haproxy install successed ."
220
+ echo " haproxy install success ."
181
221
182
222
echo " Config haproxy start..."
183
223
config_haproxy
184
224
echo " Config haproxy completed..."
185
225
186
- if [ " ${OS} " == " centos " ] ; then
226
+ if check_sys packageManager yum ; then
187
227
chkconfig --add haproxy
188
228
chkconfig haproxy on
189
- else
229
+ elif check_sys packageManager apt ; then
190
230
update-rc.d haproxy defaults
191
231
fi
192
232
193
233
# Start haproxy
194
- /etc/init.d/ haproxy start
234
+ service haproxy start
195
235
if [ $? -eq 0 ]; then
196
236
echo " haproxy start success..."
197
237
else
@@ -205,7 +245,7 @@ install(){
205
245
206
246
sleep 3
207
247
# restart haproxy
208
- /etc/init.d/ haproxy restart
248
+ service haproxy restart
209
249
# Active Internet connections confirm
210
250
netstat -nxtlp
211
251
echo
@@ -222,11 +262,10 @@ install(){
222
262
223
263
# Install haproxy
224
264
install_haproxy (){
225
- checkos
226
265
disable_selinux
227
266
pre_install
228
267
install
229
268
}
230
269
231
270
# Initialization step
232
- install_haproxy 2>&1 | tee ~ /haproxy_for_shadowsocks.log
271
+ install_haproxy 2>&1 | tee ${cur_dir} /haproxy_for_shadowsocks.log
0 commit comments