forked from SuperManito/LinuxMirrors
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChangeMirrors.sh
More file actions
executable file
·8437 lines (8029 loc) · 318 KB
/
ChangeMirrors.sh
File metadata and controls
executable file
·8437 lines (8029 loc) · 318 KB
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
## Author: SuperManito
## Modified: 2025-10-20
## License: MIT
## GitHub: https://github.com/SuperManito/LinuxMirrors
## Website: https://linuxmirrors.cn
## 定制方法
# 只需要在头部(此处)定义全局变量即可,具体详见官网文档,简单写几个例子
# SOURCE="www.example.com" # 指定软件源地址
# BRANCH="branch" # 指定软件源仓库
# WEB_PROTOCOL="https" # 指定 Web 协议
## 软件源列表
# 中国大陆默认
mirror_list_default=(
"mirrors.aliyun.com"
"mirrors.tencent.com"
"mirrors.huaweicloud.com"
"mirrors.cmecloud.cn"
"mirrors.ctyun.cn"
"mirrors.163.com"
"mirrors.volces.com"
"mirrors.tuna.tsinghua.edu.cn"
"mirrors.pku.edu.cn"
"mirrors.zju.edu.cn"
"mirrors.nju.edu.cn"
"mirror.lzu.edu.cn"
"mirror.sjtu.edu.cn"
"mirrors.cqupt.edu.cn"
"mirrors.ustc.edu.cn"
"mirror.iscas.ac.cn"
"__OFFICIAL_SOURCE_TAG__"
)
# 中国大陆教育网
mirror_list_edu=(
"mirrors.pku.edu.cn"
"mirror.bjtu.edu.cn"
"mirrors.bfsu.edu.cn"
"mirrors.bupt.edu.cn"
"mirrors.cqu.edu.cn"
"mirrors.cqupt.edu.cn"
"mirrors.neusoft.edu.cn"
"mirrors.uestc.cn"
"mirrors.scau.edu.cn"
"mirrors.hust.edu.cn"
"mirrors.jlu.edu.cn"
"mirrors.jcut.edu.cn"
"mirrors.jxust.edu.cn"
"mirror.lzu.edu.cn"
"mirrors.nju.edu.cn"
"mirrors.njtech.edu.cn"
"mirrors.njupt.edu.cn"
"mirrors.sustech.edu.cn"
"mirror.nyist.edu.cn"
"mirrors.qlu.edu.cn"
"mirrors.tuna.tsinghua.edu.cn"
"mirrors.sdu.edu.cn"
"mirrors.shanghaitech.edu.cn"
"mirror.sjtu.edu.cn"
"mirrors.sjtug.sjtu.edu.cn"
"mirrors.wsyu.edu.cn"
"mirrors.xjtu.edu.cn"
"mirrors.nwafu.edu.cn"
"mirrors.zju.edu.cn"
"mirrors.ustc.edu.cn"
"__OFFICIAL_SOURCE_TAG__"
)
# 境外以及海外地区
mirror_list_abroad=(
"mirrors.xtom.hk"
"mirror.01link.hk"
"download.nus.edu.sg/mirror"
"mirror.sg.gs"
"mirrors.xtom.sg"
"free.nchc.org.tw"
"mirror.ossplanet.net"
"linux.cs.nctu.edu.tw"
"ftp.tku.edu.tw"
"mirror.twds.com.tw"
"mirror.anigil.com"
"ftp.udx.icscoe.jp/Linux"
"ftp.jaist.ac.jp/pub/Linux"
"linux2.yz.yamagata-u.ac.jp/pub/Linux"
"mirrors.xtom.jp"
"mirrors.gbnetwork.com"
"mirror.kku.ac.th"
"mirror.vorboss.net"
"mirror.quickhost.uk"
"mirror.dogado.de"
"mirrors.xtom.de"
"ftp.halifax.rwth-aachen.de"
"ftp.agdsn.de"
"mirror.in2p3.fr/pub/linux"
"mirrors.ircam.fr/pub"
"eclats.crans.org"
"ftp.crihan.fr"
"mirrors.xtom.nl"
"mirror.datapacket.com"
"eu.edge.kernel.org"
"mirrors.xtom.ee"
"mirror.netsite.dk"
"mirrors.dotsrc.org"
"mirror.accum.se"
"ftp.lysator.liu.se"
"mirror.yandex.ru"
"mirror.linux-ia64.org"
"mirror.truenetwork.ru"
"ftp.belnet.be/mirror"
"ftp.cc.uoc.gr/mirrors/linux"
"ftp.fi.muni.cz/pub/linux"
"ftp.sh.cvut.cz"
"mirror.karneval.cz/pub/linux"
"mirrors.nic.cz"
"mirror.ethz.ch"
"mirrors.kernel.org"
"mirrors.mit.edu"
"mirror.math.princeton.edu/pub"
"ftp-chi.osuosl.org/pub"
"mirror.fcix.net"
"mirrors.xtom.com"
"mirror.steadfast.net"
"mirror.it.ubc.ca"
"mirror.xenyth.net"
"mirrors.switch.ca"
"mirror.pop-sc.rnp.br/mirror"
"mirror.uepg.br"
"mirror.ufscar.br"
"mirrors.eze.sysarmy.com"
"gsl-syd.mm.fcix.net"
"mirror.aarnet.edu.au/pub"
"mirror.datamossa.io"
"mirror.amaze.com.au"
"mirrors.xtom.au"
"mirror.overthewire.com.au"
"mirror.fsmg.org.nz"
"mirror.liquidtelecom.com"
"mirror.dimensiondata.com"
"__OFFICIAL_SOURCE_TAG__"
)
## 配置需要区分公网地址和内网地址的软件源(不分地域)
# 需要同时在两个数组变量中分别定义软件源地址,并且保证排列顺序一致
# 软件源公网地址列表
mirror_list_extranet=(
"mirrors.aliyun.com"
"mirrors.tencent.com"
"mirrors.huaweicloud.com"
"mirrors.ctyun.cn"
"mirrors.volces.com"
)
# 软件源内网地址列表
mirror_list_intranet=(
"mirrors.cloud.aliyuncs.com"
"mirrors.tencentyun.com"
"mirrors.myhuaweicloud.com"
"internal.mirrors.ctyun.cn"
"mirrors.ivolces.com"
)
## 赞助商广告
SPONSOR_ADS=(
"1Panel · Linux 面板|极简运维 ➜ \033[3mhttps://1panel.cn\033[0m"
"多途云 · 智能化防护,每一次连接皆在安全之下 ➜ \033[3mhttps://www.duotuyun.com\033[0m"
"毫秒镜像 · 专为中国开发者提供Docker镜像加速下载服务 ➜ \033[3mhttps://1ms.run\033[0m"
"不死鸟CDN · 香港日本高防CDN,免实名/免备案,轻松阻断DDOS/CC攻击 ➜ \033[3mhttps://www.bsncdn.org\033[0m"
"青叶云 · 香港1T高防|自助防火墙,无视CC|大带宽回国优化线路 ➜ \033[3mhttps://www.qingyeyun.com\033[0m"
"莱卡云 · 专业云计算服务器提供商 ➜ \033[3m https://www.lcayun.com\033[0m"
"云悠YUNYOO · 全球高性价比云服务器|低至15.99元起 ➜ \033[3mhttps://yunyoo.cc\033[0m"
"速拓云 · 国内高防云28元/月|香港云100M优化线路9元/月 ➜ \033[3mhttps://www.sutuoyun.com\033[0m"
"林枫云 · 专注独立IP高频VPS|R9/i9系列定制 ➜ \033[3mhttps://www.dkdun.cn\033[0m"
"语鹿云盾 · 专业CDN加速、防御,亚太百兆三网优化CDN低至9元起 ➜ \033[3mhttps://www.lucdn.cn\033[0m"
"不二云 · 国内外建站快响应服务器的不二之选 ➜ \033[3mhttps://cb2.cn\033[0m"
"HKGserver · 全球家宽|双ISP|住宅原生云服务器54元/月起 ➜ \033[3mhttps://www.hkgserver.com\033[0m"
"浪浪云 · BGP网络让每一次连接都纵享丝滑,明码标价、无套路续费 ➜ \033[3mhttps://langlangy.cn\033[0m"
)
##############################################################################
## 定义系统判定变量
SYSTEM_DEBIAN="Debian"
SYSTEM_UBUNTU="Ubuntu"
SYSTEM_KALI="Kali"
SYSTEM_DEEPIN="Deepin"
SYSTEM_LINUX_MINT="Linuxmint"
SYSTEM_ZORIN="Zorin"
SYSTEM_RASPBERRY_PI_OS="Raspberry Pi OS"
SYSTEM_REDHAT="RedHat"
SYSTEM_RHEL="Red Hat Enterprise Linux"
SYSTEM_CENTOS="CentOS"
SYSTEM_CENTOS_STREAM="CentOS Stream"
SYSTEM_ROCKY="Rocky"
SYSTEM_ALMALINUX="AlmaLinux"
SYSTEM_FEDORA="Fedora"
SYSTEM_ORACLE="Oracle Linux"
SYSTEM_OPENCLOUDOS="OpenCloudOS"
SYSTEM_OPENCLOUDOS_STREAM="OpenCloudOS Stream"
SYSTEM_TENCENTOS="TencentOS"
SYSTEM_OPENEULER="openEuler"
SYSTEM_ANOLISOS="Anolis"
SYSTEM_OPENKYLIN="openKylin"
SYSTEM_OPENSUSE="openSUSE"
SYSTEM_ARCH="Arch"
SYSTEM_MANJARO="Manjaro"
SYSTEM_ALPINE="Alpine"
SYSTEM_GENTOO="Gentoo"
SYSTEM_NIXOS="NixOS"
## 定义系统版本文件
File_LinuxRelease=/etc/os-release
File_RedHatRelease=/etc/redhat-release
File_DebianVersion=/etc/debian_version
File_ArmbianRelease=/etc/armbian-release
File_RaspberryPiOSRelease=/etc/rpi-issue
File_openEulerRelease=/etc/openEuler-release
File_HuaweiCloudEulerOSRelease=/etc/hce-release
File_OpenCloudOSRelease=/etc/opencloudos-release
File_TencentOSServerRelease=/etc/tlinux-release
File_AnolisOSRelease=/etc/anolis-release
File_AlibabaCloudLinuxRelease=/etc/alinux-release
File_OracleLinuxRelease=/etc/oracle-release
File_ArchLinuxRelease=/etc/arch-release
File_ManjaroRelease=/etc/manjaro-release
File_AlpineRelease=/etc/alpine-release
File_GentooRelease=/etc/gentoo-release
File_openKylinVersion=/etc/kylin-version/kylin-system-version.conf
File_ProxmoxVersion=/etc/pve/.version
## 定义软件源相关文件或目录
Dir_AptAdditionalSources=/etc/apt/sources.list.d
Dir_AptAdditionalSourcesBackup=$Dir_AptAdditionalSources.bak
Dir_YumRepos=/etc/yum.repos.d
Dir_YumReposBackup=$Dir_YumRepos.bak
Dir_ZYppRepos=/etc/zypp/repos.d
Dir_ZYppReposBackup=$Dir_ZYppRepos.bak
Dir_GentooReposConf=/etc/portage/repos.conf
Dir_NixConfig=/etc/nix
File_AptSourceList=/etc/apt/sources.list
File_AptSourceListBackup=$File_AptSourceList.bak
File_DebianSources=$Dir_AptAdditionalSources/debian.sources
File_DebianSourcesBackup=$File_DebianSources.bak
File_UbuntuSources=$Dir_AptAdditionalSources/ubuntu.sources
File_UbuntuSourcesBackup=$File_UbuntuSources.bak
File_ArmbianSourceList=$Dir_AptAdditionalSources/armbian.list
File_ArmbianSourceListBackup=$File_ArmbianSourceList.bak
File_ProxmoxSourceList=$Dir_AptAdditionalSources/pve-no-subscription.list
File_ProxmoxSourceListBackup=$File_ProxmoxSourceList.bak
File_ProxmoxAPLInfo=/usr/share/perl5/PVE/APLInfo.pm
File_LinuxMintSourceList=$Dir_AptAdditionalSources/official-package-repositories.list
File_LinuxMintSourceListBackup=$File_LinuxMintSourceList.bak
File_RaspberryPiSourceList=$Dir_AptAdditionalSources/raspi.list
File_RaspberryPiSourceListBackup=$File_RaspberryPiSourceList.bak
File_PacmanMirrorList=/etc/pacman.d/mirrorlist
File_PacmanMirrorListBackup=$File_PacmanMirrorList.bak
File_AlpineRepositories=/etc/apk/repositories
File_AlpineRepositoriesBackup=$File_AlpineRepositories.bak
File_GentooMakeConf=/etc/portage/make.conf
File_GentooMakeConfBackup=$File_GentooMakeConf.bak
File_GentooReposConf=/etc/portage/repos.conf/gentoo.conf
File_GentooReposConfBackup=$File_GentooReposConf.bak
File_NixConf=/etc/nix/nix.conf
File_NixConfBackup=$File_NixConf.bak
## 定义颜色和样式变量
RED='\033[31m'
GREEN='\033[32m'
YELLOW='\033[33m'
BLUE='\033[34m'
PURPLE='\033[35m'
AZURE='\033[36m'
PLAIN='\033[0m'
BOLD='\033[1m'
SUCCESS="\033[1;32m✔${PLAIN}"
COMPLETE="\033[1;32m✔${PLAIN}"
WARN="\033[1;43m 警告 ${PLAIN}"
ERROR="\033[1;31m✘${PLAIN}"
FAIL="\033[1;31m✘${PLAIN}"
TIP="\033[1;44m 提示 ${PLAIN}"
WORKING="\033[1;36m◉${PLAIN}"
function main() {
permission_judgment
collect_system_info
check_command_options
run_start
choose_mirrors
choose_protocol
choose_install_epel_packages
backup_original_mirrors
remove_original_mirrors
change_mirrors_main
upgrade_software
run_end
}
function handle_command_options() {
while [ $# -gt 0 ]; do
case "$1" in
## 海外模式
--abroad)
USE_ABROAD_SOURCE="true"
;;
## 中国大陆教育网模式
--edu)
USE_EDU_SOURCE="true"
;;
## 指定软件源地址
--source)
if [ "$2" ]; then
echo "$2" | grep -Eq "\(|\)|\[|\]|\{|\}"
if [ $? -eq 0 ]; then
command_error "$2" "$(msg "error.cmd.options.validAddress")"
else
SOURCE="$(echo "$2" | sed -e 's,^http[s]\?://,,g' -e 's,/$,,')"
shift
fi
else
command_error "$1" "$(msg "error.cmd.options.sourceAddress")"
fi
;;
--source-epel)
if [ "$2" ]; then
echo "$2" | grep -Eq "\(|\)|\[|\]|\{|\}"
if [ $? -eq 0 ]; then
command_error "$2" "$(msg "error.cmd.options.validAddress")"
else
SOURCE_EPEL="$(echo "$2" | sed -e 's,^http[s]\?://,,g' -e 's,/$,,')"
shift
fi
else
command_error "$1" "$(msg "error.cmd.options.sourceAddress")"
fi
;;
--source-security)
if [ "$2" ]; then
echo "$2" | grep -Eq "\(|\)|\[|\]|\{|\}"
if [ $? -eq 0 ]; then
command_error "$2" "$(msg "error.cmd.options.validAddress")"
else
SOURCE_SECURITY="$(echo "$2" | sed -e 's,^http[s]\?://,,g' -e 's,/$,,')"
shift
fi
else
command_error "$1" "$(msg "error.cmd.options.sourceAddress")"
fi
;;
--source-vault)
if [ "$2" ]; then
echo "$2" | grep -Eq "\(|\)|\[|\]|\{|\}"
if [ $? -eq 0 ]; then
command_error "$2" "$(msg "error.cmd.options.validAddress")"
else
SOURCE_VAULT="$(echo "$2" | sed -e 's,^http[s]\?://,,g' -e 's,/$,,')"
shift
fi
else
command_error "$1" "$(msg "error.cmd.options.sourceAddress")"
fi
;;
--source-portage)
if [ "$2" ]; then
echo "$2" | grep -Eq "\(|\)|\[|\]|\{|\}"
if [ $? -eq 0 ]; then
command_error "$2" "$(msg "error.cmd.options.validAddress")"
else
SOURCE_PORTAGE="$(echo "$2" | sed -e 's,^http[s]\?://,,g' -e 's,/$,,')"
shift
fi
else
command_error "$1" "$(msg "error.cmd.options.sourceAddress")"
fi
;;
--source-base-system)
if [ "$2" ]; then
echo "$2" | grep -Eq "\(|\)|\[|\]|\{|\}"
if [ $? -eq 0 ]; then
command_error "$2" "$(msg "error.cmd.options.validAddress")"
else
SOURCE_BASE_SYSTEM="$(echo "$2" | sed -e 's,^http[s]\?://,,g' -e 's,/$,,')"
shift
fi
else
command_error "$1" "$(msg "error.cmd.options.sourceAddress")"
fi
;;
## 指定软件源仓库
--branch)
if [ "$2" ]; then
SOURCE_BRANCH="$2"
shift
else
command_error "$1" "$(msg "error.cmd.options.sourceRepository")"
fi
;;
--branch-epel)
if [ "$2" ]; then
SOURCE_EPEL_BRANCH="$2"
shift
else
command_error "$1" "$(msg "error.cmd.options.sourceRepository")"
fi
;;
--branch-security)
if [ "$2" ]; then
SOURCE_SECURITY_BRANCH="$2"
shift
else
command_error "$1" "$(msg "error.cmd.options.sourceRepository")"
fi
;;
--branch-vault)
if [ "$2" ]; then
SOURCE_VAULT_BRANCH="$2"
shift
else
command_error "$1" "$(msg "error.cmd.options.sourceRepository")"
fi
;;
--branch-portage)
if [ "$2" ]; then
SOURCE_PORTAGE_BRANCH="$2"
shift
else
command_error "$1" "$(msg "error.cmd.options.sourceRepository")"
fi
;;
--branch-base-system)
if [ "$2" ]; then
SOURCE_BASE_SYSTEM_BRANCH="$2"
shift
else
command_error "$1" "$(msg "error.cmd.options.sourceRepository")"
fi
;;
## 指定 Debian 系操作系统的版本代号
--codename)
if [ "$2" ]; then
DEBIAN_CODENAME="$2"
shift
else
command_error "$1" "$(msg "error.cmd.options.codename")"
fi
;;
## 使用官方源
--use-official-source)
if [ "$2" ]; then
case "$2" in
[Tt]rue | [Ff]alse)
USE_OFFICIAL_SOURCE="${2,,}"
shift
;;
*)
command_error "$2" "$(msg "error.cmd.options.boolean")"
;;
esac
else
command_error "$1" "$(msg "error.cmd.options.boolean")"
fi
;;
## EPEL 使用 官方源
--use-official-source-epel)
if [ "$2" ]; then
case "$2" in
[Tt]rue | [Ff]alse)
USE_OFFICIAL_SOURCE_EPEL="${2,,}"
shift
;;
*)
command_error "$2" "$(msg "error.cmd.options.boolean")"
;;
esac
else
command_error "$1" "$(msg "error.cmd.options.boolean")"
fi
;;
## 使用内网地址
--intranet | --use-intranet-source)
if [ "$2" ]; then
case "$2" in
[Tt]rue | [Ff]alse)
USE_INTRANET_SOURCE="${2,,}"
shift
;;
*)
command_error "$2" "$(msg "error.cmd.options.boolean")"
;;
esac
else
command_error "$1" "$(msg "error.cmd.options.boolean")"
fi
;;
## Web 协议(HTTP/HTTPS)
--protocol | --web-protocol)
if [ "$2" ]; then
case "$2" in
http | https | HTTP | HTTPS)
WEB_PROTOCOL="${2,,}"
shift
;;
*)
command_error "$2" "$(msg "error.cmd.options.protocol")"
;;
esac
else
ocommand_error "$1" "$(msg "error.cmd.options.needProtocol")"
fi
;;
## 安装 EPEL 附加软件包
--install-epel)
if [ "$2" ]; then
case "$2" in
[Tt]rue | [Ff]alse)
INSTALL_EPEL="${2,,}"
shift
;;
*)
command_error "$2" "$(msg "error.cmd.options.boolean")"
;;
esac
else
command_error "$1" "$(msg "error.cmd.options.boolean")"
fi
;;
--only-epel)
ONLY_EPEL="true"
INSTALL_EPEL="true"
;;
## 备份原有软件源
--backup)
if [ "$2" ]; then
case "$2" in
[Tt]rue | [Ff]alse)
BACKUP="${2,,}"
shift
;;
*)
command_error "$2" "$(msg "error.cmd.options.boolean")"
;;
esac
else
command_error "$1" "$(msg "error.cmd.options.boolean")"
fi
;;
## 忽略覆盖备份提示
--ignore-backup-tips)
IGNORE_BACKUP_TIPS="true"
;;
## 更新软件包
--upgrade-software | --updata-software)
if [ "$2" ]; then
case "$2" in
[Tt]rue | [Ff]alse)
UPGRADE_SOFTWARE="${2,,}"
shift
;;
*)
command_error "$2" "$(msg "error.cmd.options.boolean")"
;;
esac
else
command_error "$1" "$(msg "error.cmd.options.boolean")"
fi
;;
## 在更新软件包后清理下载缓存
--clean-cache)
if [ "$2" ]; then
case "$2" in
[Tt]rue | [Ff]alse)
CLEAN_CACHE="${2,,}"
shift
;;
*)
command_error "$2" "$(msg "error.cmd.options.boolean")"
;;
esac
else
command_error "$1" "$(msg "error.cmd.options.boolean")"
fi
;;
## Locale
--lang)
if [ "$2" ]; then
local lang_norm="${2//_/-}"
lang_norm="${lang_norm,,}"
case "$lang_norm" in
zh | zh-cn | zh-hans | zh-hans-*)
init_msg_pack "zh-hans"
shift
;;
zh-hant | zh-hant-* | zh-tw | zh-hk)
init_msg_pack "zh-hant"
shift
;;
en | en-us | en-*)
init_msg_pack "en"
shift
;;
auto)
choose_display_language
shift
;;
*)
command_error "$2" "$(msg "error.cmd.options.validLangKey")"
;;
esac
else
command_error "$1" "$(msg "error.cmd.options.langKey")"
fi
;;
--zh | --zh-[Cc][Nn])
init_msg_pack "zh-hans"
;;
--en | --en-[Uu][Ss])
init_msg_pack "en"
;;
--zh-[Hh]an[st])
init_msg_pack "$1"
;;
## 清除屏幕上的所有内容
--clean-screen)
if [ "$2" ]; then
case "$2" in
[Tt]rue | [Ff]alse)
CLEAN_SCREEN="${2,,}"
shift
;;
*)
command_error "$2" "$(msg "error.cmd.options.boolean")"
;;
esac
else
command_error "$1" "$(msg "error.cmd.options.boolean")"
fi
;;
## 打印源文件修改前后差异
--print-diff)
PRINT_DIFF="true"
;;
## 纯净模式
--pure-mode)
PURE_MODE="true"
;;
## 命令帮助
--help)
echo -e "\n$(msg "commands.help" "https://github.com/SuperManito/LinuxMirrors/issues")\n"
exit
;;
*)
command_error "$1"
;;
esac
shift
done
## 设置部分功能的默认值
ONLY_EPEL="${ONLY_EPEL:-"false"}"
BACKUP="${BACKUP:-"true"}"
USE_OFFICIAL_SOURCE="${USE_OFFICIAL_SOURCE:-"false"}"
IGNORE_BACKUP_TIPS="${IGNORE_BACKUP_TIPS:-"false"}"
PRINT_DIFF="${PRINT_DIFF:-"false"}"
PURE_MODE="${PURE_MODE:-"false"}"
}
function run_start() {
if [ -z "${CLEAN_SCREEN}" ]; then
[ -z "${SOURCE}" ] && clear
elif [ "${CLEAN_SCREEN}" == "true" ]; then
clear
fi
if [[ "${PURE_MODE}" == "true" ]]; then
return
fi
local system_name="${SYSTEM_PRETTY_NAME:-"${SYSTEM_NAME} ${SYSTEM_VERSION_ID}"}"
local arch="${DEVICE_ARCH}"
local date_time="$(date "+%Y-%m-%d %H:%M")"
local time_zone="$(timedatectl status 2>/dev/null | grep "Time zone" | awk -F ':' '{print$2}' | awk -F ' ' '{print$1}')"
echo -e "+-----------------------------------+"
echo -e "| \033[0;1;35;95m⡇\033[0m \033[0;1;33;93m⠄\033[0m \033[0;1;32;92m⣀⡀\033[0m \033[0;1;36;96m⡀\033[0;1;34;94m⢀\033[0m \033[0;1;35;95m⡀⢀\033[0m \033[0;1;31;91m⡷\033[0;1;33;93m⢾\033[0m \033[0;1;32;92m⠄\033[0m \033[0;1;36;96m⡀⣀\033[0m \033[0;1;34;94m⡀\033[0;1;35;95m⣀\033[0m \033[0;1;31;91m⢀⡀\033[0m \033[0;1;33;93m⡀\033[0;1;32;92m⣀\033[0m \033[0;1;36;96m⢀⣀\033[0m |"
echo -e "| \033[0;1;31;91m⠧\033[0;1;33;93m⠤\033[0m \033[0;1;32;92m⠇\033[0m \033[0;1;36;96m⠇⠸\033[0m \033[0;1;34;94m⠣\033[0;1;35;95m⠼\033[0m \033[0;1;31;91m⠜⠣\033[0m \033[0;1;33;93m⠇\033[0;1;32;92m⠸\033[0m \033[0;1;36;96m⠇\033[0m \033[0;1;34;94m⠏\033[0m \033[0;1;35;95m⠏\033[0m \033[0;1;33;93m⠣⠜\033[0m \033[0;1;32;92m⠏\033[0m \033[0;1;34;94m⠭⠕\033[0m |"
echo -e "+-----------------------------------+"
echo -e "$(msg "start.welcome")"
echo -e ''
echo -e "$(msg "start.runtimeEnv") ${BLUE}${system_name} ${arch}${PLAIN}"
echo -e "$(msg "start.dateTime") ${BLUE}${date_time} ${time_zone}${PLAIN}"
sleep 1 >/dev/null 2>&1
}
function run_end() {
if [[ "${PURE_MODE}" == "true" ]]; then
echo ''
return
fi
echo -e "\n✨ $(msg "end.moreInfo") 👉 \033[3mhttps://linuxmirrors.cn\033[0m"
if [[ "${#SPONSOR_ADS[@]}" -gt 0 ]]; then
echo -e "\n\033[2m$(msg "end.sponsorAds")\033[0m"
for ad in "${SPONSOR_ADS[@]}"; do
sleep 0.1
echo -e " \033[2m${ad}\033[0m"
done
fi
echo -e "\n\033[3;1mPowered by \033[34mLinuxMirrors\033[0m\n"
}
function output_error() {
[ "$1" ] && echo -e "\n$ERROR $1\n"
exit 1
}
function command_error() {
local tmp_text="$(msg "error.cmd.options.needConfirm")"
if [[ "${2}" ]]; then
tmp_text="$(msg "error.cmd.options.needSpecify" "${2}")"
fi
output_error "$(msg "error.cmd.options.invalid" "${BLUE}$1${PLAIN}" "${tmp_text}")"
}
function unsupport_system_error() {
output_error "$(msg "error.unsupportSystem" "${1}")"
}
function input_error() {
echo -e "\n$WARN $(msg "error.input" "${1}")"
}
function command_exists() {
command -v "$@" &>/dev/null
}
function permission_judgment() {
if [ $UID -ne 0 ]; then
output_error "$(msg "error.needRoot")"
fi
}
function get_os_release_value() {
grep -E "^${1}=" $File_LinuxRelease | cut -d= -f2- | sed "s/[\'\"]//g"
}
function collect_system_info() {
if [ ! -s "${File_LinuxRelease}" ]; then
unsupport_system_error "$(msg "error.unknownSystem")"
fi
## 定义系统名称
SYSTEM_NAME="$(get_os_release_value NAME)"
SYSTEM_PRETTY_NAME="$(get_os_release_value PRETTY_NAME)"
## 定义系统版本号
SYSTEM_VERSION_ID="$(get_os_release_value VERSION_ID)"
SYSTEM_VERSION_ID_MAJOR="${SYSTEM_VERSION_ID%.*}"
SYSTEM_VERSION_ID_MINOR="${SYSTEM_VERSION_ID#*.}"
## 定义系统ID
SYSTEM_ID="$(get_os_release_value ID)"
## 判定当前系统派系
if [ -s "${File_DebianVersion}" ]; then
SYSTEM_FACTIONS="${SYSTEM_DEBIAN}"
elif [ -s "${File_RedHatRelease}" ]; then
SYSTEM_FACTIONS="${SYSTEM_REDHAT}"
elif [ -s "${File_openEulerRelease}" ]; then
SYSTEM_FACTIONS="${SYSTEM_OPENEULER}"
elif [ -s "${File_OpenCloudOSRelease}" ]; then
SYSTEM_FACTIONS="${SYSTEM_OPENCLOUDOS}" # 自 9.0 版本起不再基于红帽
elif [ -s "${File_AnolisOSRelease}" ]; then
SYSTEM_FACTIONS="${SYSTEM_ANOLISOS}" # 自 8.8 版本起不再基于红帽
elif [ -s "${File_openKylinVersion}" ]; then
SYSTEM_FACTIONS="${SYSTEM_OPENKYLIN}"
elif [ -f "${File_ArchLinuxRelease}" ]; then
SYSTEM_FACTIONS="${SYSTEM_ARCH}"
elif [ -f "${File_AlpineRelease}" ]; then
SYSTEM_FACTIONS="${SYSTEM_ALPINE}"
elif [ -f "${File_GentooRelease}" ]; then
SYSTEM_FACTIONS="${SYSTEM_GENTOO}"
elif [[ "${SYSTEM_NAME}" == *"openSUSE"* ]]; then
SYSTEM_FACTIONS="${SYSTEM_OPENSUSE}"
elif [[ "${SYSTEM_NAME}" == *"NixOS"* ]]; then
SYSTEM_FACTIONS="${SYSTEM_NIXOS}"
else
unsupport_system_error "$(msg "error.unknownSystem")"
fi
## 判定系统类型、版本、版本号
case "${SYSTEM_FACTIONS}" in
"${SYSTEM_DEBIAN}" | "${SYSTEM_OPENKYLIN}")
if command_exists lsb_release; then
SYSTEM_JUDGMENT="$(lsb_release -is)"
SYSTEM_VERSION_CODENAME="${DEBIAN_CODENAME:-"$(lsb_release -cs)"}"
else
## https://codeberg.org/gioele/lsb-release-minimal
SYSTEM_JUDGMENT="${SYSTEM_ID^}"
if [ "${SYSTEM_NAME}" ]; then
if [[ "${SYSTEM_ID,,}" == "${SYSTEM_NAME,,}" ]]; then
SYSTEM_JUDGMENT="${SYSTEM_NAME}"
fi
fi
SYSTEM_VERSION_CODENAME="${DEBIAN_CODENAME:-"$(get_os_release_value VERSION_CODENAME)"}"
fi
## Raspberry Pi OS 判定
if [[ "${SYSTEM_FACTIONS}" == "${SYSTEM_DEBIAN}" ]] && [ -s "${File_RaspberryPiOSRelease}" ]; then
SYSTEM_JUDGMENT="${SYSTEM_RASPBERRY_PI_OS}"
SYSTEM_PRETTY_NAME="${SYSTEM_RASPBERRY_PI_OS}"
fi
## 针对特定系统的判定
if [[ "${SYSTEM_JUDGMENT}" == "${SYSTEM_DEBIAN}" ]]; then
## 尚未正式发布的版本
if [[ -z "${SYSTEM_VERSION_ID}" && "${SYSTEM_VERSION_CODENAME}" == "trixie" ]]; then
SYSTEM_VERSION_ID="13"
SYSTEM_VERSION_ID_MAJOR="${SYSTEM_VERSION_ID%.*}"
SYSTEM_VERSION_ID_MINOR="${SYSTEM_VERSION_ID#*.}"
fi
## 是否使用 DEB822 格式
if [[ "${SYSTEM_VERSION_ID_MAJOR}" && "${SYSTEM_VERSION_ID_MAJOR}" -ge 13 ]]; then
USE_DEB822_FORMAT="true"
fi
fi
if [[ "${SYSTEM_JUDGMENT}" == "${SYSTEM_UBUNTU}" ]]; then
## 是否使用 DEB822 格式
if [[ "${SYSTEM_VERSION_ID_MAJOR}" && "${SYSTEM_VERSION_ID_MAJOR}" -ge 24 ]]; then
USE_DEB822_FORMAT="true"
fi
fi
;;
"${SYSTEM_REDHAT}")
SYSTEM_JUDGMENT="$(awk '{printf $1}' $File_RedHatRelease)"
## 针对特定系统的判定
# Red Hat Enterprise Linux
grep -q "${SYSTEM_RHEL}" $File_RedHatRelease && SYSTEM_JUDGMENT="${SYSTEM_RHEL}"
# CentOS Stream
grep -q "${SYSTEM_CENTOS_STREAM}" $File_RedHatRelease && SYSTEM_JUDGMENT="${SYSTEM_CENTOS_STREAM}"
# Oracle Linux
[ -s "${File_OracleLinuxRelease}" ] && SYSTEM_JUDGMENT="${SYSTEM_ORACLE}"
;;
"${SYSTEM_ARCH}")
if [ -f "${File_ManjaroRelease}" ]; then
SYSTEM_JUDGMENT="${SYSTEM_MANJARO}"
else
SYSTEM_JUDGMENT="${SYSTEM_FACTIONS}"
fi
;;
*)
SYSTEM_JUDGMENT="${SYSTEM_FACTIONS}"
;;
esac
## 判断系统及版本是否适配
local is_supported="true"
case "${SYSTEM_JUDGMENT}" in
"${SYSTEM_DEBIAN}")
if [[ "${SYSTEM_VERSION_ID_MAJOR}" =~ ^[0-9]{1,2}$ ]]; then
if [[ "${SYSTEM_VERSION_ID_MAJOR}" -lt 8 || "${SYSTEM_VERSION_ID_MAJOR}" -gt 13 ]]; then
is_supported="false"
fi
fi
if [[ "${SYSTEM_VERSION_CODENAME}" == "sid" ]]; then
if [[ "${PURE_MODE}" != "true" ]]; then
echo -e "\n${WARN} $(msg "warn.unstableDebian" "${BLUE}unstable(sid)${PLAIN}")\n"
fi
fi
;;
"${SYSTEM_UBUNTU}")
if [[ "${SYSTEM_VERSION_ID_MAJOR}" -lt 14 || "${SYSTEM_VERSION_ID_MAJOR}" -gt 25 ]]; then
is_supported="false"
fi
;;
"${SYSTEM_LINUX_MINT}")
if [[ "${SYSTEM_VERSION_ID_MAJOR}" != 19 && "${SYSTEM_VERSION_ID_MAJOR}" != 2[0-2] && "${SYSTEM_VERSION_ID_MAJOR}" != 6 ]]; then
is_supported="false"
fi
;;
"${SYSTEM_RHEL}")
if [[ "${SYSTEM_VERSION_ID_MAJOR}" != [7-9] && "${SYSTEM_VERSION_ID_MAJOR}" != 10 ]]; then
is_supported="false"
fi
;;
"${SYSTEM_CENTOS}")
if [[ "${SYSTEM_VERSION_ID_MAJOR}" != [7-8] ]]; then
is_supported="false"
fi
;;
"${SYSTEM_CENTOS_STREAM}" | "${SYSTEM_ROCKY}" | "${SYSTEM_ALMALINUX}" | "${SYSTEM_ORACLE}")
if [[ "${SYSTEM_VERSION_ID_MAJOR}" != [8-9] && "${SYSTEM_VERSION_ID_MAJOR}" != 10 ]]; then
is_supported="false"
fi
;;
"${SYSTEM_FEDORA}")
if [[ "${SYSTEM_VERSION_ID}" != [3-4][0-9] ]]; then
is_supported="false"
fi
;;
"${SYSTEM_OPENEULER}")
if [[ "${SYSTEM_VERSION_ID_MAJOR}" != 2[0-5] ]]; then
is_supported="false"
fi
;;
"${SYSTEM_OPENCLOUDOS}")
if [[ "${SYSTEM_VERSION_ID_MAJOR}" != [8-9] && "${SYSTEM_VERSION_ID_MAJOR}" != 23 ]] || [[ "${SYSTEM_VERSION_ID_MAJOR}" == 8 && "${SYSTEM_VERSION_ID_MINOR}" -lt 6 ]]; then
is_supported="false"
fi
;;
"${SYSTEM_ANOLISOS}")
if [[ "${SYSTEM_VERSION_ID_MAJOR}" != 8 && "${SYSTEM_VERSION_ID_MAJOR}" != 23 ]]; then
is_supported="false"
fi
;;
"${SYSTEM_OPENSUSE}")
case "${SYSTEM_ID}" in
"opensuse-leap")
if [[ "${SYSTEM_VERSION_ID_MAJOR}" != 1[5-6] ]]; then
is_supported="false"
fi
;;
"opensuse-tumbleweed") ;;
*)
is_supported="false"
;;
esac
;;
# 理论全部支持或不作判断
"${SYSTEM_KALI}" | "${SYSTEM_DEEPIN}" | "${SYSTEM_ZORIN}" | "${SYSTEM_RASPBERRY_PI_OS}" | "${SYSTEM_OPENKYLIN}") ;;
"${SYSTEM_ARCH}" | "${SYSTEM_MANJARO}" | "${SYSTEM_ALPINE}" | "${SYSTEM_GENTOO}" | "${SYSTEM_NIXOS}") ;;
*)
unsupport_system_error "$(msg "error.unknownVersion")"
;;
esac
if [[ "${is_supported}" == "false" ]]; then
unsupport_system_error "$(msg "error.unsupportVersion")"
fi
## 判定系统处理器架构
DEVICE_ARCH_RAW="$(uname -m)"
case "${DEVICE_ARCH_RAW}" in
x86_64)
DEVICE_ARCH="x86_64"
;;
aarch64)
DEVICE_ARCH="ARM64"
;;
armv8l)
DEVICE_ARCH="ARMv8_32"
;;
armv7l)
DEVICE_ARCH="ARMv7"
;;
armv6l)
DEVICE_ARCH="ARMv6"
;;
armv5tel)
DEVICE_ARCH="ARMv5"
;;
i686)
DEVICE_ARCH="x86_32"
;;
*)
DEVICE_ARCH="${DEVICE_ARCH_RAW}"
;;
esac
## 定义软件源仓库名称
if [[ -z "${SOURCE_BRANCH}" ]]; then
## 默认为系统名称小写,替换空格
SOURCE_BRANCH="${SYSTEM_JUDGMENT,,}"
SOURCE_BRANCH="${SOURCE_BRANCH// /-}"
## 处理特殊的仓库名称
case "${SYSTEM_JUDGMENT}" in
"${SYSTEM_DEBIAN}")
case "${SYSTEM_VERSION_ID_MAJOR}" in
8 | 9 | 10)
SOURCE_BRANCH="debian-archive/debian"
;;
*)
SOURCE_BRANCH="debian"
;;
esac
;;
"${SYSTEM_UBUNTU}" | "${SYSTEM_ZORIN}")
if [[ "${DEVICE_ARCH_RAW}" == "x86_64" || "${DEVICE_ARCH_RAW}" == *i?86* ]]; then
SOURCE_BRANCH="ubuntu"
else
SOURCE_BRANCH="ubuntu-ports"
fi
;;
"${SYSTEM_RASPBERRY_PI_OS}")
SOURCE_BRANCH="raspberrypi"
;;
"${SYSTEM_RHEL}")
case "${SYSTEM_VERSION_ID_MAJOR}" in
7 | 8)
if [[ "${DEVICE_ARCH_RAW}" == "x86_64" ]]; then
SOURCE_BRANCH="centos-vault"
else
SOURCE_BRANCH="centos-altarch"
fi
;;
*)
SOURCE_BRANCH="centos-stream" # 使用 CentOS Stream 仓库
;;
esac
;;
"${SYSTEM_CENTOS}")
if [[ "${DEVICE_ARCH_RAW}" == "x86_64" ]]; then
SOURCE_BRANCH="centos-vault"
else
SOURCE_BRANCH="centos-altarch"
fi
;;
"${SYSTEM_CENTOS_STREAM}" | "${SYSTEM_ORACLE}")
# 自 CentOS Stream 9 开始使用 centos-stream 仓库,旧版本使用 centos 仓库
case "${SYSTEM_VERSION_ID_MAJOR}" in