forked from deathline94/sing-REALITY-Box
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
919 lines (847 loc) · 27.4 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
#!/bin/bash
# 延迟打字
print_with_delay() {
text="$1"
delay="$2"
for ((i = 0; i < ${#text}; i++)); do
echo -n "${text:$i:1}"
sleep $delay
done
echo
}
# 自定义字体彩色,read 函数
red() { echo -e "\033[31m\033[01m$*\033[0m"; } # 红色
green() { echo -e "\033[32m\033[01m$*\033[0m"; } # 绿色
yellow() { echo -e "\033[33m\033[01m$*\033[0m"; } # 黄色
#信息提示
show_notice() {
local message="$1"
local green_bg="\e[48;5;34m"
local white_fg="\e[97m"
local reset="\e[0m"
echo -e "${green_bg}${white_fg}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${reset}"
echo -e "${white_fg}┃${reset} "
echo -e "${white_fg}┃${reset} ${message} "
echo -e "${white_fg}┃${reset} "
echo -e "${green_bg}${white_fg}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${reset}"
}
# 作者介绍
print_with_delay "Reality Hysteria2 二合一脚本 by 绵阿羊" 0.03
echo ""
echo ""
# 安装依赖
install_base(){
# 安装qrencode
local packages=("qrencode")
for package in "${packages[@]}"; do
if ! command -v "$package" &> /dev/null; then
echo "正在安装 $package..."
if [ -n "$(command -v apt)" ]; then
sudo apt update > /dev/null 2>&1
sudo apt install -y "$package" > /dev/null 2>&1
elif [ -n "$(command -v yum)" ]; then
sudo yum install -y "$package"
elif [ -n "$(command -v dnf)" ]; then
sudo dnf install -y "$package"
else
echo "无法安装 $package。请手动安装,并重新运行脚本。"
exit 1
fi
echo "$package 已安装。"
else
echo "$package 已经安装。"
fi
done
}
# 创建快捷方式
create_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
}
# 下载cloudflared和sb
download_singbox(){
arch=$(uname -m)
echo "Architecture: $arch"
# Map architecture names
case ${arch} in
x86_64)
arch="amd64"
;;
aarch64)
arch="arm64"
;;
armv7l)
arch="armv7"
;;
esac
# Fetch the latest (including pre-releases) release version number from GitHub API
# 正式版
#latest_version_tag=$(curl -s "https://api.github.com/repos/SagerNet/sing-box/releases" | grep -Po '"tag_name": "\K.*?(?=")' | head -n 1)
#beta版本
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} # Remove 'v' prefix from version number
echo "Latest version: $latest_version"
# Detect server architecture
# Prepare package names
package_name="sing-box-${latest_version}-linux-${arch}"
# Prepare download URL
url="https://github.com/SagerNet/sing-box/releases/download/${latest_version_tag}/${package_name}.tar.gz"
# Download the latest release package (.tar.gz) from GitHub
curl -sLo "/root/${package_name}.tar.gz" "$url"
# Extract the package and move the binary to /root
tar -xzf "/root/${package_name}.tar.gz" -C /root
mv "/root/${package_name}/sing-box" /root/sbox
# 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
}
# client configuration
show_client_configuration() {
# 获取当前ip
server_ip=$(grep -o "SERVER_IP='[^']*'" /root/sbox/config | awk -F"'" '{print $2}')
# reality
# reality当前端口
reality_port=$(grep -o "REALITY_PORT='[^']*'" /root/sbox/config | awk -F"'" '{print $2}')
# 当前偷取的网站
reality_server_name=$(grep -o "REALITY_SERVER_NAME='[^']*'" /root/sbox/config | awk -F"'" '{print $2}')
# 当前reality uuid
reality_uuid=$(grep -o "REALITY_UUID='[^']*'" /root/sbox/config | awk -F"'" '{print $2}')
# 获取公钥
public_key=$(grep -o "PUBLIC_KEY='[^']*'" /root/sbox/config | awk -F"'" '{print $2}')
# 获取short_id
short_id=$(grep -o "SHORT_ID='[^']*'" /root/sbox/config | awk -F"'" '{print $2}')
#聚合reality
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 ""
echo ""
show_notice "$(red "Reality 通用链接和二维码和通用参数")"
echo ""
echo ""
red "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━Reality 通用链接如下━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
echo "$reality_link"
echo ""
red "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
echo ""
red "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━Reality 二维码如下━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
qrencode -t UTF8 $reality_link
echo ""
red "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
echo ""
red "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━Reality 客户端通用参数-━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
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 ""
red "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
echo ""
# hy port
hy_port=$(grep -o "HY_PORT='[^']*'" /root/sbox/config | awk -F"'" '{print $2}')
# hy sni
hy_server_name=$(grep -o "HY_SERVER_NAME='[^']*'" /root/sbox/config | awk -F"'" '{print $2}')
# hy password
hy_password=$(grep -o "HY_PASSWORD='[^']*'" /root/sbox/config | awk -F"'" '{print $2}')
# Generate the hy link
hy2_link="hysteria2://$hy_password@$server_ip:$hy_port?insecure=1&sni=$hy_server_name"
echo ""
echo ""
show_notice "$(green "Hysteria2 通用链接和二维码和通用参数")"
echo ""
echo ""
green "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━hysteria2 通用链接格式━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
echo "$hy2_link"
echo ""
green "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
echo ""
green "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━hysteria2 二维码━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
qrencode -t UTF8 $hy2_link
echo ""
green "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
echo ""
green "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━Hysteria2 客户端通用参数━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
echo "服务器ip: $server_ip"
echo "端口号: $hy_port"
echo "密码password: $hy_password"
echo "域名SNI: $hy_server_name"
echo "跳过证书验证(允许不安全): True"
echo ""
green "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
echo ""
green "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━Hysteria2 官方内核yaml文件(可搭配v2rayN)━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
cat << EOF
server: $server_ip:$hy_port
auth: $hy_password
tls:
sni: $hy_server_name
insecure: true
# 可自己修改对应带宽,不添加则默认为bbr,否则使用hy2的brutal拥塞控制
# bandwidth:
# up: 100 mbps
# down: 100 mbps
fastOpen: true
socks5:
listen: 127.0.0.1:50000
EOF
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
show_notice "sing-box客户端配置参数"
cat << EOF
{
"log": {
"level": "debug",
"timestamp": true
},
"dns": {
"servers": [
{
"tag": "proxyDns",
"address": "8.8.8.8",
"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"
},
{
"geosite": "category-ads-all",
"server": "block"
},
{
"outbound": "any",
"server": "localDns",
"disable_cache": true
},
{
"geosite": "cn",
"server": "localDns"
},
{
"clash_mode": "direct",
"server": "localDns"
},
{
"clash_mode": "global",
"server": "proxyDns"
},
{
"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
}
],
"route": {
"auto_detect_interface": true,
"final": "proxy",
"geoip": {
"download_url": "https://testingcf.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@release/geoip.db",
"download_detour": "direct"
},
"geosite": {
"download_url": "https://testingcf.jsdelivr.net/gh/MetaCubeX/meta-rules-dat@release/geosite.db",
"download_detour": "direct"
},
"rules": [
{
"protocol": "dns",
"outbound": "dns-out"
},
{
"network": "udp",
"port": 443,
"outbound": "block"
},
{
"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"
},
{
"geosite": "geolocation-!cn",
"outbound": "proxy"
},
{
"geoip": [
"private",
"cn"
],
"outbound": "direct"
},
{
"geosite": "cn",
"outbound": "direct"
}
]
},
"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",
"store_selected": true,
"cache_file": "",
"cache_id": ""
}
}
}
EOF
}
#enable bbr
enable_bbr() {
# temporary workaround for installing bbr
bash <(curl -L -s https://raw.githubusercontent.com/teddysun/across/master/bbr.sh)
echo ""
}
#修改sb
modify_singbox() {
#modifying reality configuration
show_notice "开始修改reality端口号和域名"
reality_current_port=$(grep -o "REALITY_PORT='[^']*'" /root/sbox/config | awk -F"'" '{print $2}')
while true; do
read -p "请输入想要修改的端口号 (当前端口号为 $reality_current_port): " reality_port
reality_port=${reality_port:-$reality_current_port}
if [ "$reality_port" -eq "$reality_current_port" ]; then
break
fi
if ss -tuln | grep -q ":$reality_port\b"; then
echo "端口 $reality_port 已经被占用,请选择其他端口。"
else
break
fi
done
reality_current_server_name=$(grep -o "REALITY_SERVER_NAME='[^']*'" /root/sbox/config | awk -F"'" '{print $2}')
read -p "请输入想要偷取的域名 (当前域名为 $reality_current_server_name): " reality_server_name
reality_server_name=${reality_server_name:-$reality_current_server_name}
echo ""
# modifying hysteria2 configuration
show_notice "开始修改hysteria2端口号"
echo ""
hy_current_port=$(grep -o "HY_PORT='[^']*'" /root/sbox/config | awk -F"'" '{print $2}')
while true; do
read -p "请输入想要修改的端口号 (当前端口号为 $hy_current_port): " hy_port
hy_port=${hy_port:-$hy_current_port}
if [ "$hy_port" -eq "$hy_current_port" ]; then
break
fi
if ss -tuln | grep -q ":$hy_port\b"; then
echo "端口 $hy_port 已经被占用,请选择其他端口。"
else
break
fi
done
# 修改sing-box
sed -i -e "/\"type\": \"vless\"/,/\"type\": \"hysteria2\"/ { /\"listen_port\":/s/[0-9]\+/$reality_port/ }" \
-e "/\"type\": \"hysteria2\"/,/\"tls\":/ { /\"listen_port\":/s/[0-9]\+/$hy_port/ }" \
-e "s/\"server_name\": *\"[^\"]*\"/\"server_name\": \"$reality_server_name\"/" \
-e "s/\"server\": *\"[^\"]*\"/\"server\": \"$reality_server_name\"/" /root/sbox/sbconfig_server.json
#修改config
sed -i "s/REALITY_PORT='[^']*'/REALITY_PORT='$reality_port'/" /root/sbox/config
sed -i "s/REALITY_SERVER_NAME='[^']*'/REALITY_SERVER_NAME='$reality_server_name'/" /root/sbox/config
sed -i "s/HY_PORT='[^']*'/HY_PORT='$hy_port'/" /root/sbox/config
# Restart sing-box service
systemctl restart sing-box
}
uninstall_singbox() {
# Stop and disable services
systemctl stop sing-box
systemctl disable sing-box > /dev/null 2>&1
# Remove service files
rm -f /etc/systemd/system/sing-box.service
# Remove configuration and executable files
rm -f /root/sbox/sbconfig_server.json
rm -f /root/sbox/sing-box
rm -f /root/sbox/mianyang.sh
rm -f /usr/bin/mianyang
rm -f /root/sbox/self-cert/private.key
rm -f /root/sbox/self-cert/cert.pem
rm -f /root/sbox/config
# Remove directories
rm -rf /root/sbox/self-cert/
rm -rf /root/sbox/
echo "卸载完成"
}
install_base
# Check if reality.json, sing-box, and sing-box.service already exist
if [ -f "/root/sbox/sbconfig_server.json" ] && [ -f "/root/sbox/config" ] && [ -f "/root/sbox/mianyang.sh" ] && [ -f "/usr/bin/mianyang" ] && [ -f "/root/sbox/sing-box" ] && [ -f "/etc/systemd/system/sing-box.service" ]; then
echo "sing-box-reality-hysteria2已经安装"
echo ""
echo "请选择选项:"
echo ""
echo "1. 重新安装"
echo "2. 修改配置"
echo "3. 显示客户端配置"
echo "4. 卸载"
echo "5. 更新sing-box内核"
echo "6. 一键开启bbr"
echo "7. 重启sing-box"
echo ""
read -p "Enter your choice (1-8): " choice
case $choice in
1)
show_notice "开始卸载..."
# Uninstall previous installation
uninstall_singbox
;;
2)
#修改sb
modify_singbox
# show client configuration
show_client_configuration
exit 0
;;
3)
# show client configuration
show_client_configuration
exit 0
;;
4)
uninstall_singbox
exit 0
;;
5)
show_notice "更新 Sing-box..."
download_singbox
# Check configuration and start the service
if /root/sbox/sing-box check -c /root/sbox/sbconfig_server.json; then
echo "Configuration checked successfully. Starting sing-box service..."
systemctl restart sing-box
fi
echo ""
exit 0
;;
6)
enable_bbr
exit 0
;;
7)
systemctl restart sing-box
echo "重启完成"
exit 0
;;
*)
echo "Invalid choice. Exiting."
exit 1
;;
esac
fi
mkdir -p "/root/sbox/"
download_singbox
# reality
red "开始配置Reality"
echo ""
# Generate key pair
echo "自动生成基本参数"
echo ""
key_pair=$(/root/sbox/sing-box generate reality-keypair)
echo "Key pair生成完成"
echo ""
# Extract private key and public key
private_key=$(echo "$key_pair" | awk '/PrivateKey/ {print $2}' | tr -d '"')
public_key=$(echo "$key_pair" | awk '/PublicKey/ {print $2}' | tr -d '"')
# Generate necessary values
reality_uuid=$(/root/sbox/sing-box generate uuid)
short_id=$(/root/sbox/sing-box generate rand --hex 8)
echo "uuid和短id 生成完成"
echo ""
# Ask for listen port
while true; do
read -p "请输入Reality端口号 (default: 443): " reality_port
reality_port=${reality_port:-443}
# 检测端口是否被占用
if ss -tuln | grep -q ":$reality_port\b"; then
echo "端口 $reality_port 已经被占用,请重新输入。"
else
break
fi
done
echo ""
# Ask for server name (sni)
read -p "请输入想要偷取的域名,需要支持tls1.3 (default: itunes.apple.com): " reality_server_name
reality_server_name=${reality_server_name:-itunes.apple.com}
echo ""
# hysteria2
green "开始配置hysteria2"
echo ""
# Generate hysteria necessary values
hy_password=$(/root/sbox/sing-box generate rand --hex 8)
echo "自动生成了8位随机密码"
echo ""
# Ask for listen port
while true; do
read -p "请输入hysteria2监听端口 (default: 8443): " hy_port
hy_port=${hy_port:-8443}
# 检测端口是否被占用
if ss -tuln | grep -q ":$hy_port\b"; then
echo "端口 $hy_port 已经被占用,请选择其他端口。"
else
break
fi
done
echo ""
# Ask for self-signed certificate domain
read -p "输入自签证书域名 (default: bing.com): " hy_server_name
hy_server_name=${hy_server_name:-bing.com}
mkdir -p /root/sbox/self-cert/ && openssl ecparam -genkey -name prime256v1 -out /root/sbox/self-cert/private.key && openssl req -new -x509 -days 36500 -key /root/sbox/self-cert/private.key -out /root/sbox/self-cert/cert.pem -subj "/CN=${hy_server_name}"
echo ""
echo "自签证书生成完成"
echo ""
#ip地址
server_ip=$(curl -s4m8 ip.sb -k) || server_ip=$(curl -s6m8 ip.sb -k)
#config配置文件
cat > /root/sbox/config <<EOF
# VPS ip
SERVER_IP='$server_ip'
# Singbox
# Reality
PRIVATE_KEY='$private_key'
PUBLIC_KEY='$public_key'
SHORT_ID='$short_id'
REALITY_UUID='$reality_uuid'
REALITY_PORT='$reality_port'
REALITY_SERVER_NAME='$reality_server_name'
# Hy2
HY_PORT='$hy_port'
HY_SERVER_NAME='$hy_server_name'
HY_PASSWORD='$hy_password'
EOF
# sbox配置文件
cat > /root/sbox/sbconfig_server.json << EOF
{
"log": {
"disabled": false,
"level": "info",
"timestamp": true
},
"inbounds": [
{
"type": "vless",
"tag": "vless-in",
"listen": "::",
"listen_port": $reality_port,
"users": [
{
"uuid": "$reality_uuid",
"flow": "xtls-rprx-vision"
}
],
"tls": {
"enabled": true,
"server_name": "$reality_server_name",
"reality": {
"enabled": true,
"handshake": {
"server": "$reality_server_name",
"server_port": 443
},
"private_key": "$private_key",
"short_id": ["$short_id"]
}
}
},
{
"type": "hysteria2",
"tag": "hy2-in",
"listen": "::",
"listen_port": $hy_port,
"users": [
{
"password": "$hy_password"
}
],
"tls": {
"enabled": true,
"alpn": [
"h3"
],
"certificate_path": "/root/sbox/self-cert/cert.pem",
"key_path": "/root/sbox/self-cert/private.key"
}
}
],
"outbounds": [
{
"type": "direct",
"tag": "direct"
},
{
"type": "block",
"tag": "block"
}
]
}
EOF
# Create sing-box.service
cat > /etc/systemd/system/sing-box.service <<EOF
[Unit]
After=network.target nss-lookup.target
[Service]
User=root
WorkingDirectory=/root
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE CAP_NET_RAW
AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE CAP_NET_RAW
ExecStart=/root/sbox/sing-box run -c /root/sbox/sbconfig_server.json
ExecReload=/bin/kill -HUP \$MAINPID
Restart=on-failure
RestartSec=10
LimitNOFILE=infinity
[Install]
WantedBy=multi-user.target
EOF
# Check configuration and start the service
if /root/sbox/sing-box check -c /root/sbox/sbconfig_server.json; then
echo "Configuration checked successfully. Starting sing-box service..."
systemctl daemon-reload
systemctl enable sing-box > /dev/null 2>&1
systemctl start sing-box
systemctl restart sing-box
create_shortcut
show_client_configuration
else
echo "Error in configuration. Aborting"
fi