-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathss5i.sh
299 lines (258 loc) · 7.32 KB
/
ss5i.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
#!/usr/bin/env bash
#====================================================
# System Request:Centos 7+ or Ubuntu 20.4+
# Dscription: Socks5 Installation
# Version: 1.0
# email: [email protected]
# TG: @kangcw
#====================================================
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
cd "$(
cd "$(dirname "$0")" || exit
pwd
)" || exit
#fonts color
Green="\033[32m"
Red="\033[31m"
# Yellow="\033[33m"
GreenBG="\033[42;37m"
RedBG="\033[41;37m"
Font="\033[0m"
source '/etc/os-release'
#notification information
# Info="${Green}[信息]${Font}"
OK="${Green}[OK]${Font}"
error="${Red}[错误]${Font}"
check_system() {
if [[ "${ID}" == "centos" && ${VERSION_ID} -ge 7 ]]; then
echo -e "${OK} ${GreenBG} 当前系统为 Centos ${VERSION_ID} ${VERSION} ${Font}"
INS="yum"
# $INS update -y
yum remove firewalld -y ; yum install -y iptables-services ; iptables -F ; iptables -t filter -F ; systemctl enable iptables.service ; service iptables save ; systemctl start iptables.service
elif [[ "${ID}" == "debian" && ${VERSION_ID} -ge 8 ]]; then
echo -e "${OK} ${GreenBG} 当前系统为 Debian ${VERSION_ID} ${VERSION} ${Font}"
INS="apt"
$INS update -y
## 添加 apt源
elif [[ "${ID}" == "ubuntu" && $(echo "${VERSION_ID}" | cut -d '.' -f1) -ge 16 ]]; then
echo -e "${OK} ${GreenBG} 当前系统为 Ubuntu ${VERSION_ID} ${UBUNTU_CODENAME} ${Font}"
INS="apt"
$INS update
systemctl disable ufw.service ; systemctl stop ufw.service
else
echo -e "${Error} ${RedBG} 当前系统为 ${ID} ${VERSION_ID} 不在支持的系统列表内,安装中断 ${Font}"
exit 1
fi
$INS -y install lsof wget curl
}
is_root() {
if [ 0 == $UID ]; then
echo -e "${OK} ${GreenBG} 当前用户是root用户,进入安装流程 ${Font}"
sleep 3
else
echo -e "${Error} ${RedBG} 当前用户不是root用户,请切换到使用 'sudo -i' 切换到root用户后重新执行脚本 ${Font}"
exit 1
fi
}
judge() {
if [[ 0 -eq $? ]]; then
echo -e "${OK} ${GreenBG} $1 完成 ${Font}"
sleep 1
else
echo -e "${Error} ${RedBG} $1 失败${Font}"
exit 1
fi
}
sic_optimization() {
# 最大文件打开数
sed -i '/^\*\ *soft\ *nofile\ *[[:digit:]]*/d' /etc/security/limits.conf
sed -i '/^\*\ *hard\ *nofile\ *[[:digit:]]*/d' /etc/security/limits.conf
echo '* soft nofile 65536' >>/etc/security/limits.conf
echo '* hard nofile 65536' >>/etc/security/limits.conf
# 关闭 Selinux
if [[ "${ID}" == "centos" ]]; then
sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
setenforce 0
fi
}
port_set() {
read -rp "请设置连接端口(默认:1080):" port
[[ -z ${port} ]] && port="1080"
}
port_exist_check() {
if [[ 0 -eq $(lsof -i:"${port}" | grep -i -c "listen") ]]; then
echo -e "${OK} ${GreenBG} $1 端口未被占用 ${Font}"
sleep 1
else
echo -e "${Error} ${RedBG} 检测到 ${port} 端口被占用,以下为 ${port} 端口占用信息 ${Font}"
lsof -i:"${port}"
echo -e "${OK} ${GreenBG} 5s 后将尝试自动 kill 占用进程 ${Font}"
sleep 5
lsof -i:"${port}" | awk '{print $2}' | grep -v "PID" | xargs kill -9
echo -e "${OK} ${GreenBG} kill 完成 ${Font}"
sleep 1
fi
}
bbr_install() {
[ -f "tcp.sh" ] && rm -rf ./tcp.sh
wget -O tcp.sh --no-check-certificate "https://raw.githubusercontent.com/ylx2016/Linux-NetSpeed/master/tcp.sh" && chmod +x tcp.sh && ./tcp.sh
}
user_set() {
read -rp "请设置ss5账户。默认:admin):" user
[[ -z ${user} ]] && user="admin"
read -rp "请设置ss5连接密码。默认:admin):" passwd
[[ -z ${passwd} ]] && passwd="admin"
}
install_ss5() {
# Xray Installation
wget -O /usr/local/bin/socks --no-check-certificate https://github.com/kangcwei/ss5/releases/download/ss5/socks
chmod +x /usr/local/bin/socks
cat <<EOF > /etc/systemd/system/sockd.service
[Unit]
Description=Socks Service
After=network.target nss-lookup.target
[Service]
User=nobody
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
NoNewPrivileges=true
ExecStart=/usr/local/bin/socks run -config /etc/socks/config.yaml
Restart=on-failure
RestartPreventExitStatus=23
LimitNPROC=10000
LimitNOFILE=1000000
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable sockd.service &> /dev/null
}
config_install() {
#Xray Configuration
mkdir -p /etc/socks
cat <<EOF > /etc/socks/config.yaml
{
"log": {
"loglevel": "warning"
},
"routing": {
"domainStrategy": "AsIs"
},
"inbounds": [
{
"listen": "0.0.0.0",
"port": "$port",
"protocol": "socks",
"settings": {
"auth": "password",
"accounts": [
{
"user": "$user",
"pass": "$passwd"
}
],
"udp": true
},
"streamSettings": {
"network": "tcp"
}
}
],
"outbounds": [
{
"protocol": "freedom",
"tag": "direct"
},
{
"protocol": "blackhole",
"tag": "block"
}
]
}
EOF
systemctl start sockd.service
}
connect() {
IP=$(curl -4 http://ip.sb)
echo "协议:Socks5"
echo "IP: $IP"
echo "端口:$port"
echo "账户:$user"
echo "密码:$passwd"
echo "
IP: $IP
端口:$port
账户:$user
密码:$passwd
" >/root/ss5.txt
}
is_root
check_system
install() {
sic_optimization
port_set
port_exist_check
user_set
install_ss5
config_install
connect
systemctl restart sockd.service
judge "安装 ss5 "
}
del_ss5() {
systemctl stop sockd.service
rm -rf /usr/local/bin/socks
rm -rf /etc/systemd/system/sockd.service
systemctl daemon-reload
rm -rf /etc/socks
judge "删除 ss5 "
}
update_ss5() {
port_set
port_exist_check
user_set
rm -rf /etc/socks/config.yaml
config_install
systemctl restart sockd.service
connect
}
menu() {
echo -e "\t ss5 安装管理脚本 "
echo -e "\t---authored by kangcw---"
echo -e "\thttps://www.google.com"
echo -e "\tSystem Request:Debian 9+/Ubuntu 20.04+/Centos 7+"
echo -e "\t站群搭建多IP联系63979483\n"
echo -e "—————————————— 安装向导 ——————————————"
echo -e "${Green} 搭建调试IPV6 站群多IP搭建 联系QQ 63979483${Font}"
echo -e "${Red} 调试MikroTik RouterOS软路由 站群搭建 分流IP${Font}"
echo -e "${Green}1.${Font} 安装ss5"
echo -e "${Green}2.${Font} 停止ss5"
echo -e "${Green}3.${Font} 删除ss5"
echo -e "${Green}4.${Font} 更改端口账户密码"
# echo -e "${Green}5.${Font} install BBR"
echo -e "${Green}99.${Font} 退出 \n"
read -rp "请输入数字:" menu_num
case $menu_num in
1)
install
;;
2)
systemctl stop sockd.service
judge "停止 ss5 "
;;
3)
del_ss5
;;
4)
update_ss5
;;
99)
exit 0
;;
*)
echo -e "${RedBG}请输入正确的数字${Font}"
;;
esac
}
menu