-
Notifications
You must be signed in to change notification settings - Fork 98
/
install.sh
1073 lines (894 loc) · 30.9 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
# 检测当前用户是否为 root 用户
if [ "$EUID" -ne 0 ]; then
echo "请使用 root 用户执行此脚本!"
echo "你可以使用 'sudo -i' 进入 root 用户模式。"
exit 1
fi
check_sys() {
if [[ -f /etc/redhat-release ]]; then
release="centos"
elif grep -qi "debian" /etc/issue; then
release="debian"
elif grep -qi "ubuntu" /etc/issue; then
release="ubuntu"
elif grep -qi -E "centos|red hat|redhat|rocky" /etc/issue || grep -qi -E "centos|red hat|redhat|rocky" /proc/version; then
release="centos"
fi
if [[ -f /etc/debian_version ]]; then
OS_type="Debian"
echo "检测为Debian通用系统,判断有误请反馈"
elif [[ -f /etc/redhat-release || -f /etc/centos-release || -f /etc/fedora-release || -f /etc/rocky-release ]]; then
OS_type="CentOS"
echo "检测为CentOS通用系统,判断有误请反馈"
else
echo "Unknown"
fi
}
_exists() {
local cmd="$1"
if eval type type >/dev/null 2>&1; then
eval type "$cmd" >/dev/null 2>&1
elif command >/dev/null 2>&1; then
command -v "$cmd" >/dev/null 2>&1
else
which "$cmd" >/dev/null 2>&1
fi
local rt=$?
return ${rt}
}
random_color() {
colors=("31" "32" "33" "34" "35" "36" "37")
echo -e "\e[${colors[$((RANDOM % 7))]}m$1\e[0m"
}
if [ -f /etc/os-release ]; then
. /etc/os-release
OS_TYPE=$ID
OS_VERSION=$VERSION_ID
else
echo "无法确定操作系统类型。"
exit 1
fi
install_custom_packages() {
if [ "$OS_TYPE" = "debian" ] || [ "$OS_TYPE" = "ubuntu" ]; then
apt update
apt install -y wget sed sudo openssl net-tools psmisc procps iptables iproute2 ca-certificates jq
elif [ "$OS_TYPE" = "centos" ] || [ "$OS_TYPE" = "rhel" ] || [ "$OS_TYPE" = "fedora" ] || [ "$OS_TYPE" = "rocky" ]; then
yum install -y epel-release
yum install -y wget sed sudo openssl net-tools psmisc procps-ng iptables iproute ca-certificates jq
else
echo "不支持的操作系统。"
exit 1
fi
}
install_custom_packages
echo "已安装的软件包:"
for pkg in wget sed openssl iptables jq; do
if command -v $pkg >/dev/null 2>&1; then
echo "$pkg 已安装"
else
echo "$pkg 未安装"
fi
done
echo "所有指定的软件包均已安装完毕。"
set_architecture() {
case "$(uname -m)" in
'i386' | 'i686')
arch='386'
;;
'amd64' | 'x86_64')
arch='amd64'
;;
'armv5tel' | 'armv6l' | 'armv7' | 'armv7l')
arch='arm'
;;
'armv8' | 'aarch64')
arch='arm64'
;;
'mips' | 'mipsle' | 'mips64' | 'mips64le')
arch='mipsle'
;;
's390x')
arch='s390x'
;;
*)
echo "暂时不支持你的系统哦,可能是因为不在已知架构范围内。"
exit 1
;;
esac
}
get_installed_version() {
if [ -x "/root/hy3/hysteria-linux-$arch" ]; then
version="$("/root/hy3/hysteria-linux-$arch" version | grep Version | grep -o 'v[.0-9]*')"
else
version="你还没有安装,老登"
fi
}
get_latest_version() {
local tmpfile
tmpfile=$(mktemp)
if ! curl -sS "https://api.hy2.io/v1/update?cver=installscript&plat=linux&arch="$arch"&chan=release&side=server" -o "$tmpfile"; then
error "Failed to get the latest version from Hysteria 2 API, please check your network and try again."
exit 11
fi
local latest_version
latest_version=$(grep -oP '"lver":\s*\K"v.*?"' "$tmpfile" | head -1)
latest_version=${latest_version#'"'}
latest_version=${latest_version%'"'}
if [[ -n "$latest_version" ]]; then
echo "$latest_version"
fi
rm -f "$tmpfile"
}
checkact() {
pid=$(pgrep -f "hysteria-linux-$arch")
if [ -n "$pid" ]; then
hy2zt="运行中"
else
hy2zt="未运行"
fi
}
BBR_grub() {
if [[ "${OS_type}" == "CentOS" ]]; then
if [[ ${version} == "6" ]]; then
if [ -f "/boot/grub/grub.conf" ]; then
sed -i 's/^default=.*/default=0/g' /boot/grub/grub.conf
elif [ -f "/boot/grub/grub.cfg" ]; then
grub-mkconfig -o /boot/grub/grub.cfg
grub-set-default 0
elif [ -f "/boot/efi/EFI/centos/grub.cfg" ]; then
grub-mkconfig -o /boot/efi/EFI/centos/grub.cfg
grub-set-default 0
elif [ -f "/boot/efi/EFI/redhat/grub.cfg" ]; then
grub-mkconfig -o /boot/efi/EFI/redhat/grub.cfg
grub-set-default 0
else
echo -e "${Error} grub.conf/grub.cfg 找不到,请检查."
exit
fi
elif [[ ${version} == "7" ]]; then
if [ -f "/boot/grub2/grub.cfg" ]; then
grub2-mkconfig -o /boot/grub2/grub.cfg
grub2-set-default 0
elif [ -f "/boot/efi/EFI/centos/grub.cfg" ]; then
grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg
grub2-set-default 0
elif [ -f "/boot/efi/EFI/redhat/grub.cfg" ]; then
grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg
grub2-set-default 0
else
echo -e "${Error} grub.cfg 找不到,请检查."
exit
fi
elif [[ ${version} == "8" ]]; then
if [ -f "/boot/grub2/grub.cfg" ]; then
grub2-mkconfig -o /boot/grub2/grub.cfg
grub2-set-default 0
elif [ -f "/boot/efi/EFI/centos/grub.cfg" ]; then
grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg
grub2-set-default 0
elif [ -f "/boot/efi/EFI/redhat/grub.cfg" ]; then
grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg
grub2-set-default 0
else
echo -e "${Error} grub.cfg 找不到,请检查."
exit
fi
grubby --info=ALL | awk -F= '$1=="kernel" {print i++ " : " $2}'
fi
elif [[ "${OS_type}" == "Debian" ]]; then
if _exists "update-grub"; then
update-grub
elif [ -f "/usr/sbin/update-grub" ]; then
/usr/sbin/update-grub
else
apt install grub2-common -y
update-grub
fi
#exit 1
fi
}
check_version() {
if [[ -s /etc/redhat-release ]]; then
version=$(grep -oE "[0-9.]+" /etc/redhat-release | cut -d . -f 1)
else
version=$(grep -oE "[0-9.]+" /etc/issue | cut -d . -f 1)
fi
bit=$(uname -m)
check_github
}
installxanmod1 () {
# 检查系统是否为 Debian 或 Ubuntu
if [[ $(cat /etc/os-release) =~ ^(Debian|Ubuntu) ]]; then
echo "OJBK"
else
echo "系统不是 Debian 或 Ubuntu"
exit 1
fi
# 检查系统架构
if [[ $(uname -m) =~ ^(x86_64|amd64) ]]; then
echo "正在安装中,请稍后……"
else
echo "系统架构不是 x86/amd64,牢弟,买个好点的吧"
exit 1
fi
echo "系统符合要求,继续执行脚本"
wget -qO - https://dl.xanmod.org/archive.key | sudo gpg --dearmor -o /usr/share/keyrings/xanmod-archive-keyring.gpg
echo 'deb [signed-by=/usr/share/keyrings/xanmod-archive-keyring.gpg] http://deb.xanmod.org releases main' | sudo tee /etc/apt/sources.list.d/xanmod-release.list
sudo apt update && sudo apt install linux-xanmod-x64v3
BBR_grub
echo -e "${Tip} 内核安装完毕,请参考上面的信息检查是否安装成功,默认从排第一的高版本内核启动"
echo "安装成功,请自行重启系统"
}
installxanmod2 () {
check_version
wget -O check_x86-64_psabi.sh https://dl.xanmod.org/check_x86-64_psabi.sh
chmod +x check_x86-64_psabi.sh
cpu_level=$(./check_x86-64_psabi.sh | awk -F 'v' '{print $2}')
echo -e "CPU supports \033[32m${cpu_level}\033[0m"
# exit
if [[ ${bit} != "x86_64" ]]; then
echo -e "${Error} 不支持x86_64以外的系统 !" && exit 1
fi
if [[ "${OS_type}" == "Debian" ]]; then
apt update
apt-get install gnupg gnupg2 gnupg1 sudo -y
echo 'deb http://deb.xanmod.org releases main' | sudo tee /etc/apt/sources.list.d/xanmod-kernel.list
wget -qO - https://dl.xanmod.org/gpg.key | sudo apt-key --keyring /etc/apt/trusted.gpg.d/xanmod-kernel.gpg add -
if [[ "${cpu_level}" == "4" ]]; then
apt update && apt install linux-xanmod-x64v4 -y
elif [[ "${cpu_level}" == "3" ]]; then
apt update && apt install linux-xanmod-x64v3 -y
elif [[ "${cpu_level}" == "2" ]]; then
apt update && apt install linux-xanmod-x64v2 -y
else
apt update && apt install linux-xanmod-x64v1 -y
fi
else
echo -e "${Error} 不支持当前系统 ${release} ${version} ${bit} !" && exit 1
fi
BBR_grub
echo -e "${Tip} 内核安装完毕,请参考上面的信息检查是否安装成功,默认从排第一的高版本内核启动,请自行重启系统"
}
detele_kernel() {
if [[ "${OS_type}" == "CentOS" ]]; then
rpm_total=$(rpm -qa | grep kernel | grep -v "${kernel_version}" | grep -v "noarch" | wc -l)
if [ "${rpm_total}" ] >"1"; then
echo -e "检测到 ${rpm_total} 个其余内核,开始卸载..."
for ((integer = 1; integer <= ${rpm_total}; integer++)); do
rpm_del=$(rpm -qa | grep kernel | grep -v "${kernel_version}" | grep -v "noarch" | head -${integer})
echo -e "开始卸载 ${rpm_del} 内核..."
rpm --nodeps -e ${rpm_del}
echo -e "卸载 ${rpm_del} 内核卸载完成,继续..."
done
echo --nodeps -e "内核卸载完毕,继续..."
else
echo -e " 检测到 内核 数量不正确,请检查 !" && exit 1
fi
elif [[ "${OS_type}" == "Debian" ]]; then
deb_total=$(dpkg -l | grep linux-image | awk '{print $2}' | grep -v "${kernel_version}" | wc -l)
if [ "${deb_total}" ] >"1"; then
echo -e "检测到 ${deb_total} 个其余内核,开始卸载..."
for ((integer = 1; integer <= ${deb_total}; integer++)); do
deb_del=$(dpkg -l | grep linux-image | awk '{print $2}' | grep -v "${kernel_version}" | head -${integer})
echo -e "开始卸载 ${deb_del} 内核..."
apt-get purge -y ${deb_del}
apt-get autoremove -y
echo -e "卸载 ${deb_del} 内核卸载完成,继续..."
done
echo -e "内核卸载完毕,继续..."
else
echo -e " 检测到 内核 数量不正确,请检查 !" && exit 1
fi
fi
}
detele_kernel_head() {
if [[ "${OS_type}" == "CentOS" ]]; then
rpm_total=$(rpm -qa | grep kernel-headers | grep -v "${kernel_version}" | grep -v "noarch" | wc -l)
if [ "${rpm_total}" ] >"1"; then
echo -e "检测到 ${rpm_total} 个其余head内核,开始卸载..."
for ((integer = 1; integer <= ${rpm_total}; integer++)); do
rpm_del=$(rpm -qa | grep kernel-headers | grep -v "${kernel_version}" | grep -v "noarch" | head -${integer})
echo -e "开始卸载 ${rpm_del} headers内核..."
rpm --nodeps -e ${rpm_del}
echo -e "卸载 ${rpm_del} 内核卸载完成,继续..."
done
echo --nodeps -e "内核卸载完毕,继续..."
else
echo -e " 检测到 内核 数量不正确,请检查 !" && exit 1
fi
elif [[ "${OS_type}" == "Debian" ]]; then
deb_total=$(dpkg -l | grep linux-headers | awk '{print $2}' | grep -v "${kernel_version}" | wc -l)
if [ "${deb_total}" ] >"1"; then
echo -e "检测到 ${deb_total} 个其余head内核,开始卸载..."
for ((integer = 1; integer <= ${deb_total}; integer++)); do
deb_del=$(dpkg -l | grep linux-headers | awk '{print $2}' | grep -v "${kernel_version}" | head -${integer})
echo -e "开始卸载 ${deb_del} headers内核..."
apt-get purge -y ${deb_del}
apt-get autoremove -y
echo -e "卸载 ${deb_del} 内核卸载完成,继续..."
done
echo -e "内核卸载完毕,继续..."
else
echo -e " 检测到 内核 数量不正确,请检查 !" && exit 1
fi
fi
}
detele_kernel_custom() {
BBR_grub
read -p " 查看上面内核输入需保留保留保留的内核关键词(如:5.15.0-11) :" kernel_version
detele_kernel
detele_kernel_head
BBR_grub
}
welcome() {
echo -e "$(random_color '
░██ ░██
░██ ░██ ░████ ░█ ░█ ░█░█░█
░██ ░██ ░█ █ ░█ ░█ ░█ ░█
░██████ ░██████ ░█ ░█ ░█ ░█
░██ ░██ ░█ ░█ ░█ ░█ ░█ ░█░█░█
░██ ░██ ░██ █ ░█ ░█ ')"
echo -e "$(random_color '
人生有两出悲剧:一是万念俱灰,另一是踌躇满志 ')"
}
echo -e "$(random_color '安装必要依赖中......')"
install_missing_commands > /dev/null 2>&1
echo -e "$(random_color '依赖安装完成')"
set_architecture
get_installed_version
latest_version=$(get_latest_version)
checkact
uninstall_hysteria() {
sudo systemctl stop hysteria.service
sudo systemctl disable hysteria.service
if [ -f "/etc/systemd/system/hysteria.service" ]; then
sudo rm "/etc/systemd/system/hysteria.service"
echo "Hysteria 服务器服务文件已删除。"
else
echo "Hysteria 服务器服务文件不存在。"
fi
process_name="hysteria-linux-$arch"
pid=$(pgrep -f "$process_name")
if [ -n "$pid" ]; then
echo "找到 $process_name 进程 (PID: $pid),正在杀死..."
kill "$pid"
echo "$process_name 进程已被杀死。"
else
echo "未找到 $process_name 进程。"
fi
if [ -f "/root/hy3/hysteria-linux-$arch" ]; then
rm -f "/root/hy3/hysteria-linux-$arch"
echo "Hysteria 服务器二进制文件已删除。"
else
echo "Hysteria 服务器二进制文件不存在。"
fi
if [ -f "/root/hy3/config.yaml" ]; then
rm -f "/root/hy3/config.yaml"
echo "Hysteria 服务器配置文件已删除。"
else
echo "Hysteria 服务器配置文件不存在。"
fi
rm -rf /root/hy3
systemctl stop ipppp.service
systemctl disable ipppp.service
rm -rf /etc/systemd/system/ipppp.service
rm -rf /bin/hy2
echo "卸载完成(ง ื▿ ื)ว."
}
hy2easy() {
# 删除现有的 hy2 二进制文件
rm -rf /bin/hy2
# 下载并安装新的 hy2 脚本
sudo wget -q hy2.willloving.xyz -O /bin/hy2 && chmod 777 /bin/hy2
echo "已添加 hy2 快捷方式"
}
hy2easy
welcome
#这些就行提示你输入的😇
echo "$(random_color '选择一个操作,小崽子(ง ื▿ ื)ว:')"
echo -e "$(random_color '输入hy2快捷启动脚本')"
echo "1. 安装(以梦为马)"
echo "2. 卸载(以心为疆)"
echo "$(random_color '>>>>>>>>>>>>>>>>>>>>')"
echo "3. 查看配置(穿越时空)"
echo "4. 退出脚本(回到未来)"
echo "$(random_color '>>>>>>>>>>>>>>>>>>>>')"
echo "5. 在线更新hy2内核(您当前的hy2版本:$version)"
echo "6. hy2内核管理"
echo "7. 安装xanmod内核(更好的调动网络资源)"
echo "hy2内核最新版本为: $latest_version"
echo "$(random_color '>>>>>>>>>>>>>>>>>>>>')"
echo "hysteria2状态: $hy2zt"
read -p "输入操作编号 (1/2/3/4/5): " choice
case $choice in
1)
#啥也没有
;;
2)
uninstall_hysteria > /dev/null 2>&1
echo -e "$(random_color '你别急,别急,正在卸载......')"
echo -e "$(random_color '卸载完成,老登ψ(`∇´)ψ!')"
exit
;;
4)
# Exit script
exit
;;
3)
echo "$(random_color '下面是你的nekobox节点信息')"
echo "$(random_color '>>>>>>>>>>>>>>>>>>>>')"
echo "$(random_color '>>>>>>>>>>>>>>>>>>>>')"
cd /root/hy3/
cat /root/hy3/neko.txt
echo "$(random_color '>>>>>>>>>>>>>>>>>>>>')"
echo "$(random_color '>>>>>>>>>>>>>>>>>>>>')"
echo "$(random_color '下面是你的clashmate配置')"
cat /root/hy3/clash-mate.yaml
echo "$(random_color '>>>>>>>>>>>>>>>>>>>>')"
exit
;;
5)
get_updated_version() {
if [ -x "/root/hy3/hysteria-linux-$arch" ]; then
version2="$("/root/hy3/hysteria-linux-$arch" version | grep Version | grep -o 'v[.0-9]*')"
else
version2="你还没有安装,老登"
fi
}
updatehy2 () {
process_name="hysteria-linux-$arch"
pid=$(pgrep -f "$process_name")
if [ -n "$pid" ]; then
echo "找到 $process_name 进程 (PID: $pid),正在杀死..."
kill "$pid"
echo "$process_name 进程已被杀死。"
else
echo "未找到 $process_name 进程。"
fi
cd /root/hy3
rm -r hysteria-linux-$arch
if wget -O hysteria-linux-$arch https://download.hysteria.network/app/latest/hysteria-linux-$arch; then
chmod +x hysteria-linux-$arch
else
if wget -O hysteria-linux-$arch https://github.com/apernet/hysteria/releases/download/app/$latest_version/hysteria-linux-$arch; then
chmod +x hysteria-linux-$arch
else
echo "无法从任何网站下载文件"
exit 1
fi
fi
systemctl stop hysteria.service
systemctl start hysteria.service
echo "更新完成,不是哥们,你有什么实力,你直接给我坐下(ง ื▿ ื)ว."
}
echo "$(random_color '正在更新中,别急,老登')"
sleep 1
updatehy2 > /dev/null 2>&1
echo "$(random_color '更新完成,老登')"
get_updated_version
echo "您当前的更新后hy2版本:$version2"
exit
;;
6)
echo "输入1启动hy2内核,输入2关闭hy2内核,输入3重启hy2内核"
read choicehy2
if [ "$choicehy2" = "1" ]; then
sudo systemctl start hysteria.service
echo "hy2内核启动成功"
elif [ "$choicehy2" = "2" ]; then
sudo systemctl stop hysteria.service
echo "hy2内核关闭成功"
elif [ "$choicehy2" = "3" ]; then
sudo systemctl restart hysteria.service
echo "hy2内核重启成功"
else
echo "请输入正确选项"
fi
exit
;;
7)
echo "输入y安装,输入n取消,输入o卸载 (y/n/o)"
read answer
if [ "$answer" = "y" ]; then
check_sys
installxanmod2
elif [ "$answer" = "n" ]; then
echo "Canceling and exiting..."
exit 0
elif [ "$answer" = "o" ]; then
check_sys
detele_kernel_custom
else
echo "Invalid input. Please enter y, n, or o."
fi
exit
;;
*)
echo "$(random_color '无效的选择,退出脚本。')"
exit
;;
esac
echo "$(random_color '别急,别急,别急,老登')"
sleep 1
if [ "$hy2zt" = "运行中" ]; then
echo "Hysteria 正在运行,请先卸载再安装。"
exit 1
else
echo "原神,启动。"
fi
uninstall_hysteria > /dev/null 2>&1
installhy2 () {
cd /root
mkdir -p ~/hy3
cd ~/hy3
REPO_URL="https://github.com/apernet/hysteria/releases"
LATEST_RELEASE=$(curl -s $REPO_URL/latest | jq -r '.tag_name')
DOWNLOAD_URL="https://github.com/apernet/hysteria/releases/download/$LATEST_RELEASE/hysteria-linux-$arch"
if wget -O hysteria-linux-$arch https://download.hysteria.network/app/latest/hysteria-linux-$arch; then
chmod +x hysteria-linux-$arch
else
if wget -O hysteria-linux-$arch $DOWNLOAD_URL; then
chmod +x hysteria-linux-$arch
else
echo "无法从任何网站下载文件"
exit 1
fi
fi
echo "Latest release version: $LATEST_RELEASE"
echo "Download URL: $DOWNLOAD_URL"
}
echo "$(random_color '正在下载中,老登( ゚д゚)つBye')"
sleep 1
installhy2 > /dev/null 2>&1
# 就是写一个配置文件,你可以自己修改,别乱搞就行,安装hysteria2文档修改
cat <<EOL > config.yaml
listen: :443
auth:
type: password
password: Se7RAuFZ8Lzg
masquerade:
type: proxy
file:
dir: /www/masq
proxy:
url: https://news.ycombinator.com/
rewriteHost: true
string:
content: hello stupid world
headers:
content-type: text/plain
custom-stuff: ice cream so good
statusCode: 200
bandwidth:
up: 0 gbps
down: 0 gbps
udpIdleTimeout: 90s
EOL
while true; do
echo "$(random_color '请输入端口号(留空默认443,输入0随机2000-60000,你可以输入1-65630指定端口号): ')"
read -p "" port
if [ -z "$port" ]; then
port=443
elif [ "$port" -eq 0 ]; then
port=$((RANDOM % 58001 + 2000))
elif ! [[ "$port" =~ ^[0-9]+$ ]]; then
echo "$(random_color '我的动物朋友,请输入数字好吧,请重新输入端口号:')"
continue
fi
while netstat -tuln | grep -q ":$port "; do
echo "$(random_color '端口已被占用,请重新输入端口号:')"
read -p "" port
done
if sed -i "s/443/$port/" config.yaml; then
echo "$(random_color '端口号已设置为:')" "$port"
else
echo "$(random_color '替换端口号失败,退出脚本。')"
exit 1
fi
generate_certificate() {
read -p "请输入要用于自签名证书的域名(默认为 bing.com): " user_domain
domain_name=${user_domain:-"bing.com"}
if curl --output /dev/null --silent --head --fail "$domain_name"; then
mkdir -p /etc/ssl/private
openssl req -x509 -nodes -newkey ec:<(openssl ecparam -name prime256v1) -keyout "/etc/ssl/private/$domain_name.key" -out "/etc/ssl/private/$domain_name.crt" -subj "/CN=$domain_name" -days 36500
chmod 777 "/etc/ssl/private/$domain_name.key" "/etc/ssl/private/$domain_name.crt"
echo -e "自签名证书和私钥已生成!"
else
echo -e "无效的域名或域名不可用,请输入有效的域名!"
generate_certificate
fi
}
read -p "请选择证书类型(输入 1 使用ACME证书,输入 2 使用自签名证书,回车默认acme证书申请): " cert_choice
if [ "$cert_choice" == "2" ]; then
generate_certificate
certificate_path="/etc/ssl/private/$domain_name.crt"
private_key_path="/etc/ssl/private/$domain_name.key"
echo -e "证书文件已保存到 /etc/ssl/private/$domain_name.crt"
echo -e "私钥文件已保存到 /etc/ssl/private/$domain_name.key"
temp_file=$(mktemp)
echo -e "temp_file: $temp_file"
sed '3i\tls:\n cert: '"/etc/ssl/private/$domain_name.crt"'\n key: '"/etc/ssl/private/$domain_name.key"'' /root/hy3/config.yaml > "$temp_file"
mv "$temp_file" /root/hy3/config.yaml
touch /root/hy3/ca
#这里加了一个小的变量
ovokk="insecure=1&"
choice1="true"
echo -e "已将证书和密钥信息写入 /root/hy3/config.yaml 文件。"
get_ipv4_info() {
ip_address=$(wget -4 -qO- --no-check-certificate --user-agent=Mozilla --tries=2 --timeout=3 http://ip-api.com/json/) &&
ispck=$(expr "$ip_address" : '.*isp\":[ ]*\"\([^"]*\).*')
if echo "$ispck" | grep -qi "cloudflare"; then
echo "检测到Warp,请输入正确的服务器 IP:"
read new_ip
ipwan="$new_ip"
else
ipwan="$(expr "$ip_address" : '.*query\":[ ]*\"\([^"]*\).*')"
fi
}
get_ipv6_info() {
ip_address=$(wget -6 -qO- --no-check-certificate --user-agent=Mozilla --tries=2 --timeout=3 https://api.ip.sb/geoip) &&
ispck=$(expr "$ip_address" : '.*isp\":[ ]*\"\([^"]*\).*')
if echo "$ispck" | grep -qi "cloudflare"; then
echo "检测到Warp,请输入正确的服务器 IP:"
read new_ip
ipwan="[$new_ip]"
else
ipwan="[$(expr "$ip_address" : '.*ip\":[ ]*\"\([^"]*\).*')]"
fi
}
while true; do
echo "1. IPv4 模式"
echo "2. IPv6 模式"
echo "按回车键选择默认的 IPv4 模式."
read -p "请选择: " choice
case $choice in
1)
get_ipv4_info
echo "老登你的IP 地址为:$ipwan"
ipta="iptables"
break
;;
2)
get_ipv6_info
echo "老登你的IP 地址为:$ipwan"
ipta="ip6tables"
break
;;
"")
echo "使用默认的 IPv4 模式。"
get_ipv4_info
echo "老登你的IP 地址为:$ipwan"
ipta="iptables"
break
;;
*)
echo "输入无效。请输入1或2,或者按回车键使用默认的 IPv4 模式。"
;;
esac
done
fi
if [ -f "/root/hy3/ca" ]; then
echo "$(random_color '/root/hy3/ 文件夹中已存在名为 ca 的文件。跳过添加操作。')"
else
echo "$(random_color '请输入你的域名(必须是解析好的域名哦): ')"
read -p "" domain
while [ -z "$domain" ]; do
echo "$(random_color '域名不能为空,请重新输入: ')"
read -p "" domain
done
echo "$(random_color '请输入你的邮箱(默认随机邮箱): ')"
read -p "" email
if [ -z "$email" ]; then
random_part=$(head /dev/urandom | LC_ALL=C tr -dc A-Za-z0-9 | head -c 6 ; echo '')
email="${random_part}@gmail.com"
fi
if [ -f "config.yaml" ]; then
echo -e "\nAppending to config.yaml..."
sed -i '3i\acme:\n domains:\n - '$domain'\n email: '$email'' config.yaml
echo "$(random_color '域名和邮箱已添加到 config.yaml 文件。')"
ipta="iptables"
choice2="false"
else
echo "$(random_color 'config.yaml 文件不存在,无法添加。')"
exit 1
fi
fi
echo "请选择一个选项:"
echo "1. 是否开启dns申请证书方式(默认cloudflare申请方式,需要api令牌,邮箱必须为注册邮箱)"
echo "2. 跳过(自签用户和不知道这个的回车默认直接跳过就行)"
read -p "请输入你的选择 (1或2): " choice
# 如果用户直接按回车,默认选择2
if [ -z "$choice" ]; then
choice=2
fi
if [ "$choice" -eq 1 ]; then
read -p "请输入Cloudflare的API令牌: " api_key
# 查找email行的位置
line_number=$(grep -n "email" /root/hy3/config.yaml | cut -d: -f1)
if [ -z "$line_number" ]; then
echo "未找到email行,请检查配置文件。"
exit 1
fi
sed -i "${line_number}a\\
type: dns\\
dns:\\
name: cloudflare\\
config:\\
cloudflare_api_token: $api_key" /root/hy3/config.yaml
echo "配置已成功添加到/root/hy3/config.yaml"
else
echo "跳过DNS配置步骤。"
fi
echo "$(random_color '请输入你的密码(留空将生成随机密码,不超过20个字符): ')"
read -p "" password
if [ -z "$password" ]; then
password=$(openssl rand -base64 20 | tr -dc 'a-zA-Z0-9')
fi
if sed -i "s/Se7RAuFZ8Lzg/$password/" config.yaml; then
echo "$(random_color '密码已设置为:')" $password
else
echo "$(random_color '替换密码失败,退出脚本。')"
exit 1
fi
echo "$(random_color '请输入伪装网址(默认https://news.ycombinator.com/): ')"
read -p "" masquerade_url
if [ -z "$masquerade_url" ]; then
masquerade_url="https://news.ycombinator.com/"
fi
if sed -i "s|https://news.ycombinator.com/|$masquerade_url|" config.yaml; then
echo "$(random_color '伪装域名已设置为:')" $masquerade_url
else
echo "$(random_color '替换伪装域名失败,退出脚本。')"
exit 1
fi
echo "$(random_color '是否要开启端口跳跃功能?如果你不知道是干啥的,就衮吧,不用开启(ง ื▿ ื)ว(回车默认不开启,输入1开启): ')"
read -p "" port_jump
if [ -z "$port_jump" ]; then
break
elif [ "$port_jump" -eq 1 ]; then
echo "$(random_color '请输入起始端口号(起始端口必须小于末尾端口): ')"
read -p "" start_port
echo "$(random_color '请输入末尾端口号(末尾端口必须大于起始端口): ')"
read -p "" end_port
if [ "$start_port" -lt "$end_port" ]; then
"$ipta" -t nat -A PREROUTING -i eth0 -p udp --dport "$start_port":"$end_port" -j DNAT --to-destination :"$port"
echo "$(random_color '端口跳跃功能已开启,将范围重定向到主端口:')" "$port"
break
else
echo "$(random_color '末尾端口必须大于起始端口,请重新输入。')"
fi
else
echo "$(random_color '输入无效,请输入1开启端口跳跃功能,或直接按回车跳过。')"
fi
done
if [ -n "$port_jump" ] && [ "$port_jump" -eq 1 ]; then
echo "#!/bin/bash" > /root/hy3/ipppp.sh
echo "$ipta -t nat -A PREROUTING -i eth0 -p udp --dport $start_port:$end_port -j DNAT --to-destination :$port" >> /root/hy3/ipppp.sh
chmod +x /root/hy3/ipppp.sh
echo "[Unit]" > /etc/systemd/system/ipppp.service
echo "Description=IP Port Redirect" >> /etc/systemd/system/ipppp.service
echo "" >> /etc/systemd/system/ipppp.service
echo "[Service]" >> /etc/systemd/system/ipppp.service
echo "ExecStart=/root/hy3/ipppp.sh" >> /etc/systemd/system/ipppp.service
echo "" >> /etc/systemd/system/ipppp.service
echo "[Install]" >> /etc/systemd/system/ipppp.service
echo "WantedBy=multi-user.target" >> /etc/systemd/system/ipppp.service
# 启用开机自启动服务
systemctl enable ipppp.service
# 启动服务
systemctl start ipppp.service
echo "$(random_color '已创建/ipppp.sh脚本文件并设置开机自启动。')"
fi
fuser -k -n udp $port
cat <<EOL > clash-mate.yaml
system-port: 7890
external-controller: 127.0.0.1:9090
allow-lan: false
mode: rule
log-level: info
ipv6: true
unified-delay: true
profile:
store-selected: true
store-fake-ip: true
tun:
enable: true
stack: system
auto-route: true
auto-detect-interface: true
dns:
enable: true
prefer-h3: true
listen: 0.0.0.0:53
enhanced-mode: fake-ip
nameserver:
- 223.5.5.5
- 8.8.8.8
proxies:
- name: Hysteria2
type: hysteria2
server: $domain$ipwan
port: $port
password: $password
sni: $domain$domain_name
skip-cert-verify: $choice1$choice2
proxy-groups:
- name: auto
type: select
proxies:
- Hysteria2
rules:
- MATCH,auto
EOL
echo "$(random_color '>>>>>>>>>>>>>>>>>>>>')"
echo "$(random_color '>>>>>>>>>>>>>>>>>>>>')"
echo "
clash-mate.yaml 已保存到当前文件夹
"
echo "$(random_color '>>>>>>>>>>>>>>>>>>>>')"
echo "$(random_color '>>>>>>>>>>>>>>>>>>>>')"
if nohup ./hysteria-linux-$arch server & then
echo "$(random_color '
Hysteria 服务器已启动。')"
else
echo "$(random_color '启动 Hysteria 服务器失败,退出脚本。')"
exit 1
fi
echo "$(random_color '>>>>>>>>>>>>>>>>>>>>')"
echo "$(random_color '>>>>>>>>>>>>>>>>>>>>')"