Skip to content

Commit 322efe6

Browse files
committed
refactor(ss.sh ssr.sh): use config file var
1 parent ceffac7 commit 322efe6

File tree

5 files changed

+25
-25
lines changed

5 files changed

+25
-25
lines changed

centos_install_ss.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,8 @@ installSS() {
230230

231231
echo "3" > /proc/sys/net/ipv4/tcp_fastopen
232232
echo "net.ipv4.tcp_fastopen = 3" >> /etc/sysctl.conf
233-
if [[ ! -d /etc/shadowsocks-libev ]];then
234-
mkdir /etc/shadowsocks-libev
235-
fi
233+
234+
mkdir -p /etc/shadowsocks-libev
236235
ssPath=`which ss-server`
237236
cat > /etc/shadowsocks-libev/config.json<<-EOF
238237
{

ss.sh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ PLAIN='\033[0m'
1212
BASE=`pwd`
1313
OS=`hostnamectl | grep -i system | cut -d: -f2`
1414

15+
CONFIG_FILE="/etc/shadowsocks-libev/config.json"
1516

1617
colorEcho() {
1718
echo -e "${1}${@:2}${PLAIN}"
@@ -246,11 +247,10 @@ installSS() {
246247

247248
echo "3" > /proc/sys/net/ipv4/tcp_fastopen
248249
echo "net.ipv4.tcp_fastopen = 3" >> /etc/sysctl.conf
249-
if [[ ! -d /etc/shadowsocks-libev ]];then
250-
mkdir /etc/shadowsocks-libev
251-
fi
250+
251+
mkdir -p /etc/shadowsocks-libev
252252
ssPath=`which ss-server`
253-
cat > /etc/shadowsocks-libev/config.json<<-EOF
253+
cat > $CONFIG_FILE<<-EOF
254254
{
255255
"server":"0.0.0.0",
256256
"server_port":${PORT},
@@ -274,7 +274,7 @@ Wants=network-online.target
274274
Type=simple
275275
PIDFile=/var/run/shadowsocks-libev.pid
276276
LimitNOFILE=32768
277-
ExecStart=$ssPath -c /etc/shadowsocks-libev/config.json -f /var/run/shadowsocks-libev.pid
277+
ExecStart=$ssPath -c $CONFIG_FILE -f /var/run/shadowsocks-libev.pid
278278
ExecReload=/bin/kill -s HUP \$MAINPID
279279
ExecStop=/bin/kill -s TERM \$MAINPID
280280
@@ -373,18 +373,18 @@ setFirewall() {
373373

374374
info() {
375375
ip=`curl -sL -4 ip.sb`
376-
port=`cat /etc/shadowsocks-libev/config.json | grep server_port | cut -d: -f2 | tr -d \",' '`
376+
port=`grep server_port $CONFIG_FILE | cut -d: -f2 | tr -d \",' '`
377377
res=`netstat -nltp | grep ${port} | grep 'ss-server'`
378378
[[ -z "$res" ]] && status="${RED}已停止${PLAIN}" || status="${GREEN}正在运行${PLAIN}"
379-
password=`cat /etc/shadowsocks-libev/config.json | grep password | cut -d: -f2 | tr -d \",' '`
380-
method=`cat /etc/shadowsocks-libev/config.json | grep method | cut -d: -f2 | tr -d \",' '`
379+
password=`grep password $CONFIG_FILE| cut -d: -f2 | tr -d \",' '`
380+
method=`grep method $CONFIG_FILE| cut -d: -f2 | tr -d \",' '`
381381

382382
res=`echo -n "${method}:${password}@${ip}:${port}" | base64 -w 0`
383383
link="ss://${res}"
384384

385385
echo ============================================
386386
echo -e " ${BLUE}ss运行状态${PLAIN}${status}"
387-
echo -e " ${BLUE}ss配置文件:${PLAIN}${RED}/etc/shadowsocks-libev/config.json${PLAIN}"
387+
echo -e " ${BLUE}ss配置文件:${PLAIN}${RED}$CONFIG_FILE${PLAIN}"
388388
echo ""
389389
echo -e " ${RED}ss配置信息:${PLAIN}"
390390
echo -e " ${BLUE}IP(address):${PLAIN} ${RED}${ip}${PLAIN}"

ssr.sh

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ BASE=`pwd`
1515

1616
OS=`hostnamectl | grep -i system | cut -d: -f2`
1717

18+
CONFIG_FILE="/etc/shadowsocksR.json"
19+
1820
colorEcho() {
1921
echo -e "${1}${@:2}${PLAIN}"
2022
}
@@ -300,7 +302,7 @@ installSSR() {
300302
cd ${BASE} && rm -rf shadowsocksr-3.2.2 ${FILENAME}.tar.gz
301303
fi
302304

303-
cat > /etc/shadowsocksR.json<<-EOF
305+
cat > $CONFIG_FILE<<-EOF
304306
{
305307
"server":"0.0.0.0",
306308
"server_ipv6":"[::]",
@@ -330,7 +332,7 @@ Wants=network-online.target
330332
[Service]
331333
Type=forking
332334
LimitNOFILE=32768
333-
ExecStart=/usr/local/shadowsocks/server.py -c /etc/shadowsocksR.json -d start
335+
ExecStart=/usr/local/shadowsocks/server.py -c $CONFIG_FILE -d start
334336
ExecReload=/bin/kill -s HUP \$MAINPID
335337
ExecStop=/bin/kill -s TERM \$MAINPID
336338
@@ -429,13 +431,13 @@ installBBR() {
429431

430432
info() {
431433
ip=`curl -sL -4 ip.sb`
432-
port=`cat /etc/shadowsocksR.json | grep server_port | cut -d: -f2 | tr -d \",' '`
434+
port=`grep server_port $CONFIG_FILE| cut -d: -f2 | tr -d \",' '`
433435
res=`netstat -nltp | grep ${port} | grep python`
434436
[[ -z "$res" ]] && status="${RED}已停止${PLAIN}" || status="${GREEN}正在运行${PLAIN}"
435-
password=`cat /etc/shadowsocksR.json | grep password | cut -d: -f2 | tr -d \",' '`
436-
method=`cat /etc/shadowsocksR.json | grep method | cut -d: -f2 | tr -d \",' '`
437-
protocol=`cat /etc/shadowsocksR.json | grep protocol | cut -d: -f2 | tr -d \",' '`
438-
obfs=`cat /etc/shadowsocksR.json | grep obfs | cut -d: -f2 | tr -d \",' '`
437+
password=`grep password $CONFIG_FILE| cut -d: -f2 | tr -d \",' '`
438+
method=`grep method $CONFIG_FILE| cut -d: -f2 | tr -d \",' '`
439+
protocol=`grep protocol $CONFIG_FILE| cut -d: -f2 | tr -d \",' '`
440+
obfs=`grep obfs $CONFIG_FILE| cut -d: -f2 | tr -d \",' '`
439441

440442
p1=`echo -n ${password} | base64 -w 0`
441443
p1=`echo -n ${p1} | tr -d =`
@@ -446,7 +448,7 @@ info() {
446448
echo ""
447449
echo ============================================
448450
echo -e " ${BLUE}ssr运行状态:${PLAIN}${status}"
449-
echo -e " ${BLUE}ssr配置文件:${PLAIN}${RED}/etc/shadowsocksR.json${PLAIN}"
451+
echo -e " ${BLUE}ssr配置文件:${PLAIN}${RED}$CONFIG_FILE${PLAIN}"
450452
echo ""
451453
echo -e " ${RED}ssr配置信息:${PLAIN}"
452454
echo -e " ${BLUE}IP(address):${PLAIN} ${RED}${ip}${PLAIN}"
@@ -491,7 +493,7 @@ uninstall() {
491493
[[ -z ${answer} ]] && answer="n"
492494

493495
if [[ "${answer}" == "y" ]] || [[ "${answer}" == "Y" ]]; then
494-
rm -f /etc/shadowsocksR.json
496+
rm -f $CONFIG_FILE
495497
rm -f /var/log/shadowsocks.log
496498
rm -rf /usr/local/shadowsocks
497499
systemctl disable shadowsocksR && systemctl stop shadowsocksR && rm -rf /usr/lib/systemd/system/shadowsocksR.service

ubuntu_install_ss.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,8 @@ installSS() {
228228

229229
echo "3" > /proc/sys/net/ipv4/tcp_fastopen
230230
echo "net.ipv4.tcp_fastopen = 3" >> /etc/sysctl.conf
231-
if [ ! -d /etc/shadowsocks-libev ];then
232-
mkdir /etc/shadowsocks-libev
233-
fi
231+
232+
mkdir -p /etc/shadowsocks-libev
234233
ssPath=`which ss-server`
235234
cat > /etc/shadowsocks-libev/config.json<<-EOF
236235
{

v2ray.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ installV2ray() {
725725
fi
726726
mkdir -p '/etc/v2ray' '/var/log/v2ray' && \
727727
unzip /tmp/v2ray/v2ray.zip -d /tmp/v2ray
728-
mkdir /usr/bin/v2ray
728+
mkdir -p /usr/bin/v2ray
729729
cp /tmp/v2ray/v2ctl /usr/bin/v2ray/; cp /tmp/v2ray/v2ray /usr/bin/v2ray/; cp /tmp/v2ray/geo* /usr/bin/v2ray/;
730730
chmod +x '/usr/bin/v2ray/v2ray' '/usr/bin/v2ray/v2ctl' || {
731731
colorEcho $RED " V2ray安装失败"

0 commit comments

Comments
 (0)