-
Notifications
You must be signed in to change notification settings - Fork 891
/
Copy pathsb_serv00.sh
752 lines (684 loc) · 28 KB
/
sb_serv00.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
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
#!/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"; }
export LC_ALL=C
HOSTNAME=$(hostname)
USERNAME=$(whoami | tr '[:upper:]' '[:lower:]')
export UUID=${UUID:-'bc97f674-c578-4940-9234-0a1da46041b0'}
export NEZHA_SERVER=${NEZHA_SERVER:-''}
export NEZHA_PORT=${NEZHA_PORT:-'5555'}
export NEZHA_KEY=${NEZHA_KEY:-''}
export ARGO_DOMAIN=${ARGO_DOMAIN:-''}
export ARGO_AUTH=${ARGO_AUTH:-''}
export CFIP=${CFIP:-'www.visa.com.tw'}
export CFPORT=${CFPORT:-'443'}
export SUB_TOKEN=${SUB_TOKEN:-${UUID:0:8}}
[[ "$HOSTNAME" == "s1.ct8.pl" ]] && WORKDIR="${HOME}/domains/${USERNAME}.ct8.pl/logs" && FILE_PATH="${HOME}/domains/${USERNAME}.ct8.pl/public_html" || WORKDIR="${HOME}/domains/${USERNAME}.serv00.net/logs" && FILE_PATH="${HOME}/domains/${USERNAME}.serv00.net/public_html"
rm -rf "$WORKDIR" && mkdir -p "$WORKDIR" "$FILE_PATH" && chmod 777 "$WORKDIR" "$FILE_PATH" >/dev/null 2>&1
check_binexec_and_port () {
port_list=$(devil port list)
tcp_ports=$(echo "$port_list" | grep -c "tcp")
udp_ports=$(echo "$port_list" | grep -c "udp")
if [[ $tcp_ports -ne 1 || $udp_ports -ne 2 ]]; then
red "端口规则不符合要求,正在调整..."
if [[ $tcp_ports -gt 1 ]]; then
tcp_to_delete=$((tcp_ports - 1))
echo "$port_list" | awk '/tcp/ {print $1, $2}' | head -n $tcp_to_delete | while read port type; do
devil port del $type $port >/dev/null 2>&1
green "已删除TCP端口: $port"
done
fi
if [[ $udp_ports -gt 2 ]]; then
udp_to_delete=$((udp_ports - 2))
echo "$port_list" | awk '/udp/ {print $1, $2}' | head -n $udp_to_delete | while read port type; do
devil port del $type $port >/dev/null 2>&1
green "已删除UDP端口: $port"
done
fi
if [[ $tcp_ports -lt 1 ]]; then
while true; do
tcp_port=$(shuf -i 10000-65535 -n 1)
result=$(devil port add tcp $tcp_port 2>&1)
if [[ $result == *"succesfully"* ]]; then
green "已添加TCP端口: $tcp_port"
break
else
yellow "端口 $tcp_port 不可用,尝试其他端口..."
fi
done
fi
if [[ $udp_ports -lt 2 ]]; then
udp_ports_to_add=$((2 - udp_ports))
udp_ports_added=0
while [[ $udp_ports_added -lt $udp_ports_to_add ]]; do
udp_port=$(shuf -i 10000-65535 -n 1)
result=$(devil port add udp $udp_port 2>&1)
if [[ $result == *"succesfully"* ]]; then
green "已添加UDP端口: $udp_port"
if [[ $udp_ports_added -eq 0 ]]; then
udp_port1=$udp_port
else
udp_port2=$udp_port
fi
udp_ports_added=$((udp_ports_added + 1))
else
yellow "端口 $udp_port 不可用,尝试其他端口..."
fi
done
fi
green "端口已调整完成,将断开ssh连接,请重新连接shh重新执行脚本"
devil binexec on >/dev/null 2>&1
kill -9 $(ps -o ppid= -p $$) >/dev/null 2>&1
else
tcp_port=$(echo "$port_list" | awk '/tcp/ {print $1}')
udp_ports=$(echo "$port_list" | awk '/udp/ {print $1}')
udp_port1=$(echo "$udp_ports" | sed -n '1p')
udp_port2=$(echo "$udp_ports" | sed -n '2p')
purple "当前TCP端口: $tcp_port"
purple "当前UDP端口: $udp_port1 和 $udp_port2"
fi
export VMESS_PORT=$tcp_port
export TUIC_PORT=$udp_port1
export HY2_PORT=$udp_port2
}
changge_ports() {
reading "将删除全部端口然后随机开放1个tcp端口和2个udp端口,确定继续吗?(直接回车即确认更换)【y/n】: " choice
if [[ -z "$choice" || "$choice" == "y" || "$choice" == "Y" ]]; then
devil port list | grep -E "^\s*[0-9]+" | while read -r line; do
port=$(echo "$line" | awk '{print $1}')
proto=$(echo "$line" | awk '{print $2}')
if [[ "$proto" != "tcp" && "$proto" != "udp" ]]; then
continue
fi
if ! [[ "$port" =~ ^[0-9]+$ ]]; then
continue
fi
if devil port del "${proto}" "${port}" > /dev/null 2>&1; then
green "Port ${port}/${proto} has been removed successfully"
else
red "Failed to remove port ${port}/${proto}"
fi
done
check_binexec_and_port
else
menu
fi
}
check_website() {
CURRENT_SITE=$(devil www list | awk -v username="${USERNAME}" '$1 == username".serv00.net" && $2 == "php" {print $0}')
if [ -n "$CURRENT_SITE" ]; then
green "检测到已存在${USERNAME}.serv00.net的php站点,无需修改"
else
EXIST_SITE=$(devil www list | awk -v username="${USERNAME}" '$1 == username".serv00.net" {print $0}')
if [ -n "$EXIST_SITE" ]; then
red "不存在${USERNAME}.serv00.net的php站点,正在为你调整..."
devil www del "${USERNAME}.serv00.net"
devil www add "${USERNAME}.serv00.net" php "$HOME/domains/${USERNAME}.serv00.net"
green "已删除旧站点并创建新的php站点"
else
devil www add "${USERNAME}.serv00.net" php "$HOME/domains/${USERNAME}.serv00.net"
green "php站点创建完成"
fi
fi
}
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() {
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
echo -e "${yellow}本脚本同时四协议共存${purple}(vmess-ws,vmess-ws-tls(argo),hysteria2,tuic)${re}"
reading "\n确定继续安装吗?(直接回车即确认安装)【y/n】: " choice
case "${choice:-y}" in
[Yy]|"")
cd $WORKDIR
check_binexec_and_port
check_website
read_nz_variables
argo_configure
generate_config
download_singbox
get_links
;;
[Nn]) exit 0 ;;
*) red "无效的选择,请输入y或n" && menu ;;
esac
}
uninstall_singbox() {
reading "\n确定要卸载吗?【y/n】: " choice
case "$choice" in
[Yy])
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
rm -rf $WORKDIR && find ${FILE_PATH} -mindepth 1 ! -name 'index.html' -exec rm -rf {} +
devil www del keep.${USERNAME}.serv00.net nodejs 2>/dev/null || true
rm -rf ${HOME}/domains/${USERNAME}.serv00.net/public_nodejs 2 >/dev/null || true
rm -rf "${HOME}/bin/00" >/dev/null 2>&1
[ -d "${HOME}/bin" ] && [ -z "$(ls -A "${HOME}/bin")" ] && rmdir "${HOME}/bin"
sed -i '/export PATH="\$HOME\/bin:\$PATH"/d' "${HOME}/.bashrc" >/dev/null 2>&1
source "${HOME}/.bashrc"
clear
green "Sing-box四合一已完全卸载"
;;
[Nn]) exit 0 ;;
*) red "无效的选择,请输入y或n" && menu ;;
esac
}
kill_all_tasks() {
reading "\n确定继续清理吗?【y/n】: " choice
case "$choice" in
[Yy]) 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 ;;
*) menu ;;
esac
}
# Generating argo Config
argo_configure() {
if [[ -z $ARGO_AUTH || -z $ARGO_DOMAIN ]]; then
reading "是否需要使用固定argo隧道?(直接回车将使用临时隧道)【y/n】: " argo_choice
[[ -z $argo_choice ]] && return
[[ "$argo_choice" != "y" && "$argo_choice" != "Y" && "$argo_choice" != "n" && "$argo_choice" != "N" ]] && { red "无效的选择,请输入y或n"; return; }
if [[ "$argo_choice" == "y" || "$argo_choice" == "Y" ]]; then
reading "请输入argo固定隧道域名: " ARGO_DOMAIN
green "你的argo固定隧道域名为: $ARGO_DOMAIN"
reading "请输入argo固定隧道密钥(Json或Token): " ARGO_AUTH
green "你的argo固定隧道密钥为: $ARGO_AUTH"
echo -e "${red}注意:${purple}使用token,需要在cloudflare后台设置隧道端口和面板开放的tcp端口一致${re}"
else
green "ARGO隧道变量未设置,将使用临时隧道"
return
fi
fi
if [[ $ARGO_AUTH =~ TunnelSecret ]]; then
echo $ARGO_AUTH > tunnel.json
cat > tunnel.yml << EOF
tunnel: $(cut -d\" -f12 <<< "$ARGO_AUTH")
credentials-file: tunnel.json
protocol: http2
ingress:
- hostname: $ARGO_DOMAIN
service: http://localhost:$VMESS_PORT
originRequest:
noTLSVerify: true
- service: http_status:404
EOF
else
green "ARGO_AUTH mismatch TunnelSecret,use token connect to tunnel"
fi
}
# Generating Configuration Files
generate_config() {
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": "vmess-ws-in",
"type": "vmess",
"listen": "::",
"listen_port": $VMESS_PORT,
"users": [
{
"uuid": "$UUID"
}
],
"transport": {
"type": "ws",
"path": "/vmess-argo",
"early_data_header_name": "Sec-WebSocket-Protocol"
}
},
{
"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": [
EOF
# 如果是s14,设置 WireGuard 出站
if [ "$HOSTNAME" == "s14.serv00.com" ]; then
cat >> config.json << EOF
{
"type": "wireguard",
"tag": "wireguard-out",
"server": "162.159.195.100",
"server_port": 4500,
"local_address": [
"172.16.0.2/32",
"2606:4700:110:83c7:b31f:5858:b3a8:c6b1/128"
],
"private_key": "mPZo+V9qlrMGCZ7+E6z2NI6NOV34PD++TpAR09PtCWI=",
"peer_public_key": "bmXOC+F1FxEMF9dyiK2H5/1SUtzH0JuVo51h2wPfgyo=",
"reserved": [
26,
21,
228
]
},
EOF
fi
cat >> config.json << EOF
{
"tag": "direct",
"type": "direct"
},
{
"tag": "block",
"type": "block"
}
],
"route": {
"rules": [
EOF
if [ "$HOSTNAME" == "s14.serv00.com" ]; then
cat >> config.json << EOF
{
"outbound": "wireguard-out",
"domain": ["geosite:all"]
},
{
"outbound": "direct",
"domain": ["geosite:cn"]
}
EOF
else
cat >> config.json << EOF
{
"outbound": "direct",
"domain": ["geosite:all"]
}
EOF
fi
cat >> config.json << EOF
]
}
}
EOF
}
# Download Dependency Files
download_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/arm64/bot13 bot" "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/server bot" "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
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
if [ -e "$(basename ${FILE_MAP[bot]})" ]; then
if [[ $ARGO_AUTH =~ ^[A-Z0-9a-z=]{120,250}$ ]]; then
args="tunnel --edge-ip-version auto --no-autoupdate --protocol http2 run --token ${ARGO_AUTH}"
elif [[ $ARGO_AUTH =~ TunnelSecret ]]; then
args="tunnel --edge-ip-version auto --config tunnel.yml run"
else
args="tunnel --edge-ip-version auto --no-autoupdate --protocol http2 --logfile boot.log --loglevel info --url http://localhost:$VMESS_PORT"
fi
nohup ./"$(basename ${FILE_MAP[bot]})" $args >/dev/null 2>&1 &
sleep 2
pgrep -x "$(basename ${FILE_MAP[bot]})" > /dev/null && green "$(basename ${FILE_MAP[bot]}) is running" || { red "$(basename ${FILE_MAP[bot]}) is not running, restarting..."; pkill -x "$(basename ${FILE_MAP[bot]})" && nohup ./"$(basename ${FILE_MAP[bot]})" "${args}" >/dev/null 2>&1 & sleep 2; purple "$(basename ${FILE_MAP[bot]}) restarted"; }
fi
sleep 2
rm -f "$(basename ${FILE_MAP[npm]})" "$(basename ${FILE_MAP[web]})" "$(basename ${FILE_MAP[bot]})"
}
get_argodomain() {
if [[ -n $ARGO_AUTH ]]; then
echo "$ARGO_DOMAIN"
else
local retry=0
local max_retries=6
local argodomain=""
while [[ $retry -lt $max_retries ]]; do
((retry++))
argodomain=$(grep -oE 'https://[[:alnum:]+\.-]+\.trycloudflare\.com' boot.log | sed 's@https://@@')
if [[ -n $argodomain ]]; then
break
fi
sleep 1
done
echo "$argodomain"
fi
}
get_ip() {
IP_LIST=($(devil vhost list | awk '/^[0-9]+/ {print $1}'))
API_URL="https://status.eooce.com/api"
IP=""
THIRD_IP=${IP_LIST[2]}
RESPONSE=$(curl -s --max-time 2 "${API_URL}/${THIRD_IP}")
if [[ $(echo "$RESPONSE" | jq -r '.status') == "Available" ]]; then
IP=$THIRD_IP
else
FIRST_IP=${IP_LIST[0]}
RESPONSE=$(curl -s --max-time 2 "${API_URL}/${FIRST_IP}")
if [[ $(echo "$RESPONSE" | jq -r '.status') == "Available" ]]; then
IP=$FIRST_IP
else
IP=${IP_LIST[1]}
fi
fi
echo "$IP"
}
generate_sub_link () {
cat > ${FILE_PATH}/.htaccess << EOF
RewriteEngine On
RewriteRule ^${SUB_TOKEN}$ sub.php [L]
EOF
base64 -w0 ${FILE_PATH}/list.txt > ${FILE_PATH}/v2.log
V2rayN_LINK="https://${USERNAME}.serv00.net/v2.log"
PHP_URL="https://00.2go.us.kg/sub.php"
curl -sS "https://sublink.eooce.com/clash?config=${V2rayN_LINK}" -o ${FILE_PATH}/clash.yaml
curl -sS "https://sublink.eooce.com/singbox?config=${V2rayN_LINK}" -o ${FILE_PATH}/singbox.yaml
command -v curl &> /dev/null && curl -s -o "${FILE_PATH}/sub.php" "$PHP_URL" || command -v wget &> /dev/null && wget -q -O "${FILE_PATH}/sub.php" "$PHP_URL" || red "Warning: Neither curl nor wget is installed. You can't use the subscription"
purple "\n自适应节点订阅链接: https://${USERNAME}.serv00.net/${SUB_TOKEN}\n"
green "节点订阅链接适用于 V2rayN/Nekoray/ShadowRocket/Clash/Mihomo/Sing-box/karing/Loon/sterisand 等\n"
}
get_links(){
argodomain=$(get_argodomain)
echo -e "\e[1;32mArgoDomain:\e[1;35m${argodomain}\e[0m\n"
ISP=$(curl -s --max-time 1.5 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 > ${FILE_PATH}/list.txt <<EOF
vmess://$(echo "{ \"v\": \"2\", \"ps\": \"$NAME-vmess\", \"add\": \"$available_ip\", \"port\": \"$VMESS_PORT\", \"id\": \"$UUID\", \"aid\": \"0\", \"scy\": \"none\", \"net\": \"ws\", \"type\": \"none\", \"host\": \"\", \"path\": \"/vmess-argo?ed=2048\", \"tls\": \"\", \"sni\": \"\", \"alpn\": \"\", \"fp\": \"\"}" | base64 -w0)
vmess://$(echo "{ \"v\": \"2\", \"ps\": \"$NAME-vmess-argo\", \"add\": \"$CFIP\", \"port\": \"$CFPORT\", \"id\": \"$UUID\", \"aid\": \"0\", \"scy\": \"none\", \"net\": \"ws\", \"type\": \"none\", \"host\": \"$argodomain\", \"path\": \"/vmess-argo?ed=2048\", \"tls\": \"tls\", \"sni\": \"$argodomain\", \"alpn\": \"\", \"fp\": \"\"}" | base64 -w0)
hysteria2://$UUID@$available_ip:$HY2_PORT/?sni=www.bing.com&alpn=h3&insecure=1#$NAME-hysteria2
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 ${FILE_PATH}/list.txt
generate_sub_link
rm -rf boot.log config.json sb.log core tunnel.yml tunnel.json fake_useragent_0.2.0.json
quick_command
green "Running done!\n"
}
install_keepalive () {
clear
reading "是否需要Telegram通知?(直接回车则不启用)【y/n】: " tg_notification
if [[ "$tg_notification" == "y" || "$tg_notification" == "Y" ]]; then
reading "请输入Telegram chat ID (tg上@userinfobot获取): " tg_chat_id
[[ -z $tg_chat_id ]] && { red "Telegram chat ID不能为空"; return; }
green "你设置的Telegram chat_id为: ${tg_chat_id}"
reading "请输入Telegram Bot Token (tg上@Botfather创建bot后获取): " tg_token
[[ -z $tg_token ]] && { red "Telegram Bot Token不能为空"; return; }
green "你设置的Telegram bot token为: ${tg_token}"
fi
reading "是否需要保活哪吒探针?(直接回车则不启用)【y/n】: " keep_nezha
if [[ "$keep_nezha" == "y" || "$keep_nezha" == "Y" ]]; then
reading "请输入哪吒面板域名:" nezha_server
green "你的哪吒面板域名为: $nezha_server"
reading "请输入哪吒agent端口(直接回车则默认使用5555): " nezha_port
[[ -z $nezha_port ]] && nezha_port=5555
green "你的哪吒agent端口为: $nezha_port"
reading "请输入哪吒agent密钥: " nezha_key
[[ -z $nezha_key ]] && { red "哪吒agent密钥不能为空"; return; }
green "你的哪吒agent密钥为: $nezha_key"
fi
reading "是否需要设置Argo固定隧道?(直接回车则使用临时隧道)【y/n】: " argo
if [[ "$argo" == "y" || "$argo" == "Y" ]]; then
reading "请输入Argo固定隧道域名: " argo_domain
[[ -z $argo_domain ]] && { red "Argo固定隧道域名不能为空"; return; }
green "你的Argo固定隧道域名为: $argo_domain"
reading "请输入Argo固定隧道密钥(json或token): " argo_key
[[ -z $argo_key ]] && { red "Argo固定隧道密钥不能为空"; return; }
green "你的Argo固定隧道密钥为: $argo_key"
fi
purple "正在安装保活服务中,请稍等......"
keep_path="$HOME/domains/keep.${USERNAME}.serv00.net/public_nodejs"
[ -d "$keep_path" ] || mkdir -p "$keep_path"
app_file_url="https://00.2go.us.kg/app.js"
if command -v curl &> /dev/null; then
curl -s -o "${keep_path}/app.js" "$app_file_url"
elif command -v wget &> /dev/null; then
wget -q -O "${keep_path}/app.js" "$app_file_url"
else
echo "警告: 文件下载失败,请手动从https://00.2go.us.kg/app.js下载文件,并将文件上传到${keep_path}目录下"
return
fi
cat > ${keep_path}/.env <<EOF
UUID=$UUID
CFIP=${CFIP}
CFPORT=${CFPORT}
SUB_TOKEN=${UUID:0:8}
${tg_chat_id:+TELEGRAM_CHAT_ID=$tg_chat_id}
${tg_token:+TELEGRAM_BOT_TOKEN=$tg_token}
${nezha_server:+NEZHA_SERVER=$nezha_server}
${nezha_port:+NEZHA_PORT=$nezha_port}
${nezha_key:+NEZHA_KEY=$nezha_key}
ARGO_DOMAIN=$argo_domain
ARGO_AUTH=$([[ -z "$argo_key" ]] && echo "" || ([[ "$argo_key" =~ ^\{.* ]] && echo "'$argo_key'" || echo "$argo_key"))
EOF
cat >> ${FILE_PATH}/.htaccess << EOF
RewriteEngine On
RewriteRule ^${SUB_TOKEN}$ sub.php [L]
EOF
devil www add ${USERNAME}.serv00.net php > /dev/null 2>&1
devil www add keep.${USERNAME}.serv00.net nodejs /usr/local/bin/node18 > /dev/null 2>&1
devil ssl www add $available_ip le le keep.${USERNAME}.serv00.net > /dev/null 2>&1
ln -fs /usr/local/bin/node18 ~/bin/node > /dev/null 2>&1
ln -fs /usr/local/bin/npm18 ~/bin/npm > /dev/null 2>&1
mkdir -p ~/.npm-global
npm config set prefix '~/.npm-global'
echo 'export PATH=~/.npm-global/bin:~/bin:$PATH' >> $HOME/.bash_profile && source $HOME/.bash_profile
rm -rf $HOME/.npmrc > /dev/null 2>&1
cd ${keep_path} && npm install dotenv axios --silent > /dev/null 2>&1
rm $HOME/domains/keep.${USERNAME}.serv00.net/public_nodejs/public/index.html > /dev/null 2>&1
devil www options keep.${USERNAME}.serv00.net sslonly on > /dev/null 2>&1
if devil www restart keep.${USERNAME}.serv00.net 2>&1 | grep -q "succesfully"; then
green "\n全自动保活服务安装成功\n"
purple "自适应节点订阅链接: https://${USERNAME}.serv00.net/${SUB_TOKEN}\n\n温馨提醒:如果未安装1,则需要等2分钟自动安装完成后再更新订阅\n\n"
green "========================================================\n"
purple "访问 https://keep.${USERNAME}.serv00.net/stop 结束进程\n"
purple "访问 https://keep.${USERNAME}.serv00.net/list 全部进程列表\n"
yellow "访问 https://keep.${USERNAME}.serv00.net/start 调起保活程序\n"
purple "访问 https://keep.${USERNAME}.serv00.net/status 查看进程状态\n"
green "========================================================"
yellow "如发现掉线访问https://keep.${USERNAME}.serv00.net/start唤醒,或者用https://console.cron-job.org在线访问网页自动唤醒\n"
purple "如果需要Telegram通知,请先在Telegram @Botfather 申请 Bot-Token,并带CHAT_ID和BOT_TOKEN环境变量运行\n\n"
quick_command
else
red "全自动保活服务安装失败,请删除所有站点后重试,卸载命令如下: \n${yellow}devil www del ${USERNAME}.serv00.net\ndevil www del ${USERNAME}.serv00.net\nrm -rf $HOME/${USERNAME}/domains/*\n${red}请依次执行上述三行命令后重新安装!"
fi
}
quick_command() {
COMMAND="00"
SCRIPT_PATH="$HOME/bin/$COMMAND"
mkdir -p "$HOME/bin"
echo "#!/bin/bash" > "$SCRIPT_PATH"
echo "bash <(curl -Ls https://raw.githubusercontent.com/eooce/sing-box/main/sb_serv00.sh)" >> "$SCRIPT_PATH"
chmod +x "$SCRIPT_PATH"
if [[ ":$PATH:" != *":$HOME/bin:"* ]]; then
echo "export PATH=\"\$HOME/bin:\$PATH\"" >> "$HOME/.bashrc"
source "$HOME/.bashrc"
fi
}
get_url_info() {
if devil www list 2>&1 | grep -q "keep.$USERNAME.serv00.net"; then
purple "\n-------------------保活相关链接------------------\n"
green "=================================================\n"
purple "https://keep.${USERNAME}.serv00.net/stop 结束进程\n"
purple "https://keep.${USERNAME}.serv00.net/list 全部进程列表\n"
yellow "https://keep.${USERNAME}.serv00.net/start 调起保活程序\n"
purple "https://keep.${USERNAME}.serv00.net/status 查看进程状态\n"
green "================================================="
else
red "尚未安装自动保活服务\n" && sleep 2 && menu
fi
}
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"
yellow "快速启动命令00\n"
green "1. 安装sing-box"
echo "==============="
green "2. 安装全自动保活"
echo "==============="
red "3. 卸载sing-box"
echo "==============="
green "4. 查看节点信息"
echo "==============="
green "5. 查看保活链接"
echo "==============="
yellow "6. 清理所有进程"
echo "==============="
yellow "7. 更换节点端口"
echo "==============="
red "0. 退出脚本"
echo "==========="
reading "请输入选择(0-7): " choice
echo ""
case "${choice}" in
1) install_singbox ;;
2) install_keepalive ;;
3) uninstall_singbox ;;
4) cat ${FILE_PATH}/list.txt && yellow "\n自适应节点订阅链接: https://${USERNAME}.serv00.net/${SUB_TOKEN}\n节点订阅链接适用于V2rayN/Nekoray/ShadowRocket/Clash/Sing-box/karing/Loon/sterisand 等\n";;
5) get_url_info ;;
6) kill_all_tasks ;;
7) changge_ports ;;
0) exit 0 ;;
*) red "无效的选项,请输入 0 到 7" ;;
esac
}
menu