逻辑优化

This commit is contained in:
Super Manito
2025-07-18 23:26:41 +08:00
parent 649f3d5638
commit 01a2f9e912
11 changed files with 128 additions and 50 deletions

View File

@@ -134,8 +134,7 @@ mirror_list_abroad=(
)
## 配置需要区分公网地址和内网地址的软件源(不分地域)
# 配置方法:需要同时在两个数组变量中分别定义软件源地址,并且保证排列顺序一致
# 工作原理:当检测到用户所选择的软件源地址在 “软件源公网地址列表” 中时就会询问是否切换为内网地址,然后在 “软件源内网地址列表” 从相同的位置提取内网地址
# 需要同时在两个数组变量中分别定义软件源地址,并且保证排列顺序一致
# 软件源公网地址列表
mirror_list_extranet=(
"mirrors.aliyun.com"
@@ -843,7 +842,7 @@ function collect_system_info() {
fi
;;
"${SYSTEM_OPENEULER}")
if [[ "${SYSTEM_VERSION_ID_MAJOR}" != 2[1-5] ]]; then
if [[ "${SYSTEM_VERSION_ID_MAJOR}" != 2[0-5] ]]; then
is_supported="false"
fi
;;
@@ -6138,7 +6137,7 @@ gpgcheck=1
gpgkey=http://repo.openeuler.org/openEuler-version/source/RPM-GPG-KEY-openEuler
EOF
## 替换版本号
local version_name="$(cat $File_LinuxRelease | grep -E "^VERSION=" | awk -F '=' '{print$2}' | sed "s/[\'\"]//g; s/[()]/ /g; s/ / /g; s/^ //g; s/ $//g; s/ /-/g; s/_/-/g")"
local version_name="$(cat $File_LinuxRelease | grep -E "^VERSION=" | awk -F '=' '{print$2}' | sed 's/["()]//g; s/[_ ]\+/-/g; s/^-\+\|-\+$//g')"
sed -e "s|openEuler-version|openEuler-${version_name}|g" \
-i \
$Dir_YumRepos/openEuler.repo

View File

@@ -11,13 +11,15 @@ mirror_list_docker_ce=(
"阿里云@mirrors.aliyun.com/docker-ce"
"腾讯云@mirrors.tencent.com/docker-ce"
"华为云@mirrors.huaweicloud.com/docker-ce"
"微软 Azure 中国@mirror.azure.cn/docker-ce"
"网易@mirrors.163.com/docker-ce"
"火山引擎@mirrors.volces.com/docker"
"微软 Azure 中国@mirror.azure.cn/docker-ce"
"清华大学@mirrors.tuna.tsinghua.edu.cn/docker-ce"
"北京大学@mirrors.pku.edu.cn/docker-ce"
"浙江大学@mirrors.zju.edu.cn/docker-ce"
"南京大学@mirrors.nju.edu.cn/docker-ce"
"上海交通大学@mirror.sjtu.edu.cn/docker-ce"
"重庆邮电大学@mirrors.cqupt.edu.cn/docker-ce"
"中国科学技术大学@mirrors.ustc.edu.cn/docker-ce"
"中国科学院软件研究所@mirror.iscas.ac.cn/docker-ce"
"官方@download.docker.com"
@@ -58,6 +60,23 @@ mirror_list_registry=(
"官方 Docker Hub@registry.hub.docker.com"
)
## 配置需要区分公网地址和内网地址的软件源(不分地域)
# 需要同时在两个数组变量中分别定义软件源地址,并且保证排列顺序一致
# 软件源公网地址列表
mirror_list_extranet=(
"mirrors.aliyun.com/docker-ce"
"mirrors.tencent.com/docker-ce"
"mirrors.huaweicloud.com/docker-ce"
"mirrors.volces.com/docker-ce"
)
# 软件源内网地址列表
mirror_list_intranet=(
"mirrors.cloud.aliyuncs.com/docker-ce"
"mirrors.tencentyun.com/docker-ce"
"mirrors.myhuaweicloud.com/docker-ce"
"mirrors.ivolces.com/docker-ce"
)
## 赞助商广告
SPONSOR_ADS=(
"1Panel · Linux 面板|极简运维 ➜ \033[3mhttps://1panel.cn\033[0m"
@@ -172,18 +191,19 @@ function handle_command_options() {
echo -e "
命令选项(名称/含义/值)
--source 指定 Docker CE 源地址(域名或IP) 地址
--source-registry 指定镜像仓库地址(域名或IP) 地址
--branch 指定 Docker CE 源仓库(路径) 仓库名
--codename 指定 Debian 系操作系统的版本代号 代号名称
--designated-version 指定 Docker CE 安装版本 版本号
--protocol 指定 Docker CE 源的 WEB 协议 http 或 https
--install-latest 是否安装最新版本的 Docker Engine true 或 false
--close-firewall 是否关闭防火墙 true 或 false
--clean-screen 是否在运行前清除屏幕上的所有内容 true 或 false
--only-registry 仅更换镜像仓库模式 无
--ignore-backup-tips 忽略覆盖备份提示
--pure-mode 纯净模式,精简打印内容
--source 指定 Docker CE 源地址(域名或IP) 地址
--source-registry 指定镜像仓库地址(域名或IP) 地址
--branch 指定 Docker CE 源仓库(路径) 仓库名
--codename 指定 Debian 系操作系统的版本代号 代号名称
--designated-version 指定 Docker CE 安装版本 版本号
--protocol 指定 Docker CE 源的 WEB 协议 http 或 https
--use-intranet-source 是否优先使用内网 Docker CE 软件源地址 true 或 false
--install-latest 是否安装最新版本的 Docker Engine true 或 false
--close-firewall 是否关闭防火墙 true 或 false
--clean-screen 是否在运行前清除屏幕上的所有内容 true 或 false
--only-registry 仅更换镜像仓库模式
--ignore-backup-tips 忽略覆盖备份提示
--pure-mode 纯净模式,精简打印内容 无
问题报告 https://github.com/SuperManito/LinuxMirrors/issues
"
@@ -268,6 +288,22 @@ function handle_command_options() {
ocommand_error "$1" " WEB 协议 (http/https) "
fi
;;
## 使用内网地址
--use-intranet-source)
if [ "$2" ]; then
case "$2" in
[Tt]rue | [Ff]alse)
USE_INTRANET_SOURCE="${2,,}"
shift
;;
*)
command_error "$2" " true 或 false "
;;
esac
else
command_error "$1" " true 或 false "
fi
;;
## 安装最新版本
--install-latest | --install-latested)
if [ "$2" ]; then
@@ -432,16 +468,8 @@ function collect_system_info() {
elif [ -s "${File_openEulerRelease}" ]; then
SYSTEM_FACTIONS="${SYSTEM_OPENEULER}"
elif [ -s "${File_OpenCloudOSRelease}" ]; then
# 拦截 OpenCloudOS 9 及以上版本,不支持从 Docker 官方仓库安装
if [[ "${SYSTEM_VERSION_ID_MAJOR}" -ge 9 ]]; then
[[ "${ONLY_REGISTRY}" != "true" ]] && unsupport_system_error "OpenCloudOS 9" "dnf install -y docker\nsystemctl enable --now docker"
fi
SYSTEM_FACTIONS="${SYSTEM_OPENCLOUDOS}" # 自 9.0 版本起不再基于红帽
elif [ -s "${File_AnolisOSRelease}" ]; then
# 拦截 Anolis OS 8.8 及以上版本,不支持从 Docker 官方仓库安装23 版本支持
if [[ "${SYSTEM_VERSION_ID_MAJOR}" == 8 ]]; then
[[ "${ONLY_REGISTRY}" != "true" ]] && unsupport_system_error "Anolis OS 8" "dnf install -y docker\nsystemctl enable --now docker"
fi
SYSTEM_FACTIONS="${SYSTEM_ANOLISOS}" # 自 8.8 版本起不再基于红帽
elif [ -s "${File_openKylinVersion}" ]; then
[[ "${ONLY_REGISTRY}" != "true" ]] && unsupport_system_error "openKylin" "apt-get install -y docker\nsystemctl enable --now docker"
@@ -476,10 +504,6 @@ function collect_system_info() {
;;
"${SYSTEM_REDHAT}")
SYSTEM_JUDGMENT="$(awk '{printf $1}' $File_RedHatRelease)"
# 拦截 Anolis OS 8.8 以下版本,不支持从 Docker 官方仓库安装
if [[ "${SYSTEM_JUDGMENT}" == "${SYSTEM_ANOLISOS}" ]]; then
[[ "${ONLY_REGISTRY}" != "true" ]] && unsupport_system_error "Anolis OS 8" "dnf install -y docker\nsystemctl enable --now docker"
fi
## 特殊系统判断
# Red Hat Enterprise Linux
grep -q "${SYSTEM_RHEL}" $File_RedHatRelease && SYSTEM_JUDGMENT="${SYSTEM_RHEL}"
@@ -640,6 +664,47 @@ function choose_mirrors() {
fi
}
## 选择使用软件源内网地址
function choose_use_intranet_address() {
local ask_text="默认使用软件源的公网地址,是否继续?"
local intranet_source
for ((i = 0; i < ${#mirror_list_extranet[@]}; i++)); do
if [[ "${SOURCE}" == "${mirror_list_extranet[i]}" ]]; then
intranet_source="${mirror_list_intranet[i]}"
ONLY_HTTP="true" # 强制使用 HTTP 协议
break
else
continue
fi
done
if [[ -z "${USE_INTRANET_SOURCE}" ]]; then
if [[ "${CAN_USE_ADVANCED_INTERACTIVE_SELECTION}" == "true" ]]; then
echo ''
interactive_select_boolean "${BOLD}${ask_text}${PLAIN}"
if [[ "${_SELECT_RESULT}" == "false" ]]; then
SOURCE="${intranet_source}"
[[ "${PURE_MODE}" != "true" ]] && echo -e "\n$WARN 已切换至内网专用地址,仅限在特定环境下使用!"
fi
else
local CHOICE="$(echo -e "\n${BOLD}└─ ${ask_text} [Y/n] ${PLAIN}")"
read -rp "${CHOICE}" INPUT
[[ -z "${INPUT}" ]] && INPUT=Y
case "${INPUT}" in
[Yy] | [Yy][Ee][Ss]) ;;
[Nn] | [Nn][Oo])
SOURCE="${intranet_source}"
[[ "${PURE_MODE}" != "true" ]] && echo -e "\n$WARN 已切换至内网专用地址,仅限在特定环境下使用!"
;;
*)
input_error "默认不使用内网地址"
;;
esac
fi
elif [[ "${USE_INTRANET_SOURCE}" == "true" ]]; then
SOURCE="${intranet_source}"
fi
}
function print_title() {
local system_name="${SYSTEM_PRETTY_NAME:-"${SYSTEM_NAME} ${SYSTEM_VERSION_ID}"}"
local arch="${DEVICE_ARCH}"
@@ -685,6 +750,11 @@ function choose_mirrors() {
fi
fi
## 选择软件源内网地址
if [[ "${mirror_list_extranet[*]}" =~ (^|[^[:alpha:]])"${SOURCE}"([^[:alpha:]]|$) ]]; then
choose_use_intranet_address
fi
if [[ -z "${SOURCE_REGISTRY}" ]]; then
mirror_list_name="mirror_list_registry"
if [[ "${CAN_USE_ADVANCED_INTERACTIVE_SELECTION}" == "true" ]]; then
@@ -882,7 +952,7 @@ function configure_docker_ce_mirror() {
apt-key del 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88 >/dev/null 2>&1 # 删除旧的密钥
[ -f "${file_keyring}" ] && rm -rf $file_keyring
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://${SOURCE}/linux/${SOURCE_BRANCH}/gpg -o $file_keyring >/dev/null
curl -fsSL "${WEB_PROTOCOL}://${SOURCE}/linux/${SOURCE_BRANCH}/gpg" -o $file_keyring >/dev/null
if [ $? -ne 0 ]; then
output_error "GPG 密钥下载失败,请检查网络或更换 Docker CE 软件源后重试!"
fi
@@ -913,8 +983,13 @@ function configure_docker_ce_mirror() {
target_version="${SYSTEM_VERSION_ID_MAJOR}"
;;
*)
## 目前红帽系衍生系统还没有普及 10 版本
target_version="9" # 使用较新的版本
target_version="8" # 注部分系统使用9版本分支会有兼容性问题
# 适配国产系统
if [[ "${SYSTEM_JUDGMENT}" != "${SYSTEM_OPENEULER}" ]] && [[ "${SYSTEM_VERSION_ID_MAJOR}" == 23 ]]; then
target_version="9"
elif [[ "${SYSTEM_JUDGMENT}" == "${SYSTEM_OPENEULER}" ]] && [[ "${SYSTEM_VERSION_ID_MAJOR}" -ge 22 ]]; then
target_version="9"
fi
;;
esac
sed -i "s|\$releasever|${target_version}|g" $Dir_YumRepos/docker-ce.repo

View File

@@ -88,7 +88,7 @@
</tr>
<tr>
<td><a href="https://www.openeuler.org/zh" target="_blank"><sub><img src="/docs/assets/images/icon/openeuler.ico" width="16" height="16"></sub></a>&nbsp;openEuler</td>
<td align="center">21 ~ 25</td>
<td align="center">20 ~ 25</td>
</tr>
<tr>
<td><a href="https://www.opencloudos.org" target="_blank"><sub><img src="/docs/assets/images/icon/opencloudos.png" width="16" height="16"></sub></a>&nbsp;OpenCloudOS</td>

View File

@@ -88,7 +88,7 @@
</tr>
<tr>
<td><a href="https://www.openeuler.org/zh" target="_blank"><sub><img src="/docs/assets/images/icon/openeuler.ico" width="16" height="16"></sub></a>&nbsp;openEuler开源欧拉</td>
<td align="center">21 ~ 25</td>
<td align="center">20 ~ 25</td>
</tr>
<tr>
<td><a href="https://www.opencloudos.org" target="_blank"><sub><img src="/docs/assets/images/icon/opencloudos.png" width="16" height="16"></sub></a>&nbsp;OpenCloudOS鸥栖</td>

View File

@@ -88,7 +88,7 @@
</tr>
<tr>
<td><a href="https://www.openeuler.org/zh" target="_blank"><sub><img src="/docs/assets/images/icon/openeuler.ico" width="16" height="16"></sub></a>&nbsp;openEuler</td>
<td align="center">21 ~ 25</td>
<td align="center">20 ~ 25</td>
</tr>
<tr>
<td><a href="https://www.opencloudos.org" target="_blank"><sub><img src="/docs/assets/images/icon/opencloudos.png" width="16" height="16"></sub></a>&nbsp;OpenCloudOS</td>

View File

@@ -120,7 +120,7 @@ hide:
| <a href="https://rockylinux.org" title="https://rockylinux.org" target="_blank"><img src="/assets/images/icon/rocky-linux.svg" width="16" height="16" style="vertical-align: -0.2em"></a> **Rocky Linux** | _810_ |
| <a href="https://almalinux.org" title="https://almalinux.org" target="_blank"><img src="/assets/images/icon/almalinux.svg" width="16" height="16" style="vertical-align: -0.15em"></a> **AlmaLinux** | _810_ |
| <a href="https://www.oracle.com/linux" title="https://www.oracle.com/linux" target="_blank"><img src="/assets/images/icon/oracle-linux.png" width="16" height="16" style="vertical-align: -0.25em"></a> **Oracle Linux** :material-information-outline:{ title="Uses <code>CentOS Stream</code> mirrors" } | _810_ |
| <a href="https://www.openeuler.org/zh" title="https://www.openeuler.org/zh" target="_blank"><img src="/assets/images/icon/openeuler.ico" width="16" height="16" style="vertical-align: -0.2em"></a> **openEuler** | _2125_ |
| <a href="https://www.openeuler.org/zh" title="https://www.openeuler.org/zh" target="_blank"><img src="/assets/images/icon/openeuler.ico" width="16" height="16" style="vertical-align: -0.2em"></a> **openEuler** | _2025_ |
| <a href="https://www.opencloudos.org" title="https://www.opencloudos.org" target="_blank"><img src="/assets/images/icon/opencloudos.png" width="16" height="16" style="vertical-align: -0.25em"></a> **OpenCloudOS** | _8.69 / Stream 23_ |
| <a href="https://www.openkylin.top" title="https://www.openkylin.top" target="_blank"><img src="/assets/images/icon/openkylin.ico" width="16" height="16" style="vertical-align: -0.25em"></a> **openKylin** | _all_ |
| <a href="https://openanolis.cn" title="https://openanolis.cn" target="_blank"><img src="/assets/images/icon/anolis.png" width="16" height="16" style="vertical-align: -0.1em"></a> **Anolis OS** | _8 / 23_ |

View File

@@ -120,7 +120,7 @@ hide:
| <a href="https://rockylinux.org" title="https://rockylinux.org" target="_blank"><img src="/assets/images/icon/rocky-linux.svg" width="16" height="16" style="vertical-align: -0.2em"></a> **Rocky Linux** | _810_ |
| <a href="https://almalinux.org" title="https://almalinux.org" target="_blank"><img src="/assets/images/icon/almalinux.svg" width="16" height="16" style="vertical-align: -0.15em"></a> **AlmaLinux** | _810_ |
| <a href="https://www.oracle.com/linux" title="https://www.oracle.com/linux" target="_blank"><img src="/assets/images/icon/oracle-linux.png" width="16" height="16" style="vertical-align: -0.25em"></a> **Oracle Linux** :material-information-outline:{ title="使用 <code>CentOS Stream</code> 源" } | _810_ |
| <a href="https://www.openeuler.org/zh" title="https://www.openeuler.org/zh" target="_blank"><img src="/assets/images/icon/openeuler.ico" width="16" height="16" style="vertical-align: -0.2em"></a> **openEuler开源欧拉** | _2125_ |
| <a href="https://www.openeuler.org/zh" title="https://www.openeuler.org/zh" target="_blank"><img src="/assets/images/icon/openeuler.ico" width="16" height="16" style="vertical-align: -0.2em"></a> **openEuler开源欧拉** | _2025_ |
| <a href="https://www.opencloudos.org" title="https://www.opencloudos.org" target="_blank"><img src="/assets/images/icon/opencloudos.png" width="16" height="16" style="vertical-align: -0.25em"></a> **OpenCloudOS鸥栖** | _8.69 / Stream 23_ |
| <a href="https://www.openkylin.top" title="https://www.openkylin.top" target="_blank"><img src="/assets/images/icon/openkylin.ico" width="16" height="16" style="vertical-align: -0.25em"></a> **openKylin开放麒麟** | _all_ |
| <a href="https://openanolis.cn" title="https://openanolis.cn" target="_blank"><img src="/assets/images/icon/anolis.png" width="16" height="16" style="vertical-align: -0.1em"></a> **Anolis OS龙蜥** | _8 / 23_ |

View File

@@ -120,7 +120,7 @@ hide:
| <a href="https://rockylinux.org" title="https://rockylinux.org" target="_blank"><img src="/assets/images/icon/rocky-linux.svg" width="16" height="16" style="vertical-align: -0.2em"></a> **Rocky Linux** | _810_ |
| <a href="https://almalinux.org" title="https://almalinux.org" target="_blank"><img src="/assets/images/icon/almalinux.svg" width="16" height="16" style="vertical-align: -0.15em"></a> **AlmaLinux** | _810_ |
| <a href="https://www.oracle.com/linux" title="https://www.oracle.com/linux" target="_blank"><img src="/assets/images/icon/oracle-linux.png" width="16" height="16" style="vertical-align: -0.25em"></a> **Oracle Linux** :material-information-outline:{ title="使用 <code>CentOS Stream</code> 源" } | _810_ |
| <a href="https://www.openeuler.org/zh" title="https://www.openeuler.org/zh" target="_blank"><img src="/assets/images/icon/openeuler.ico" width="16" height="16" style="vertical-align: -0.2em"></a> **openEuler** | _2125_ |
| <a href="https://www.openeuler.org/zh" title="https://www.openeuler.org/zh" target="_blank"><img src="/assets/images/icon/openeuler.ico" width="16" height="16" style="vertical-align: -0.2em"></a> **openEuler** | _2025_ |
| <a href="https://www.opencloudos.org" title="https://www.opencloudos.org" target="_blank"><img src="/assets/images/icon/opencloudos.png" width="16" height="16" style="vertical-align: -0.25em"></a> **OpenCloudOS** | _8.69 / Stream 23_ |
| <a href="https://www.openkylin.top" title="https://www.openkylin.top" target="_blank"><img src="/assets/images/icon/openkylin.ico" width="16" height="16" style="vertical-align: -0.25em"></a> **openKylin** | _all_ |
| <a href="https://openanolis.cn" title="https://openanolis.cn" target="_blank"><img src="/assets/images/icon/anolis.png" width="16" height="16" style="vertical-align: -0.1em"></a> **Anolis OS** | _8 / 23_ |

View File

@@ -175,6 +175,7 @@ hide:
| `--codename` | Specify Debian-based OS codename | `codename` |
| `--designated-version` | Specify `Docker CE` installation version | `version (see docs below)` |
| `--protocol` | Specify WEB protocol for `Docker CE` source | `http` or `https` |
| `--use-intranet-source` | Prefer intranet Docker CE mirror address | `true` or `false` |
| `--install-latest` | Whether to install the latest Docker Engine | `true` or `false` |
| `--close-firewall` | Whether to disable the firewall | `true` or `false` |
| `--clean-screen` | Whether to clear the screen before running | `true` or `false` |

View File

@@ -183,18 +183,19 @@ hide:
命令选项(名称/含义/值)
--source 指定 Docker CE 源地址(域名或IP) 地址
--source-registry 指定镜像仓库地址(域名或IP) 地址
--branch 指定 Docker CE 源仓库(路径) 仓库名
--codename 指定 Debian 系操作系统的版本代号 代号名称
--designated-version 指定 Docker CE 安装版本 版本号
--protocol 指定 Docker CE 源的 WEB 协议 http 或 https
--install-latest 是否安装最新版本的 Docker Engine true 或 false
--close-firewall 是否关闭防火墙 true 或 false
--clean-screen 是否在运行前清除屏幕上的所有内容 true 或 false
--only-registry 仅更换镜像仓库模式 无
--ignore-backup-tips 忽略覆盖备份提示
--pure-mode 纯净模式,精简打印内容
--source 指定 Docker CE 源地址(域名或IP) 地址
--source-registry 指定镜像仓库地址(域名或IP) 地址
--branch 指定 Docker CE 源仓库(路径) 仓库名
--codename 指定 Debian 系操作系统的版本代号 代号名称
--designated-version 指定 Docker CE 安装版本 版本号
--protocol 指定 Docker CE 源的 WEB 协议 http 或 https
--use-intranet-source 是否优先使用内网 Docker CE 软件源地址 true 或 false
--install-latest 是否安装最新版本的 Docker Engine true 或 false
--close-firewall 是否关闭防火墙 true 或 false
--clean-screen 是否在运行前清除屏幕上的所有内容 true 或 false
--only-registry 仅更换镜像仓库模式
--ignore-backup-tips 忽略覆盖备份提示
--pure-mode 纯净模式,精简打印内容 无
```
| 名称 | 含义 | 选项值 |
@@ -205,6 +206,7 @@ hide:
| `--codename` | 指定 Debian 系操作系统的版本代号 | `代号名称` |
| `--designated-version` | 指定 `Docker CE` 安装版本 | `版本号(详见下方文档)` |
| `--protocol` | 指定 `Docker CE` 源的 WEB 协议 | `http` 或 `https` |
| `--use-intranet-source` | 是否优先使用内网 Docker CE 软件源地址 | `true` 或 `false` |
| `--install-latest` | 是否安装最新版本的 Docker Engine | `true` 或 `false` |
| `--close-firewall` | 是否关闭防火墙 | `true` 或 `false` |
| `--clean-screen` | 是否在运行前清除屏幕上的所有内容 | `true` 或 `false` |

View File

@@ -191,6 +191,7 @@ hide:
| `--codename` | 指定 Debian 係作業系統的版本代號 | `代號名稱` |
| `--designated-version` | 指定 `Docker CE` 安裝版本 | `版本號(詳見下方文檔)` |
| `--protocol` | 指定 `Docker CE` 源的 WEB 協議 | `http` 或 `https` |
| `--use-intranet-source` | 是否優先使用內部網路 Docker CE 軟體源位址 | `true` 或 `false` |
| `--install-latest` | 是否安裝最新版本的 Docker Engine | `true` 或 `false` |
| `--close-firewall` | 是否關閉防火牆 | `true` 或 `false` |
| `--clean-screen` | 是否在運行前清除螢幕上的所有內容 | `true` 或 `false` |