-
Notifications
You must be signed in to change notification settings - Fork 143
/
install.sh
111 lines (100 loc) · 2.68 KB
/
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
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
pluginPath=/www/server/panel/plugin/ss
if [ ! -f /etc/init.d/bt ];then
echo 'No BT-Panel is installed, please go to http://www.bt.cn installation.';
exit;
fi
Install_ss()
{
pip install shadowsocks m2crypto
mkdir -p $pluginPath
\cp -a -r ss_main.py icon.png info.json index.html install.sh ss.init shadowsocks.zip shadowsocks-nightly-4.2.5.apk $pluginPath/
\cp -a -r ss.init /etc/init.d/ss
chmod +x /etc/init.d/ss
chkconfig --add ss
chkconfig --level 2345 ss on
password=`cat /dev/urandom | head -n 16 | md5sum | head -c 16`
cat > $pluginPath/config.json <<EOF
{
"server":"0.0.0.0",
"local_address":"127.0.0.1",
"local_port":1080,
"port_password":{
"62443":"$password"
},
"timeout":300,
"method":"aes-256-cfb",
"fast_open":false
}
EOF
groupadd ssuser
useradd -s /sbin/nologin -M -g ssuser ssuser
chown ssuser:ssuser $pluginPath/config.json
Set_port 62443
/etc/init.d/ss start
}
Set_port()
{
if [ -f "/usr/sbin/ufw" ];then
ufw allow $1/tcp
ufw allow $1/udp
ufw reload
fi
if [ -f "/etc/sysconfig/firewalld" ];then
firewall-cmd --permanent --zone=public --add-port=$1/tcp
firewall-cmd --permanent --zone=public --add-port=$1/udp
firewall-cmd --reload
fi
if [ -f "/etc/init.d/iptables" ];then
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport $1 -j ACCEPT
iptables -I INPUT -p udp -m state --state NEW -m udp --dport $1 -j ACCEPT
/etc/init.d/iptables save
fi
}
Remove_port()
{
if [ -f "/usr/sbin/ufw" ];then
ufw delete allow $1/tcp
ufw delete allow $1/udp
ufw reload
fi
if [ -f "/etc/sysconfig/firewalld" ];then
firewall-cmd --permanent --zone=public --remove-port=$1/tcp
firewall-cmd --permanent --zone=public --remove-port=$1/udp
firewall-cmd --reload
fi
if [ -f "/etc/init.d/iptables" ];then
iptables -D INPUT -p tcp -m state --state NEW -m tcp --dport $1 -j ACCEPT
iptables -D INPUT -p udp -m state --state NEW -m udp --dport $1 -j ACCEPT
/etc/init.d/iptables save
fi
}
Uninstall_ss()
{
/etc/init.d/ss stop
chkconfig --del ss
rm -f /etc/init.d/ss
rm -rf $pluginPath
pip uninstall shadowsocks -y
userdel ssuser
groupdel ssuser
}
if [ "${1}" == 'install' ];then
Install_ss
elif [ "${1}" == 'uninstall' ];then
Uninstall_ss
elif [ "${1}" == 'port' ];then
Set_port $2
elif [ "${1}" == 'rmport' ];then
Remove_port $2
else
while [ "$isInstall" != 'y' ] && [ "$isInstall" != 'n' ]
do
read -p "Do you really want to install ss-plugin to BT-Panel?(y/n): " isInstall;
done
if [ "$isInstall" = 'y' ] || [ "$isInstall" = 'Y' ];then
Install_ss
fi
fi