-
Notifications
You must be signed in to change notification settings - Fork 451
/
install_centos.sh
382 lines (319 loc) · 9.91 KB
/
install_centos.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
#!/bin/bash
#
# Provides: sockd.info (Lozy)
#
VERSION="1.3.2"
INSTALL_FROM="compile"
DEFAULT_PORT="2016"
DEFAULT_USER=""
DEFAULT_PAWD=""
WHITE_LIST_NET=""
WHITE_LIST=""
SCRIPT_HOST="https://public.sockd.info"
PACKAGE_NAME="dante_1.3.2-1_$(uname -m).deb"
COLOR_PATH="/etc/default/color"
BIN_DIR="/etc/danted"
BIN_PATH="/etc/danted/sbin/sockd"
CONFIG_PATH="/etc/danted/sockd.conf"
BIN_SCRIPT="/etc/init.d/sockd"
DEFAULT_IPADDR=$(ip addr | grep 'inet ' | grep -Ev 'inet 127|inet 192\.168' | \
sed "s/[[:space:]]*inet \([0-9.]*\)\/.*/\1/")
RUN_PATH=$(cd `dirname $0`;pwd )
RUN_OPTS=$*
##################------------Func()---------#####################################
remove_install(){
[ -s "${BIN_SCRIPT}" ] && ${BIN_SCRIPT} stop > /dev/null 2>&1
[ -f "${BIN_SCRIPT}" ] && rm "${BIN_SCRIPT}"
[ -n "$BIN_DIR" ] && rm -r "$BIN_DIR"
}
detect_install(){
if [ -s "${BIN_PATH}" ];then
echo "dante socks5 already install"
${BIN_PATH} -v
fi
}
generate_config_ip(){
local ipaddr="$1"
local port="$2"
cat <<EOF
# Generate interface ${ipaddr}
internal: ${ipaddr} port = ${port}
external: ${ipaddr}
EOF
}
generate_config_iplist(){
local ipaddr_list="$1"
local port="$2"
[ -z "${ipaddr_list}" ] && return 1
[ -z "${port}" ] && return 2
for ipaddr in ${ipaddr_list};do
generate_config_ip ${ipaddr} ${port} >> ${CONFIG_PATH}
done
ipaddr_array=($ipaddr_list)
if [ ${#ipaddr_array[@]} -gt 1 ];then
echo "external.rotation: same-same" >> ${CONFIG_PATH}
fi
}
generate_config_static(){
if [ "$VERSION" == "1.3.2" ];then
cat <<EOF
method: pam none
clientmethod: none
user.privileged: root
user.notprivileged: sockd
logoutput: /var/log/sockd.log
client pass {
from: 0.0.0.0/0 to: 0.0.0.0/0
}
client block {
from: 0.0.0.0/0 to: 0.0.0.0/0
}
EOF
else
cat <<EOF
clientmethod: none
socksmethod: pam.username none
user.privileged: root
user.notprivileged: sockd
logoutput: /var/log/sockd.log
client pass {
from: 0/0 to: 0/0
log: connect disconnect
}
client block {
from: 0/0 to: 0/0
log: connect error
}
EOF
fi
}
generate_config_white(){
local white_ipaddr="$1"
[ -z "${white_ipaddr}" ] && return 1
# x.x.x.x/32
for ipaddr_range in ${white_ipaddr};do
cat <<EOF
#------------ Network Trust: ${ipaddr_range} ---------------
pass {
from: ${ipaddr_range} to: 0.0.0.0/0
method: none
}
EOF
done
}
generate_config_whitelist(){
local whitelist_url="$1"
if [ -n "${whitelist_url}" ];then
ipaddr_list=$(curl -s --insecure -A "Mozilla Server Init" ${whitelist_url})
generate_config_white "${ipaddr_list}"
fi
}
generate_config_bottom(){
if [ "$VERSION" == "1.3.2" ];then
cat <<EOF
pass {
from: 0.0.0.0/0 to: 0.0.0.0/0
protocol: tcp udp
method: pam
log: connect disconnect
}
block {
from: 0.0.0.0/0 to: 0.0.0.0/0
log: connect error
}
EOF
else
cat <<EOF
socks pass {
from: 0/0 to: 0/0
socksmethod: pam.username
log: connect disconnect
}
socks block {
from: 0/0 to: 0/0
log: connect error
}
EOF
fi
}
generate_config(){
local ipaddr_list="$1"
local whitelist_url="$2"
local whitelist_ip="$3"
mkdir -p ${BIN_DIR}
echo "# Generate by sockd.info" > ${CONFIG_PATH}
generate_config_iplist "${ipaddr_list}" ${DEFAULT_PORT} >> ${CONFIG_PATH}
generate_config_static >> ${CONFIG_PATH}
generate_config_white ${whitelist_ip} >> ${CONFIG_PATH}
generate_config_whitelist "${whitelist_url}" >> ${CONFIG_PATH}
generate_config_bottom >> ${CONFIG_PATH}
}
download_file(){
local path="$1"
local filename="$2"
local execute="$3"
[ -z "${filename}" ] && filename="$path"
[ -n "$path" ] && \
wget -q --no-check-certificate ${SCRIPT_HOST}/${path} -O ${filename}
[ -f "${filename}" ] && [ -n "${execute}" ] && chmod +x ${filename}
}
##################------------Menu()---------#####################################
echo "Current Options: $RUN_OPTS"
for _PARAMETER in $RUN_OPTS
do
case "${_PARAMETER}" in
--version=*)
VERSION="${_PARAMETER#--version=}"
;;
--ip=*) #split by: ip1:ip2:ip3
ipaddr_list=$(echo "${_PARAMETER#--ip=}" | sed 's/:/\n/g' | sed '/^$/d')
;;
--port=*)
port="${_PARAMETER#--port=}"
;;
--user=*)
user="${_PARAMETER#--user=}"
;;
--passwd=*)
passwd="${_PARAMETER#--passwd=}"
;;
--whitelist=*)
whitelist_ipaddrs=$(echo "${_PARAMETER#--whitelist=}" | sed 's/:/\n/g' | sed '/^$/d')
;;
--whitelist-url=*)
whitelist="${_PARAMETER#--whitelist-url=}"
;;
--from-package|-p)
echo "Sorry, install from-package is not available for CentOS."
# INSTALL_FROM="package"
exit 1
;;
--update-whitelist|-u)
gen_config_only="True"
;;
--force|-f)
remove_install
;;
--uninstall)
remove_install
exit 0
;;
--no-github)
echo "skip download script from github.com"
;;
--help|-h)
clear
options=(
"--ip=@Socks5 Server Ip address" \
"--port=[${DEFAULT_PORT}]@port for dante socks5 server" \
"--version=@Specify dante version [$VERSION]"\s
"--user=@Socks5 Auth user" \
"--passwd=@Socks5 Auth passwd"\
"--whitelist=@Socks5 Auth IP list" \
"--whitelist-url=@Socks Auth whitelist http online" \
"--from-package | -p @Install package from Bin package" \
"--update-whitelist | -u @update white list" \
"--force-update | -f @force update sockd" \
"--help,-h@print help info" )
printf "Usage: %s [OPTIONS]\n\nOptions:\n\n" $0
for option in "${options[@]}";do
printf " %-20s%s\n" "$( echo ${option} | sed 's/@.*//g')" "$( echo ${option} | sed 's/.*@//g')"
done
echo -e "\n"
exit 1
;;
*)
echo "option ${_PARAMETER} is not support"
exit 1
;;
esac
done
[ -n "${port}" ] && DEFAULT_PORT="${port}"
[ -n "${ipaddr_list}" ] && DEFAULT_IPADDR="${ipaddr_list}"
[ -n "${user}" ] && DEFAULT_USER="${user}"
[ -n "${passwd}" ] && DEFAULT_PAWD="${passwd}"
[ -n "${whitelist_ipaddrs}" ] && WHITE_LIST_NET="${whitelist_ipaddrs}"
[ -n "${whitelist}" ] && WHITE_LIST="${whitelist}"
generate_config "${DEFAULT_IPADDR}" "${WHITE_LIST}" "${WHITE_LIST_NET}"
[ -n "$gen_config_only" ] && echo "===========>> update config" && cat ${CONFIG_PATH} && exit 0
download_file "script/sockd" "${BIN_SCRIPT}" "execute"
[ -n "$(detect_install)" ] && echo -e "\n[Warning] dante sockd already install." && exit 1
[ -n "$COLOR_PATH" ] && [ ! -s "$COLOR_PATH" ] && download_file "script/color" $COLOR_PATH && . $COLOR_PATH
########################################## DEBIAN 8 ####################################################################
yum install gcc g++ make vim pam-devel tcp_wrappers-devel unzip httpd-tools -y
mkdir -p /tmp/danted && rm /tmp/danted/* -rf && cd /tmp/danted
id sockd > /dev/null 2>&1 || useradd sockd -s /bin/false
# Installing Start-Stop Daemon
if [ -z "$(command -v start-stop-daemon)" ];then
download_file "source/apps-sys-utils-start-stop-daemon-IR1_9_18-2.tar.gz" "start-stop-daemon-IR1_9_18-2.tar.gz"
tar zxvf start-stop-daemon-IR1_9_18-2.tar.gz
gcc apps/sys-utils/start-stop-daemon-IR1_9_18-2/start-stop-daemon.c \
-o start-stop-daemon -o /sbin/start-stop-daemon
fi
#--# Check libpam-pwdfile
if [ ! -s /lib/security/pam_pwdfile.so ];then
download_file "source/libpam-pwdfile.zip" "libpam-pwdfile.zip"
if [ -f "libpam-pwdfile.zip" ];then
unzip libpam-pwdfile.zip
cd libpam-pwdfile-master && make -j && make install
cd ../
fi
fi
if [ -d /lib64/security/ ] && [ ! -f /lib64/security/pam_pwdfile.so ];then
[ -f /lib/security/pam_pwdfile.so ] && \
cp /lib/security/pam_pwdfile.so /lib64/security/ || echo "[ERROR] pam_pwdfile.so not exist!"
fi
if [ "$INSTALL_FROM" == "compile" ];then
yum install gcc g++ make libpam-dev libwrap0-dev -y
download_file "source/dante-${VERSION}.tar.gz" "dante-${VERSION}.tar.gz"
if [ -f "dante-${VERSION}.tar.gz" ];then
tar xzf dante-${VERSION}.tar.gz --strip 1
./configure --with-sockd-conf=${CONFIG_PATH} --prefix=${BIN_DIR}
make -j && make install
fi
else
download_file "package/${PACKAGE_NAME}" "${PACKAGE_NAME}"
[ -f "${PACKAGE_NAME}" ] && dpkg -i ${PACKAGE_NAME}
fi
cat > /etc/pam.d/sockd <<EOF
auth required pam_pwdfile.so pwdfile ${BIN_DIR}/sockd.passwd
account required pam_permit.so
EOF
cat > /etc/default/sockd <<EOF
# Default Config for sockd
# -n :: not tcp-keep alive
Start_Process=1
Sockd_Opts="-n"
EOF
rm /usr/bin/sockd -f && ln -s /etc/danted/sbin/sockd /usr/bin/sockd
${BIN_SCRIPT} adduser "${DEFAULT_USER}" "${DEFAULT_PAWD}"
if [ -n "$(ls -l /sbin/init | grep systemd)" ];then
download_file "script/sockd.service" "/lib/systemd/system/sockd.service"
systemctl enable sockd
else
chkconfig --add sockd
fi
service sockd restart
clear
if [ -n "$(ss -ln | grep "$DEFAULT_PORT")" ];then
cat <<EOF
${CCYAN}+-----------------------------------------+$CEND
${CGREEN} Dante Socks5 Install Done. $CEND
${CCYAN}+-----------------------------------------+$CEND
${CGREEN} Dante Version: $CMAGENTA v${VERSION}$CEND
${CGREEN} Socks5 Info: $CMAGENTA$CEND
EOF
for ipaddr in ${DEFAULT_IPADDR};do
echo "${CGREEN} $CMAGENTA ${ipaddr}:${DEFAULT_PORT}$CEND"
done
cat <<EOF
${CGREEN} Socks5 User&Passwd: $CMAGENTA ${DEFAULT_USER}:${DEFAULT_PAWD}$CEND
${CCYAN}+_________________________________________+$CEND
EOF
echo -e "\033[32m Dante Server Install Successfuly! \033[0m"
else
echo -e "\033[1;31m Dante Server Install Failed! \033[0m"
fi
echo ""
${BIN_SCRIPT} -h
exit 0