-
Notifications
You must be signed in to change notification settings - Fork 796
/
sb_00.sh
393 lines (361 loc) · 12.8 KB
/
sb_00.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
383
384
385
386
387
388
389
390
391
392
393
#!/bin/bash
# 定义颜色
re="\033[0m"
red="\033[1;91m"
green="\e[1;32m"
yellow="\e[1;33m"
purple="\e[1;35m"
red() { echo -e "\e[1;91m$1\033[0m"; }
green() { echo -e "\e[1;32m$1\033[0m"; }
yellow() { echo -e "\e[1;33m$1\033[0m"; }
purple() { echo -e "\e[1;35m$1\033[0m"; }
reading() { read -p "$(red "$1")" "$2"; }
USERNAME=$(whoami)
HOSTNAME=$(hostname)
export UUID=${UUID:-'bc97f674-c578-4940-9234-0a1da46041b9'}
export NEZHA_SERVER=${NEZHA_SERVER:-''}
export NEZHA_PORT=${NEZHA_PORT:-'5555'}
export NEZHA_KEY=${NEZHA_KEY:-''}
[[ "$HOSTNAME" == "s1.ct8.pl" ]] && WORKDIR="domains/${USERNAME}.ct8.pl/logs" || WORKDIR="domains/${USERNAME}.serv00.net/logs"
[ -d "$WORKDIR" ] || (mkdir -p "$WORKDIR" && chmod 777 "$WORKDIR")
bash -c 'ps aux | grep $(whoami) | grep -v "sshd\|bash\|grep" | awk "{print \$2}" | xargs -r kill -9 >/dev/null 2>&1' >/dev/null 2>&1
read_vless_port() {
while true; do
reading "请输入vless-reality端口 (面板开放的tcp端口): " vless_port
if [[ "$vless_port" =~ ^[0-9]+$ ]] && [ "$vless_port" -ge 1 ] && [ "$vless_port" -le 65535 ]; then
green "你的vless-reality端口为: $vless_port"
break
else
yellow "输入错误,请重新输入面板开放的TCP端口"
fi
done
}
read_hy2_port() {
while true; do
reading "请输入hysteria2端口 (面板开放的UDP端口): " hy2_port
if [[ "$hy2_port" =~ ^[0-9]+$ ]] && [ "$hy2_port" -ge 1 ] && [ "$hy2_port" -le 65535 ]; then
green "你的hysteria2端口为: $hy2_port"
break
else
yellow "输入错误,请重新输入面板开放的UDP端口"
fi
done
}
read_tuic_port() {
while true; do
reading "请输入Tuic端口 (面板开放的UDP端口): " tuic_port
if [[ "$tuic_port" =~ ^[0-9]+$ ]] && [ "$tuic_port" -ge 1 ] && [ "$tuic_port" -le 65535 ]; then
green "你的tuic端口为: $tuic_port"
break
else
yellow "输入错误,请重新输入面板开放的UDP端口"
fi
done
}
read_nz_variables() {
if [ -n "$NEZHA_SERVER" ] && [ -n "$NEZHA_PORT" ] && [ -n "$NEZHA_KEY" ]; then
green "使用自定义变量哪吒运行哪吒探针"
return
else
reading "是否需要安装哪吒探针?【y/n】: " nz_choice
[[ -z $nz_choice ]] && return
[[ "$nz_choice" != "y" && "$nz_choice" != "Y" ]] && return
reading "请输入哪吒探针域名或ip:" NEZHA_SERVER
green "你的哪吒域名为: $NEZHA_SERVER"
reading "请输入哪吒探针端口(回车跳过默认使用5555):" NEZHA_PORT
[[ -z $NEZHA_PORT ]] && NEZHA_PORT="5555"
green "你的哪吒端口为: $NEZHA_PORT"
reading "请输入哪吒探针密钥:" NEZHA_KEY
green "你的哪吒密钥为: $NEZHA_KEY"
fi
}
install_singbox() {
echo -e "${yellow}本脚本同时三协议共存${purple}(vless-reality|hysteria2|tuic)${re}"
echo -e "${yellow}开始运行前,请确保在面板${purple}已开放3个端口,一个tcp端口和两个udp端口${re}"
echo -e "${yellow}面板${purple}Additional services中的Run your own applications${yellow}已开启为${purplw}Enabled${yellow}状态${re}"
reading "\n确定继续安装吗?【y/n】: " choice
case "$choice" in
[Yy])
cd $WORKDIR
read_nz_variables
read_vless_port
read_hy2_port
read_tuic_port
download_and_run_singbox
get_links
;;
[Nn]) exit 0 ;;
*) red "无效的选择,请输入y或n" && menu ;;
esac
}
uninstall_singbox() {
reading "\n确定要卸载吗?【y/n】: " choice
case "$choice" in
[Yy])
ps aux | grep $(whoami) | grep -v "sshd\|bash\|grep" | awk '{print $2}' | xargs -r kill -9 2>/dev/null
rm -rf $WORKDIR
clear
green "已完全卸载"
;;
[Nn]) exit 0 ;;
*) red "无效的选择,请输入y或n" && menu ;;
esac
}
kill_all_tasks() {
reading "\n清理所有进程将退出ssh连接,确定继续清理吗?【y/n】: " choice
case "$choice" in
[Yy]) killall -9 -u $(whoami) ;;
*) menu ;;
esac
}
# Download Dependency Files
download_and_run_singbox() {
ARCH=$(uname -m) && DOWNLOAD_DIR="." && mkdir -p "$DOWNLOAD_DIR" && FILE_INFO=()
if [ "$ARCH" == "arm" ] || [ "$ARCH" == "arm64" ] || [ "$ARCH" == "aarch64" ]; then
FILE_INFO=("https://github.com/eooce/test/releases/download/arm64/sb web" "https://github.com/eooce/test/releases/download/ARM/swith npm")
elif [ "$ARCH" == "amd64" ] || [ "$ARCH" == "x86_64" ] || [ "$ARCH" == "x86" ]; then
FILE_INFO=("https://github.com/eooce/test/releases/download/freebsd/sb web" "https://github.com/eooce/test/releases/download/freebsd/npm npm")
else
echo "Unsupported architecture: $ARCH"
exit 1
fi
declare -A FILE_MAP
generate_random_name() {
local chars=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890
local name=""
for i in {1..6}; do
name="$name${chars:RANDOM%${#chars}:1}"
done
echo "$name"
}
download_with_fallback() {
local URL=$1
local NEW_FILENAME=$2
curl -L -sS --max-time 2 -o "$NEW_FILENAME" "$URL" &
CURL_PID=$!
CURL_START_SIZE=$(stat -c%s "$NEW_FILENAME" 2>/dev/null || echo 0)
sleep 1
CURL_CURRENT_SIZE=$(stat -c%s "$NEW_FILENAME" 2>/dev/null || echo 0)
if [ "$CURL_CURRENT_SIZE" -le "$CURL_START_SIZE" ]; then
kill $CURL_PID 2>/dev/null
wait $CURL_PID 2>/dev/null
wget -q -O "$NEW_FILENAME" "$URL"
echo -e "\e[1;32mDownloading $NEW_FILENAME by wget\e[0m"
else
wait $CURL_PID
echo -e "\e[1;32mDownloading $NEW_FILENAME by curl\e[0m"
fi
}
for entry in "${FILE_INFO[@]}"; do
URL=$(echo "$entry" | cut -d ' ' -f 1)
RANDOM_NAME=$(generate_random_name)
NEW_FILENAME="$DOWNLOAD_DIR/$RANDOM_NAME"
if [ -e "$NEW_FILENAME" ]; then
echo -e "\e[1;32m$NEW_FILENAME already exists, Skipping download\e[0m"
else
download_with_fallback "$URL" "$NEW_FILENAME"
fi
chmod +x "$NEW_FILENAME"
FILE_MAP[$(echo "$entry" | cut -d ' ' -f 2)]="$NEW_FILENAME"
done
wait
output=$(./"$(basename ${FILE_MAP[web]})" generate reality-keypair)
private_key=$(echo "${output}" | awk '/PrivateKey:/ {print $2}')
public_key=$(echo "${output}" | awk '/PublicKey:/ {print $2}')
openssl ecparam -genkey -name prime256v1 -out "private.key"
openssl req -new -x509 -days 3650 -key "private.key" -out "cert.pem" -subj "/CN=$USERNAME.serv00.net"
yellow "获取可用IP中,请稍等..."
available_ip=$(get_ip)
purple "当前选择IP为:$available_ip 如安装完后节点不通可尝试重新安装"
cat > config.json << EOF
{
"log": {
"disabled": true,
"level": "info",
"timestamp": true
},
"dns": {
"servers": [
{
"address": "8.8.8.8",
"address_resolver": "local"
},
{
"tag": "local",
"address": "local"
}
]
},
"inbounds": [
{
"tag": "hysteria-in",
"type": "hysteria2",
"listen": "$available_ip",
"listen_port": $hy2_port,
"users": [
{
"password": "$UUID"
}
],
"masquerade": "https://bing.com",
"tls": {
"enabled": true,
"alpn": [
"h3"
],
"certificate_path": "cert.pem",
"key_path": "private.key"
}
},
{
"tag": "vless-reality-vesion",
"type": "vless",
"listen": "$available_ip",
"listen_port": $vless_port,
"users": [
{
"uuid": "$UUID",
"flow": "xtls-rprx-vision"
}
],
"tls": {
"enabled": true,
"server_name": "www.cerebrium.ai",
"reality": {
"enabled": true,
"handshake": {
"server": "www.cerebrium.ai",
"server_port": 443
},
"private_key": "$private_key",
"short_id": [
""
]
}
}
},
{
"tag": "tuic-in",
"type": "tuic",
"listen": "$available_ip",
"listen_port": $tuic_port,
"users": [
{
"uuid": "$UUID",
"password": "admin123"
}
],
"congestion_control": "bbr",
"tls": {
"enabled": true,
"alpn": [
"h3"
],
"certificate_path": "cert.pem",
"key_path": "private.key"
}
}
],
"outbounds": [
{
"tag": "direct",
"type": "direct"
},
{
"tag": "block",
"type": "block"
}
]
}
EOF
if [ -e "$(basename ${FILE_MAP[npm]})" ]; then
tlsPorts=("443" "8443" "2096" "2087" "2083" "2053")
if [[ "${tlsPorts[*]}" =~ "${NEZHA_PORT}" ]]; then
NEZHA_TLS="--tls"
else
NEZHA_TLS=""
fi
if [ -n "$NEZHA_SERVER" ] && [ -n "$NEZHA_PORT" ] && [ -n "$NEZHA_KEY" ]; then
export TMPDIR=$(pwd)
nohup ./"$(basename ${FILE_MAP[npm]})" -s ${NEZHA_SERVER}:${NEZHA_PORT} -p ${NEZHA_KEY} ${NEZHA_TLS} >/dev/null 2>&1 &
sleep 2
pgrep -x "$(basename ${FILE_MAP[npm]})" > /dev/null && green "$(basename ${FILE_MAP[npm]}) is running" || { red "$(basename ${FILE_MAP[npm]}) is not running, restarting..."; pkill -x "$(basename ${FILE_MAP[npm]})" && nohup ./"$(basename ${FILE_MAP[npm]})" -s "${NEZHA_SERVER}:${NEZHA_PORT}" -p "${NEZHA_KEY}" ${NEZHA_TLS} >/dev/null 2>&1 & sleep 2; purple "$(basename ${FILE_MAP[npm]}) restarted"; }
else
purple "NEZHA variable is empty, skipping running"
fi
fi
if [ -e "$(basename ${FILE_MAP[web]})" ]; then
nohup ./"$(basename ${FILE_MAP[web]})" run -c config.json >/dev/null 2>&1 &
sleep 2
pgrep -x "$(basename ${FILE_MAP[web]})" > /dev/null && green "$(basename ${FILE_MAP[web]}) is running" || { red "$(basename ${FILE_MAP[web]}) is not running, restarting..."; pkill -x "$(basename ${FILE_MAP[web]})" && nohup ./"$(basename ${FILE_MAP[web]})" run -c config.json >/dev/null 2>&1 & sleep 2; purple "$(basename ${FILE_MAP[web]}) restarted"; }
fi
sleep 1
rm -f "$(basename ${FILE_MAP[npm]})" "$(basename ${FILE_MAP[web]})"
}
get_ip() {
IP_LIST=($(devil vhost list | awk '/^[0-9]+/ {print $1}'))
URL_TEMPLATE="https://www.toolsdaquan.com/toolapi/public/ipchecking"
REFERER="https://www.toolsdaquan.com/ipcheck"
IP=""
THIRD_IP=${IP_LIST[2]}
RESPONSE=$(curl -s --location --max-time 3 --request GET "${URL_TEMPLATE}/${THIRD_IP}/22" --header "Referer: ${REFERER}")
if [[ $RESPONSE == '{"tcp":"success","icmp":"success"}' ]]; then
IP=$THIRD_IP
else
FIRST_IP=${IP_LIST[0]}
RESPONSE=$(curl -s --location --max-time 3 --request GET "${URL_TEMPLATE}/${FIRST_IP}/22" --header "Referer: ${REFERER}")
if [[ $RESPONSE == '{"tcp":"success","icmp":"success"}' ]]; then
IP=$FIRST_IP
else
IP=${IP_LIST[1]}
fi
fi
echo "$IP"
}
get_links(){
ISP=$(curl -s --max-time 2 https://speed.cloudflare.com/meta | awk -F\" '{print $26}' | sed -e 's/ /_/g' || echo "0")
get_name() { if [ "$HOSTNAME" = "s1.ct8.pl" ]; then SERVER="CT8"; else SERVER=$(echo "$HOSTNAME" | cut -d '.' -f 1); fi; echo "$SERVER"; }
NAME="$ISP-$(get_name)"
yellow "注意:v2ray或其他软件的跳过证书验证需设置为true,否则hy2或tuic节点可能不通\n"
cat > list.txt <<EOF
vless://$UUID@$available_ip:$vless_port?encryption=none&flow=xtls-rprx-vision&security=reality&sni=www.cerebrium.ai&fp=chrome&pbk=$public_key&type=tcp&headerType=none#$NAME-reality
hysteria2://$UUID@$available_ip:$hy2_port/?sni=www.bing.com&alpn=h3&insecure=1#$NAME-hy2
tuic://$UUID:admin123@$available_ip:$tuic_port?sni=www.bing.com&congestion_control=bbr&udp_relay_mode=native&alpn=h3&allow_insecure=1#$NAME-tuic
EOF
cat list.txt
purple "\n$WORKDIR/list.txt saved successfully"
purple "Running done!\n"
sleep 3
rm -rf config.json sb.log core fake_useragent_0.2.0.json
}
#主菜单
menu() {
clear
echo ""
purple "=== Serv00|ct8老王sing-box一键三协议安装脚本 ===\n"
echo -e "${green}脚本地址:${re}${yellow}https://github.com/eooce/Sing-box${re}\n"
echo -e "${green}反馈论坛:${re}${yellow}https://bbs.vps8.me${re}\n"
echo -e "${green}TG反馈群组:${re}${yellow}https://t.me/vps888${re}\n"
purple "转载请著名出处,请勿滥用\n"
green "1. 安装sing-box"
echo "==============="
red "2. 卸载sing-box"
echo "==============="
green "3. 查看节点信息"
echo "==============="
yellow "4. 清理所有进程"
echo "==============="
red "0. 退出脚本"
echo "==========="
reading "请输入选择(0-3): " choice
echo ""
case "${choice}" in
1) install_singbox ;;
2) uninstall_singbox ;;
3) cat $WORKDIR/list.txt ;;
4) kill_all_tasks ;;
0) exit 0 ;;
*) red "无效的选项,请输入 0 到 4" ;;
esac
}
menu