forked from deathline94/sing-REALITY-Box
-
Notifications
You must be signed in to change notification settings - Fork 62
/
install.sh
1882 lines (1796 loc) · 64.7 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
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
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
red="\033[31m\033[01m"
green="\033[32m\033[01m"
yellow="\033[33m\033[01m"
reset="\033[0m"
bold="\e[1m"
warning() { echo -e "${red}$*${reset}"; }
error() { warning "$*" && exit 1; }
info() { echo -e "${green}$*${reset}"; }
hint() { echo -e "${yellow}$*${reset}"; }
show_notice() {
local message="$1"
local terminal_width=$(tput cols)
local line=$(printf "%*s" "$terminal_width" | tr ' ' '*')
local padding=$(( (terminal_width - ${#message}) / 2 ))
local padded_message="$(printf "%*s%s" $padding '' "$message")"
warning "${bold}${line}${reset}"
echo ""
warning "${bold}${padded_message}${reset}"
echo ""
warning "${bold}${line}${reset}"
}
print_with_delay() {
text="$1"
delay="$2"
for ((i = 0; i < ${#text}; i++)); do
printf "%s" "${text:$i:1}"
sleep "$delay"
done
echo
}
show_status(){
singbox_pid=$(pgrep sing-box)
singbox_status=$(systemctl is-active sing-box)
if [ "$singbox_status" == "active" ]; then
cpu_usage=$(ps -p $singbox_pid -o %cpu | tail -n 1)
memory_usage_mb=$(( $(ps -p "$singbox_pid" -o rss | tail -n 1) / 1024 ))
p_latest_version_tag=$(curl -s "https://api.github.com/repos/SagerNet/sing-box/releases" | jq -r '[.[] | select(.prerelease==true)][0].tag_name')
latest_version_tag=$(curl -s "https://api.github.com/repos/SagerNet/sing-box/releases" | jq -r '[.[] | select(.prerelease==false)][0].tag_name')
latest_version=${latest_version_tag#v} # Remove 'v' prefix from version number
p_latest_version=${p_latest_version_tag#v} # Remove 'v' prefix from version number
iswarp=$(grep '^WARP_ENABLE=' /root/sbox/config | cut -d'=' -f2)
hyhop=$(grep '^HY_HOPPING=' /root/sbox/config | cut -d'=' -f2)
warning "SING-BOX服务状态信息:"
hint "========================="
info "状态: 运行中"
info "CPU 占用: $cpu_usage%"
info "内存 占用: ${memory_usage_mb}MB"
info "singbox测试版最新版本: $p_latest_version"
info "singbox正式版最新版本: $latest_version"
info "singbox当前版本(输入4管理切换): $(/root/sbox/sing-box version 2>/dev/null | awk '/version/{print $NF}')"
info "warp流媒体解锁(输入6管理): $(if [ "$iswarp" == "TRUE" ]; then echo "开启"; else echo "关闭"; fi)"
info "hy2端口跳跃(输入7管理): $(if [ "$hyhop" == "TRUE" ]; then echo "开启"; else echo "关闭"; fi)"
hint "========================="
else
warning "SING-BOX 未运行!"
fi
}
install_pkgs() {
# Install qrencode, jq, and iptables if not already installed
local pkgs=("qrencode" "jq" "iptables")
for pkg in "${pkgs[@]}"; do
if command -v "$pkg" &> /dev/null; then
hint "$pkg 已经安装"
else
hint "开始安装 $pkg..."
if command -v apt &> /dev/null; then
sudo apt update > /dev/null 2>&1 && sudo apt install -y "$pkg" > /dev/null 2>&1
elif command -v yum &> /dev/null; then
sudo yum install -y "$pkg"
elif command -v dnf &> /dev/null; then
sudo dnf install -y "$pkg"
else
error "Unable to install $pkg. Please install it manually and rerun the script."
fi
hint "$pkg 安装成功"
fi
done
}
install_shortcut() {
cat > /root/sbox/mianyang.sh << EOF
#!/usr/bin/env bash
bash <(curl -fsSL https://github.com/vveg26/sing-box-reality-hysteria2/raw/main/install.sh) \$1
EOF
chmod +x /root/sbox/mianyang.sh
ln -sf /root/sbox/mianyang.sh /usr/bin/mianyang
}
reload_singbox() {
if /root/sbox/sing-box check -c /root/sbox/sbconfig_server.json; then
echo "检查配置文件成功,开始重启服务..."
if systemctl reload sing-box; then
echo "服务重启成功."
else
error "服务重启失败,请检查错误日志"
fi
else
error "配置文件检查错误,请检查配置文件"
fi
}
install_singbox(){
echo "请选择需要安装的SING-BOX版本:"
echo "1. 正式版"
echo "2. 测试版"
read -p "输入你的选项 (1-2, 默认: 1): " version_choice
version_choice=${version_choice:-1}
# Set the tag based on user choice
if [ "$version_choice" -eq 2 ]; then
echo "Installing Alpha version..."
latest_version_tag=$(curl -s "https://api.github.com/repos/SagerNet/sing-box/releases" | jq -r '[.[] | select(.prerelease==true)][0].tag_name')
else
echo "Installing Stable version..."
latest_version_tag=$(curl -s "https://api.github.com/repos/SagerNet/sing-box/releases" | jq -r '[.[] | select(.prerelease==false)][0].tag_name')
fi
# No need to fetch the latest version tag again, it's already set based on user choice
latest_version=${latest_version_tag#v} # Remove 'v' prefix from version number
echo "Latest version: $latest_version"
# Detect server architecture
arch=$(uname -m)
echo "本机架构为: $arch"
case ${arch} in
x86_64) arch="amd64" ;;
aarch64) arch="arm64" ;;
armv7l) arch="armv7" ;;
esac
# latest_version_tag=$(curl -s "https://api.github.com/repos/SagerNet/sing-box/releases" | grep -Po '"tag_name": "\K.*?(?=")' | sort -V | tail -n 1)
# latest_version=${latest_version_tag#v}
echo "最新版本为: $latest_version"
package_name="sing-box-${latest_version}-linux-${arch}"
url="https://github.com/SagerNet/sing-box/releases/download/${latest_version_tag}/${package_name}.tar.gz"
curl -sLo "/root/${package_name}.tar.gz" "$url"
tar -xzf "/root/${package_name}.tar.gz" -C /root
mv "/root/${package_name}/sing-box" /root/sbox
rm -r "/root/${package_name}.tar.gz" "/root/${package_name}"
chown root:root /root/sbox/sing-box
chmod +x /root/sbox/sing-box
}
change_singbox(){
echo "切换SING-BOX版本..."
echo ""
# Extract the current version
current_version_tag=$(/root/sbox/sing-box version | grep 'sing-box version' | awk '{print $3}')
# Fetch the latest stable and alpha version tags
latest_stable_version=$(curl -s "https://api.github.com/repos/SagerNet/sing-box/releases" | jq -r '[.[] | select(.prerelease==false)][0].tag_name')
latest_alpha_version=$(curl -s "https://api.github.com/repos/SagerNet/sing-box/releases" | jq -r '[.[] | select(.prerelease==true)][0].tag_name')
# Determine current version type (stable or alpha)
if [[ $current_version_tag == *"-alpha"* || $current_version_tag == *"-rc"* || $current_version_tag == *"-beta"* ]]; then
echo "当前为测试版,准备切换为最新正式版..."
echo ""
new_version_tag=$latest_stable_version
else
echo "当前为正式版,准备切换为最新测试版..."
echo ""
new_version_tag=$latest_alpha_version
fi
# Stop the service before updating
systemctl stop sing-box
# Download and replace the binary
arch=$(uname -m)
case $arch in
x86_64) arch="amd64" ;;
aarch64) arch="arm64" ;;
armv7l) arch="armv7" ;;
esac
package_name="sing-box-${new_version_tag#v}-linux-${arch}"
url="https://github.com/SagerNet/sing-box/releases/download/${new_version_tag}/${package_name}.tar.gz"
curl -sLo "/root/${package_name}.tar.gz" "$url"
tar -xzf "/root/${package_name}.tar.gz" -C /root
mv "/root/${package_name}/sing-box" /root/sbox/sing-box
# Cleanup the package
rm -r "/root/${package_name}.tar.gz" "/root/${package_name}"
# Set the permissions
chown root:root /root/sbox/sing-box
chmod +x /root/sbox/sing-box
# Restart the service with the new binary
systemctl daemon-reload
systemctl start sing-box
echo "Version switched and service restarted with the new binary."
echo ""
}
generate_port() {
local protocol="$1"
while :; do
port=$((RANDOM % 10001 + 10000))
read -p "请为 ${protocol} 输入监听端口(默认为随机生成): " user_input
port=${user_input:-$port}
ss -tuln | grep -q ":$port\b" || { echo "$port"; return $port; }
echo "端口 $port 被占用,请输入其他端口"
done
}
modify_port() {
local current_port="$1"
local protocol="$2"
while :; do
read -p "请输入需要修改的 ${protocol} 端口,回车不修改 (当前 ${protocol} 端口为: $current_port): " modified_port
modified_port=${modified_port:-$current_port}
if [ "$modified_port" -eq "$current_port" ] || ! ss -tuln | grep -q ":$modified_port\b"; then
break
else
echo "端口 $modified_port 被占用,请输入其他端口"
fi
done
echo "$modified_port"
}
# client configuration
show_client_configuration() {
server_ip=$(grep -o "SERVER_IP='[^']*'" /root/sbox/config | awk -F"'" '{print $2}')
public_key=$(grep -o "PUBLIC_KEY='[^']*'" /root/sbox/config | awk -F"'" '{print $2}')
reality_port=$(jq -r '.inbounds[] | select(.tag == "vless-in") | .listen_port' /root/sbox/sbconfig_server.json)
reality_uuid=$(jq -r '.inbounds[] | select(.tag == "vless-in") | .users[0].uuid' /root/sbox/sbconfig_server.json)
reality_server_name=$(jq -r '.inbounds[] | select(.tag == "vless-in") | .tls.server_name' /root/sbox/sbconfig_server.json)
short_id=$(jq -r '.inbounds[] | select(.tag == "vless-in") | .tls.reality.short_id[0]' /root/sbox/sbconfig_server.json)
reality_link="vless://$reality_uuid@$server_ip:$reality_port?encryption=none&flow=xtls-rprx-vision&security=reality&sni=$reality_server_name&fp=chrome&pbk=$public_key&sid=$short_id&type=tcp&headerType=none#SING-BOX-REALITY"
echo ""
show_notice "VISION_REALITY 通用链接 二维码 通用参数"
echo ""
info "通用链接如下"
echo ""
echo "$reality_link"
echo ""
info "二维码如下"
echo ""
qrencode -t UTF8 $reality_link
echo ""
info "客户端通用参数如下"
echo "------------------------------------"
echo "服务器ip: $server_ip"
echo "监听端口: $reality_port"
echo "UUID: $reality_uuid"
echo "域名SNI: $reality_server_name"
echo "Public Key: $public_key"
echo "Short ID: $short_id"
echo "------------------------------------"
# hy2
hy_port=$(jq -r '.inbounds[] | select(.tag == "hy2-in") | .listen_port' /root/sbox/sbconfig_server.json)
hy_server_name=$(grep -o "HY_SERVER_NAME='[^']*'" /root/sbox/config | awk -F"'" '{print $2}')
hy_password=$(jq -r '.inbounds[] | select(.tag == "hy2-in") | .users[0].password' /root/sbox/sbconfig_server.json)
ishopping=$(grep '^HY_HOPPING=' /root/sbox/config | cut -d'=' -f2)
if [ "$ishopping" = "FALSE" ]; then
hy2_link="hysteria2://$hy_password@$server_ip:$hy_port?insecure=1&sni=$hy_server_name#SING-BOX-HYSTERIA2"
else
hopping_range=$(iptables -t nat -L -n -v | grep "udp" | grep -oP 'dpts:\K\d+:\d+' || ip6tables -t nat -L -n -v | grep "udp" | grep -oP 'dpts:\K\d+:\d+')
if [ -z "$hopping_range" ]; then
warning "端口跳跃已开启却未找到端口范围。"
hy2_link="hysteria2://$hy_password@$server_ip:$hy_port?insecure=1&sni=$hy_server_name#SING-BOX-HYSTERIA2"
else
formatted_range=$(echo "$hopping_range" | sed 's/:/-/')
hy2_link="hysteria2://$hy_password@$server_ip:$hy_port?insecure=1&sni=$hy_server_name&mport=${hy_port},${formatted_range}#SING-BOX-HYSTERIA2"
fi
fi
echo ""
echo ""
show_notice "Hysteria2通用链接 二维码 通用参数"
echo ""
info "通用链接如下"
echo ""
echo "$hy2_link"
echo ""
info "二维码如下"
echo ""
qrencode -t UTF8 $hy2_link
echo ""
info "客户端通用参数如下"
echo "------------------------------------"
echo "服务器ip: $server_ip"
echo "端口号: $hy_port"
if [ "$ishopping" = "FALSE" ]; then
echo "端口跳跃未开启"
else
echo "跳跃端口为${formatted_range}"
fi
echo "密码password: $hy_password"
echo "域名SNI: $hy_server_name"
echo "跳过证书验证(允许不安全): True"
echo "------------------------------------"
show_notice "clash-meta配置参数"
cat << EOF
port: 7890
allow-lan: true
mode: rule
log-level: info
unified-delay: true
global-client-fingerprint: chrome
ipv6: true
dns:
enable: true
listen: :53
ipv6: true
enhanced-mode: fake-ip
fake-ip-range: 198.18.0.1/16
default-nameserver:
- 223.5.5.5
- 8.8.8.8
nameserver:
- https://dns.alidns.com/dns-query
- https://doh.pub/dns-query
fallback:
- https://1.0.0.1/dns-query
- tls://dns.google
fallback-filter:
geoip: true
geoip-code: CN
ipcidr:
- 240.0.0.0/4
proxies:
- name: Reality
type: vless
server: $server_ip
port: $reality_port
uuid: $reality_uuid
network: tcp
udp: true
tls: true
flow: xtls-rprx-vision
servername: $reality_server_name
client-fingerprint: chrome
reality-opts:
public-key: $public_key
short-id: $short_id
- name: Hysteria2
type: hysteria2
server: $server_ip
port: $hy_port
# up和down均不写或为0则使用BBR流控
# up: "30 Mbps" # 若不写单位,默认为 Mbps
# down: "200 Mbps" # 若不写单位,默认为 Mbps
password: $hy_password
sni: $hy_server_name
skip-cert-verify: true
alpn:
- h3
proxy-groups:
- name: 节点选择
type: select
proxies:
- 自动选择
- Reality
- Hysteria2
- DIRECT
- name: 自动选择
type: url-test #选出延迟最低的机场节点
proxies:
- Reality
- Hysteria2
url: "http://www.gstatic.com/generate_204"
interval: 300
tolerance: 50
rules:
- GEOIP,LAN,DIRECT
- GEOIP,CN,DIRECT
- MATCH,节点选择
EOF
echo ""
echo ""
show_notice "sing-box客户端配置1.8.0及以上"
cat << EOF
{
"log": {
"level": "debug",
"timestamp": true
},
"experimental": {
"clash_api": {
"external_controller": "127.0.0.1:9090",
"external_ui_download_url": "",
"external_ui_download_detour": "",
"external_ui": "ui",
"secret": "",
"default_mode": "rule"
},
"cache_file": {
"enabled": true,
"store_fakeip": false
}
},
"dns": {
"servers": [
{
"tag": "proxyDns",
"address": "https://8.8.8.8/dns-query",
"detour": "proxy"
},
{
"tag": "localDns",
"address": "https://223.5.5.5/dns-query",
"detour": "direct"
},
{
"tag": "block",
"address": "rcode://success"
},
{
"tag": "remote",
"address": "fakeip"
}
],
"rules": [
{
"domain": [
"ghproxy.com",
"cdn.jsdelivr.net",
"testingcf.jsdelivr.net"
],
"server": "localDns"
},
{
"rule_set": "geosite-category-ads-all",
"server": "block"
},
{
"outbound": "any",
"server": "localDns",
"disable_cache": true
},
{
"rule_set": "geosite-cn",
"server": "localDns"
},
{
"clash_mode": "direct",
"server": "localDns"
},
{
"clash_mode": "global",
"server": "proxyDns"
},
{
"rule_set": "geosite-geolocation-!cn",
"server": "proxyDns"
},
{
"query_type": [
"A",
"AAAA"
],
"server": "remote"
}
],
"fakeip": {
"enabled": true,
"inet4_range": "198.18.0.0/15",
"inet6_range": "fc00::/18"
},
"independent_cache": true,
"strategy": "ipv4_only"
},
"inbounds": [
{
"type": "tun",
"inet4_address": "172.19.0.1/30",
"mtu": 9000,
"auto_route": true,
"strict_route": true,
"sniff": true,
"endpoint_independent_nat": false,
"stack": "system",
"platform": {
"http_proxy": {
"enabled": true,
"server": "127.0.0.1",
"server_port": 2080
}
}
},
{
"type": "mixed",
"listen": "127.0.0.1",
"listen_port": 2080,
"sniff": true,
"users": []
}
],
"outbounds": [
{
"tag": "proxy",
"type": "selector",
"outbounds": [
"auto",
"direct",
"sing-box-reality",
"sing-box-hysteria2"
]
},
{
"type": "vless",
"tag": "sing-box-reality",
"uuid": "$reality_uuid",
"flow": "xtls-rprx-vision",
"packet_encoding": "xudp",
"server": "$server_ip",
"server_port": $reality_port,
"tls": {
"enabled": true,
"server_name": "$reality_server_name",
"utls": {
"enabled": true,
"fingerprint": "chrome"
},
"reality": {
"enabled": true,
"public_key": "$public_key",
"short_id": "$short_id"
}
}
},
{
"type": "hysteria2",
"server": "$server_ip",
"server_port": $hy_port,
"tag": "sing-box-hysteria2",
"up_mbps": 100,
"down_mbps": 100,
"password": "$hy_password",
"tls": {
"enabled": true,
"server_name": "$hy_server_name",
"insecure": true,
"alpn": [
"h3"
]
}
},
{
"tag": "direct",
"type": "direct"
},
{
"tag": "block",
"type": "block"
},
{
"tag": "dns-out",
"type": "dns"
},
{
"tag": "auto",
"type": "urltest",
"outbounds": [
"sing-box-reality",
"sing-box-hysteria2"
],
"url": "http://www.gstatic.com/generate_204",
"interval": "1m",
"tolerance": 50
},
{
"tag": "WeChat",
"type": "selector",
"outbounds": [
"direct",
"sing-box-reality",
"sing-box-hysteria2"
]
},
{
"tag": "Apple",
"type": "selector",
"outbounds": [
"direct",
"sing-box-reality",
"sing-box-hysteria2"
]
},
{
"tag": "Microsoft",
"type": "selector",
"outbounds": [
"direct",
"sing-box-reality",
"sing-box-hysteria2"
]
}
],
"route": {
"auto_detect_interface": true,
"final": "proxy",
"rules": [
{
"protocol": "dns",
"outbound": "dns-out"
},
{
"network": "udp",
"port": 443,
"outbound": "block"
},
{
"rule_set": "geosite-category-ads-all",
"outbound": "block"
},
{
"clash_mode": "direct",
"outbound": "direct"
},
{
"clash_mode": "global",
"outbound": "proxy"
},
{
"domain": [
"clash.razord.top",
"yacd.metacubex.one",
"yacd.haishan.me",
"d.metacubex.one"
],
"outbound": "direct"
},
{
"rule_set": "geosite-wechat",
"outbound": "WeChat"
},
{
"rule_set": "geosite-geolocation-!cn",
"outbound": "proxy"
},
{
"ip_is_private": true,
"outbound": "direct"
},
{
"rule_set": "geoip-cn",
"outbound": "direct"
},
{
"rule_set": "geosite-cn",
"outbound": "direct"
},
{
"rule_set": "geosite-apple",
"outbound": "Apple"
},
{
"rule_set": "geosite-microsoft",
"outbound": "Microsoft"
}
],
"rule_set": [
{
"tag": "geoip-cn",
"type": "remote",
"format": "binary",
"url": "https://testingcf.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@sing/geo/geoip/cn.srs",
"download_detour": "direct"
},
{
"tag": "geosite-cn",
"type": "remote",
"format": "binary",
"url": "https://testingcf.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@sing/geo/geosite/cn.srs",
"download_detour": "direct"
},
{
"tag": "geosite-geolocation-!cn",
"type": "remote",
"format": "binary",
"url": "https://testingcf.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@sing/geo/geosite/geolocation-!cn.srs",
"download_detour": "direct"
},
{
"tag": "geosite-category-ads-all",
"type": "remote",
"format": "binary",
"url": "https://testingcf.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@sing/geo/geosite/category-ads-all.srs",
"download_detour": "direct"
},
{
"tag": "geosite-wechat",
"type": "remote",
"format": "source",
"url": "https://testingcf.jsdelivr.net/gh/Toperlock/sing-box-geosite@main/wechat.json",
"download_detour": "direct"
},
{
"tag": "geosite-apple",
"type": "remote",
"format": "binary",
"url": "https://testingcf.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@sing/geo/geosite/apple.srs",
"download_detour": "direct"
},
{
"tag": "geosite-microsoft",
"type": "remote",
"format": "binary",
"url": "https://testingcf.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@sing/geo/geosite/microsoft.srs",
"download_detour": "direct"
}
]
}
}
EOF
}
enable_bbr() {
bash <(curl -L -s https://raw.githubusercontent.com/teddysun/across/master/bbr.sh)
echo ""
}
modify_singbox() {
echo ""
warning "开始修改VISION_REALITY 端口号和域名"
echo ""
reality_current_port=$(jq -r '.inbounds[] | select(.tag == "vless-in") | .listen_port' /root/sbox/sbconfig_server.json)
reality_port=$(modify_port "$reality_current_port" "VISION_REALITY")
info "生成的端口号为: $reality_port"
reality_current_server_name=$(jq -r '.inbounds[] | select(.tag == "vless-in") | .tls.server_name' /root/sbox/sbconfig_server.json)
reality_server_name="$reality_current_server_name"
while :; do
read -p "请输入需要偷取证书的网站,必须支持 TLS 1.3 and HTTP/2 (默认: $reality_server_name): " input_server_name
reality_server_name=${input_server_name:-$reality_server_name}
if curl --tlsv1.3 --http2 -sI "https://$reality_server_name" | grep -q "HTTP/2"; then
break
else
warning "域名 $reality_server_name 不支持 TLS 1.3 或 HTTP/2,请重新输入."
fi
done
info "域名 $reality_server_name 符合标准"
echo ""
warning "开始修改hysteria2端口号"
echo ""
hy_current_port=$(jq -r '.inbounds[] | select(.tag == "hy2-in") | .listen_port' /root/sbox/sbconfig_server.json)
hy_port=$(modify_port "$hy_current_port" "HYSTERIA2")
info "生成的端口号为: $hy_port"
info "修改hysteria2应用证书路径"
hy_current_cert=$(jq -r '.inbounds[] | select(.tag == "hy2-in") | .tls.certificate_path' /root/sbox/sbconfig_server.json)
hy_current_key=$(jq -r '.inbounds[] | select(.tag == "hy2-in") | .tls.key_path' /root/sbox/sbconfig_server.json)
hy_current_domain=$(grep -o "HY_SERVER_NAME='[^']*'" /root/sbox/config | awk -F"'" '{print $2}')
read -p "请输入证书域名 (默认: $hy_current_domain): " hy_domain
hy_domain=${hy_domain:-$hy_current_domain}
read -p "请输入证书cert路径 (默认: $hy_current_cert): " hy_cert
hy_cert=${hy_cert:-$hy_current_cert}
read -p "请输入证书key路径 (默认: $hy_current_key): " hy_key
hy_key=${hy_key:-$hy_current_key}
jq --arg reality_port "$reality_port" \
--arg hy_port "$hy_port" \
--arg reality_server_name "$reality_server_name" \
--arg hy_cert "$hy_cert" \
--arg hy_key "$hy_key" \
'
(.inbounds[] | select(.tag == "vless-in") | .listen_port) |= ($reality_port | tonumber) |
(.inbounds[] | select(.tag == "hy2-in") | .listen_port) |= ($hy_port | tonumber) |
(.inbounds[] | select(.tag == "vless-in") | .tls.server_name) |= $reality_server_name |
(.inbounds[] | select(.tag == "vless-in") | .tls.reality.handshake.server) |= $reality_server_name |
(.inbounds[] | select(.tag == "hy2-in") | .tls.certificate_path) |= $hy_cert |
(.inbounds[] | select(.tag == "hy2-in") | .tls.key_path) |= $hy_key
' /root/sbox/sbconfig_server.json > /root/sbox/sbconfig_server.temp && mv /root/sbox/sbconfig_server.temp /root/sbox/sbconfig_server.json
sed -i "s/HY_SERVER_NAME='.*'/HY_SERVER_NAME='$hy_domain'/" /root/sbox/config
reload_singbox
}
uninstall_singbox() {
warning "开始卸载..."
disable_hy2hopping
systemctl disable --now sing-box > /dev/null 2>&1
rm -f /etc/systemd/system/sing-box.service
rm -f /root/sbox/sbconfig_server.json /root/sbox/sing-box /root/sbox/mianyang.sh
rm -f /usr/bin/mianyang /root/sbox/self-cert/private.key /root/sbox/self-cert/cert.pem /root/sbox/config
rm -rf /root/sbox/self-cert/ /root/sbox/
warning "卸载完成"
}
process_warp(){
while :; do
iswarp=$(grep '^WARP_ENABLE=' /root/sbox/config | cut -d'=' -f2)
if [ "$iswarp" = "FALSE" ]; then
warning "分流解锁功能未开启,是否开启(一路回车默认为: warp v6解锁openai和奈飞)"
read -p "是否开启? (y/n 默认为y): " confirm
confirm=${confirm:-"y"}
if [ "$confirm" = "y" ] || [ "$confirm" = "Y" ]; then
enable_warp
else
break
fi
else
warp_option=$(awk -F= '/^WARP_OPTION/{gsub(/^[ \t]+|[ \t]+$/, "", $2); print $2}' /root/sbox/config)
case $warp_option in
0)
current_option="手动分流(使用geosite和domain分流)"
;;
1)
current_option="全局分流(接管所有流量)"
;;
*)
current_option="unknow!"
;;
esac
warp_mode=$(awk -F= '/^WARP_MODE/{gsub(/^[ \t]+|[ \t]+$/, "", $2); print $2}' /root/sbox/config)
case $warp_mode in
0)
current_mode="Ipv6优先"
current_mode1="warp-IPv6-prefer-out"
;;
1)
current_mode="Ipv4优先"
current_mode1="warp-IPv4-prefer-out"
;;
2)
current_mode="Ipv6仅允许"
current_mode1="warp-IPv6-out"
;;
3)
current_mode="Ipv4仅允许"
current_mode1="warp-IPv4-out"
;;
4)
current_mode="任意门解锁"
current_mode1="doko"
;;
5)
current_mode="ss解锁"
current_mode1="ss-out"
;;
*)
current_option="unknow!"
;;
esac
echo ""
warning "warp分流已经开启"
echo ""
hint "当前模式为: $current_mode"
hint "当前状态为: $current_option"
echo ""
info "请选择选项:"
echo ""
info "1. 切换为手动分流(geosite和domain分流)"
info "2. 切换为全局分流(接管所有流量)"
info "3. 设置手动分流规则(geosite和domain分流)"
info "4. 切换为分流策略"
info "5. 删除解锁"
info "0. 退出"
echo ""
read -p "请输入对应数字(0-5): " warp_input
case $warp_input in
1)
jq '.route.final = "direct"' /root/sbox/sbconfig_server.json > /root/sbox/sbconfig_server.temp && mv /root/sbox/sbconfig_server.temp /root/sbox/sbconfig_server.json
sed -i "s/WARP_OPTION=.*/WARP_OPTION=0/" /root/sbox/config
reload_singbox
;;
2)
if [ "$current_mode1" != "doko" ]; then
jq --arg current_mode1 "$current_mode1" '.route.final = $current_mode1' /root/sbox/sbconfig_server.json > /root/sbox/sbconfig_server.temp && mv /root/sbox/sbconfig_server.temp /root/sbox/sbconfig_server.json
sed -i "s/WARP_OPTION=.*/WARP_OPTION=1/" /root/sbox/config
reload_singbox
else
warning "任意门解锁无法使用全局接管,请使用ss解锁策略"
fi
;;
4)
while :; do
warning "请选择需要切换的分流策略"
echo ""
hint "当前状态为: $current_option"
echo ""
info "请选择切换的选项:"
echo ""
info "1. Ipv6优先(默认)"
info "2. Ipv4优先"
info "3. 仅允许Ipv6"
info "4. 仅允许Ipv4"
info "5. 任意门链式解锁"
info "6. ss链式解锁"
info "0. 退出"
echo ""
read -p "请输入对应数字(0-5): " user_input
user_input=${user_input:-1}
case $user_input in
1)
warp_out="warp-IPv6-prefer-out"
sed -i "s/WARP_MODE=.*/WARP_MODE=0/" /root/sbox/config
break
;;
2)
warp_out="warp-IPv4-prefer-out"
sed -i "s/WARP_MODE=.*/WARP_MODE=1/" /root/sbox/config
break
;;
3)
warp_out="warp-IPv6-out"
sed -i "s/WARP_MODE=.*/WARP_MODE=2/" /root/sbox/config
break
;;
4)
warp_out="warp-IPv4-out"
sed -i "s/WARP_MODE=.*/WARP_MODE=3/" /root/sbox/config
break
;;
5)
read -p "请输入落地机vps ip: " ipaddress
read -p "请输入落地机vps 端口: " tport
jq --arg new_address "$ipaddress" --argjson new_port "$tport" '.outbounds |= map(if .tag == "doko" then .override_address = $new_address | .override_port = ($new_port | tonumber) else . end)' /root/sbox/sbconfig_server.json > /root/sbox/sbconfig_server.temp && mv /root/sbox/sbconfig_server.temp /root/sbox/sbconfig_server.json
warp_out="doko"
sed -i "s/WARP_MODE=.*/WARP_MODE=4/" /root/sbox/config
break
;;
6)
read -p "请输入落地机vps ip: " ssipaddress
read -p "请输入落地机vps 端口: " sstport
read -p "请输入落地机vps ss密码: " sspwd
jq --arg new_address "$ssipaddress" --arg sspwd "$sspwd" --argjson new_port "$sstport" '.outbounds |= map(if .tag == "ss-out" then .server = $new_address | .password = $sspwd | .server_port = ($new_port | tonumber) else . end)' /root/sbox/sbconfig_server.json > /root/sbox/sbconfig_server.temp && mv /root/sbox/sbconfig_server.temp /root/sbox/sbconfig_server.json
warp_out="ss-out"
sed -i "s/WARP_MODE=.*/WARP_MODE=5/" /root/sbox/config
break
;;
0)
# Exit the loop if option 0 is selected
echo "退出warp"
exit 0
;;
*)
# Handle invalid input
echo "无效的输入,请重新输入"
;;
esac
done
jq --arg warp_out "$warp_out" '.route.rules[].outbound |= $warp_out' /root/sbox/sbconfig_server.json > /root/sbox/sbconfig_server.temp && mv /root/sbox/sbconfig_server.temp /root/sbox/sbconfig_server.json
if [ "$warp_option" -ne 0 ]; then
jq --arg warp_out "$warp_out" '.route.final = $warp_out' /root/sbox/sbconfig_server.json > /root/sbox/sbconfig_server.temp && mv /root/sbox/sbconfig_server.temp /root/sbox/sbconfig_server.json
fi
reload_singbox
;;
3)
info "请选择:"
echo ""
info "1. 手动添加geosite分流(适配singbox1.8.0)"
info "2. 手动添加域名关键字匹配分流"
info "0. 退出"
echo ""
read -p "请输入对应数字(0-2): " user_input
case $user_input in
1)
while :; do
echo ""
warning "geosite分流为: "
#域名关键字为
jq '.route.rules[] | select(.rule_set) | .rule_set' /root/sbox/sbconfig_server.json
info "请选择操作:"
echo "1. 添加geosite"
echo "2. 删除geosite"
echo "0. 退出"
echo ""
read -p "请输入对应数字(0-2): " user_input
case $user_input in
1)
#add domain
read -p "请输入要添加的域名关键字(若要添加geosite-openai,输入openai): " new_keyword
url="https://testingcf.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@sing/geo/geosite/$new_keyword.srs"
formatted_keyword="geosite-$new_keyword"
# 检查是否存在相同的 geosite 关键字
if jq --arg formatted_keyword "$formatted_keyword" '.route.rules[0].rule_set | any(. == $formatted_keyword)' /root/sbox/sbconfig_server.json | grep -q "true"; then
echo "geosite已存在,不添加重复项: $formatted_keyword"
else
http_status=$(curl -s -o /dev/null -w "%{http_code}" "$url")
if [ "$http_status" -eq 200 ]; then