-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.sh
227 lines (218 loc) · 7.38 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
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
#!/bin/bash
export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
#Check Root
[ $(id -u) != "0" ] && { echo "Error: You must be root to run this script"; exit 1; }
#Check OS
if [ -n "$(grep 'Aliyun Linux release' /etc/issue)" -o -e /etc/redhat-release ];then
OS=CentOS
[ -n "$(grep ' 7\.' /etc/redhat-release)" ] && CentOS_RHEL_version=7
[ -n "$(grep ' 6\.' /etc/redhat-release)" -o -n "$(grep 'Aliyun Linux release6 15' /etc/issue)" ] && CentOS_RHEL_version=6
[ -n "$(grep ' 5\.' /etc/redhat-release)" -o -n "$(grep 'Aliyun Linux release5' /etc/issue)" ] && CentOS_RHEL_version=5
elif [ -n "$(grep 'Amazon Linux AMI release' /etc/issue)" -o -e /etc/system-release ];then
OS=CentOS
CentOS_RHEL_version=6
elif [ -n "$(grep bian /etc/issue)" -o "$(lsb_release -is 2>/dev/null)" == 'Debian' ];then
OS=Debian
[ ! -e "$(which lsb_release)" ] && { apt-get -y update; apt-get -y install lsb-release; clear; }
Debian_version=$(lsb_release -sr | awk -F. '{print $1}')
elif [ -n "$(grep Deepin /etc/issue)" -o "$(lsb_release -is 2>/dev/null)" == 'Deepin' ];then
OS=Debian
[ ! -e "$(which lsb_release)" ] && { apt-get -y update; apt-get -y install lsb-release; clear; }
Debian_version=$(lsb_release -sr | awk -F. '{print $1}')
elif [ -n "$(grep Ubuntu /etc/issue)" -o "$(lsb_release -is 2>/dev/null)" == 'Ubuntu' -o -n "$(grep 'Linux Mint' /etc/issue)" ];then
OS=Ubuntu
[ ! -e "$(which lsb_release)" ] && { apt-get -y update; apt-get -y install lsb-release; clear; }
Ubuntu_version=$(lsb_release -sr | awk -F. '{print $1}')
[ -n "$(grep 'Linux Mint 18' /etc/issue)" ] && Ubuntu_version=16
else
echo "Does not support this OS, Please contact the author! "
kill -9 $$
fi
#Get Current Directory
workdir=$(pwd)
#Install Basic Tools
if [ ! -e /usr/local/bin/ssr ];then
if [[ $1 == "uninstall" ]];then
echo "你在开玩笑吗?你都没有安装怎么卸载呀!"
exit 1
fi
echo "开始部署"
sleep 2s
if [[ ${OS} == Ubuntu ]];then
apt-get update
apt-get install python -y
apt-get install python-pip -y
apt-get install git -y
apt-get install language-pack-zh-hans -y
apt-get install bc -y
apt-get install build-essential screen curl -y
fi
if [[ ${OS} == CentOS ]];then
yum install python screen curl -y
yum install python-setuptools -y && easy_install pip -y
yum install git -y
yum install bc -y
yum groupinstall "Development Tools" -y
fi
if [[ ${OS} == Debian ]];then
apt-get update
apt-get install python screen curl -y
apt-get install python-pip -y
apt-get install git -y
apt-get install bc -y
apt-get install build-essential -y
fi
#Install Libsodium
libsodiumfile="/usr/local/lib/libsodium.so"
if [[ ! -e ${libsodiumfile} ]];then
cd $workdir
export LIBSODIUM_VER=1.0.13
wget -q https://github.com/jedisct1/libsodium/releases/download/1.0.13/libsodium-$LIBSODIUM_VER.tar.gz
tar xvf libsodium-$LIBSODIUM_VER.tar.gz
pushd libsodium-$LIBSODIUM_VER
./configure --prefix=/usr && make
make install
popd
ldconfig
cd $workdir && rm -rf libsodium-$LIBSODIUM_VER.tar.gz libsodium-$LIBSODIUM_VER
# if [[ ! -e ${libsodiumfile} ]];then
# echo "libsodium安装失败 !"
# exit 1
# fi
else
echo "libsodium已安装!"
fi
cd /usr/local
git clone https://github.com/Readour/shadowsocksr.git
cd ./shadowsocksr
git manyuser
git pull
if [ $1 == "develop" ];then
git checkout stack/dev
fi
fi
#Install SSR and SSR-Bash
if [ -e /usr/local/bin/ssr ];then
if [[ $1 == "uninstall" ]];then
echo "开始卸载"
sleep 1s
echo "删除:/usr/local/bin/ssr"
rm -f /usr/local/bin/ssr
echo "删除:/usr/local/SSR-Bash-Python"
rm -rf /usr/local/SSR-Bash-Python
echo "删除:/usr/local/shadowsocksr"
rm -rf /usr/local/shadowsocksr
echo "删除:${PWD}/install.sh"
rm -f ${PWD}/install.sh
sleep 1s
echo "卸载完成!!"
exit 0
fi
echo "开始更新"
sleep 1s
echo "正在清理老版本"
rm -f /usr/local/bin/ssr
rm -rf /usr/local/SSR-Bash-Python
sleep 1s
echo "开始部署"
cd /usr/local/shadowsocksr
git pull
git checkout manyuser
if [[ $1 == "develop" ]];then
git checkout stack/dev
fi
fi
cd /usr/local
git clone https://github.com/Readour/AR-B-P-B.git
cd AR-B-P-B
git checkout master
if [[ $1 == "develop" ]];then
git checkout develop
fi
cd ..
mv AR-B-P-B SSR-Bash-Python
cd /usr/local/shadowsocksr
bash initcfg.sh
if [[ ! -e /usr/bin/bc ]];then
if [[ ${OS} == CentOS ]];then
yum install bc -y
fi
if [[ ${OS} == Ubuntu || ${OS} == Debian ]];then
apt-get install bc -y
fi
fi
#Start when boot
if [[ ${OS} == Ubuntu || ${OS} == Debian ]];then
cat >/etc/init.d/ssr-bash-python <<EOF
#!/bin/sh
### BEGIN INIT INFO
# Provides: SSR-Bash_python
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Should-Start: $network
# Should-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: SSR-Bash-Python
# Description: SSR-Bash-Python
### END INIT INFO
iptables-restore < /etc/iptables.up.rules
bash /usr/local/shadowsocksr/logrun.sh
EOF
chmod 755 /etc/init.d/ssr-bash-python
chmod +x /etc/init.d/ssr-bash-python
cd /etc/init.d
update-rc.d ssr-bash-python defaults 95
fi
if [[ ${OS} == CentOS ]];then
echo "
iptables-restore < /etc/iptables.up.rules
bash /usr/local/shadowsocksr/logrun.sh
" > /etc/rc.d/init.d/ssr-bash-python
chmod +x /etc/rc.d/init.d/ssr-bash-python
echo "/etc/rc.d/init.d/ssr-bash-python" >> /etc/rc.d/rc.local
chmod +x /etc/rc.d/rc.local
fi
#Change CentOS7 Firewall
if [[ ${OS} == CentOS && $CentOS_RHEL_version == 7 ]];then
systemctl stop firewalld.service
systemctl disable firewalld.service
yum install iptables-services -y
cat << EOF > /etc/sysconfig/iptables
# sample configuration for iptables service
# you can edit this manually or use system-config-firewall
# please do not ask us to add additional ports/services to this default configuration
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
EOF
systemctl restart iptables.service
systemctl enable iptables.service
fi
#Install SSR-Bash Background
wget -N --no-check-certificate -O /usr/local/bin/ssr https://raw.githubusercontent.com/readour/AR-B-P-B/master/ssr
chmod +x /usr/local/bin/ssr
#Modify ShadowsocksR API
sed -i "s/sspanelv2/mudbjson/g" /usr/local/shadowsocksr/userapiconfig.py
sed -i "s/UPDATE_TIME = 60/UPDATE_TIME = 10/g" /usr/local/shadowsocksr/userapiconfig.py
sed -i "s/SERVER_PUB_ADDR = '127.0.0.1'/SERVER_PUB_ADDR = '$(wget -qO- -t1 -T2 ipinfo.io/ip)'/" /usr/local/shadowsocksr/userapiconfig.py
#INstall Success
read -p "输入与您主机绑定的域名: " ipname
echo "$ipname" > /usr/local/shadowsocksr/myip.txt
bash /usr/local/SSR-Bash-Python/self-check.sh
echo '安装完成!输入 ssr 即可使用本程序~'
echo '原作者已经停止本脚本服务,此版本为2017.7.30号的备份(带最新端口限速)'
echo '还好在作者删服务前备份了'
echo '谨慎使用!仅供研究!'
echo '谨慎使用!仅供研究!'
echo '谨慎使用!仅供研究!'