mirror of
https://gitee.com/SuperManito/LinuxMirrors
synced 2025-11-02 23:40:25 +08:00
优化
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
## Author: SuperManito
|
## Author: SuperManito
|
||||||
## Modified: 2025-10-20
|
## Modified: 2025-11-01
|
||||||
## License: MIT
|
## License: MIT
|
||||||
## GitHub: https://github.com/SuperManito/LinuxMirrors
|
## GitHub: https://github.com/SuperManito/LinuxMirrors
|
||||||
## Website: https://linuxmirrors.cn
|
## Website: https://linuxmirrors.cn
|
||||||
@@ -1088,7 +1088,7 @@ function check_command_options() {
|
|||||||
function choose_display_language() {
|
function choose_display_language() {
|
||||||
local result
|
local result
|
||||||
if command_exists tput; then
|
if command_exists tput; then
|
||||||
local lang_key_labels=()
|
local -a lang_key_labels=()
|
||||||
local language_text
|
local language_text
|
||||||
for ((i = 0; i < ${#MESSAGE_LANG_KEYS[@]}; i++)); do
|
for ((i = 0; i < ${#MESSAGE_LANG_KEYS[@]}; i++)); do
|
||||||
language_text="${MESSAGE_LANG_DISPLAY[${MESSAGE_LANG_KEYS[$i]}]}"
|
language_text="${MESSAGE_LANG_DISPLAY[${MESSAGE_LANG_KEYS[$i]}]}"
|
||||||
@@ -1136,22 +1136,21 @@ function choose_mirrors() {
|
|||||||
local text=$1
|
local text=$1
|
||||||
echo "${#text}"
|
echo "${#text}"
|
||||||
}
|
}
|
||||||
|
local -a list_arr=()
|
||||||
local list_arr=()
|
|
||||||
local list_arr_sum="$(eval echo \${#$1[@]})"
|
local list_arr_sum="$(eval echo \${#$1[@]})"
|
||||||
for ((i = 0; i < $list_arr_sum; i++)); do
|
for ((i = 0; i < $list_arr_sum; i++)); do
|
||||||
list_arr[$i]="$(eval echo \${$1[i]})"
|
list_arr[$i]="$(eval echo \${$1[i]})"
|
||||||
done
|
done
|
||||||
local name_width=${2:-"30"}
|
local name_width=${2:-"30"}
|
||||||
local __labels=()
|
local -a list_labels=()
|
||||||
if [[ "${3}" ]]; then
|
if [[ "${3}" ]]; then
|
||||||
eval "__labels=(\"\${${3}[@]}\")"
|
eval "list_labels=(\"\${${3}[@]}\")"
|
||||||
fi
|
fi
|
||||||
if command_exists printf; then
|
if command_exists printf; then
|
||||||
local tmp_uchar_1 tmp_uchar_2 tmp_uchar_3 tmp_uchar_4 tmp_default_length tmp_length tmp_unicode_length tmp_spaces_nums tmp_max_length
|
local tmp_uchar_1 tmp_uchar_2 tmp_uchar_3 tmp_uchar_4 tmp_default_length tmp_length tmp_unicode_length tmp_spaces_nums tmp_max_length
|
||||||
for ((i = 0; i < ${#list_arr[@]}; i++)); do
|
for ((i = 0; i < ${#list_arr[@]}; i++)); do
|
||||||
if [[ "${__labels[$i]}" ]]; then
|
if [[ "${list_labels[$i]}" ]]; then
|
||||||
tmp_name="${__labels[$i]}"
|
tmp_name="${list_labels[$i]}"
|
||||||
else
|
else
|
||||||
tmp_name="${list_arr[i]}"
|
tmp_name="${list_arr[i]}"
|
||||||
fi
|
fi
|
||||||
@@ -1176,8 +1175,8 @@ function choose_mirrors() {
|
|||||||
done
|
done
|
||||||
else
|
else
|
||||||
for ((i = 0; i < ${#list_arr[@]}; i++)); do
|
for ((i = 0; i < ${#list_arr[@]}; i++)); do
|
||||||
if [[ "${__labels[$i]}" ]]; then
|
if [[ "${list_labels[$i]}" ]]; then
|
||||||
tmp_name="${__labels[$i]}"
|
tmp_name="${list_labels[$i]}"
|
||||||
else
|
else
|
||||||
tmp_name="${list_arr[i]}"
|
tmp_name="${list_arr[i]}"
|
||||||
fi
|
fi
|
||||||
@@ -1248,7 +1247,7 @@ function choose_mirrors() {
|
|||||||
mirror_list_label_msg_prefix="mirrors.default"
|
mirror_list_label_msg_prefix="mirrors.default"
|
||||||
mirror_list_print_length=32
|
mirror_list_print_length=32
|
||||||
fi
|
fi
|
||||||
local mirror_list_labels=()
|
local -a mirror_list_labels=()
|
||||||
local mirror_list_length=$(eval "echo \${#${mirror_list_name}[@]}")
|
local mirror_list_length=$(eval "echo \${#${mirror_list_name}[@]}")
|
||||||
local label_msg_index label_msg_content
|
local label_msg_index label_msg_content
|
||||||
for ((i = 0; i < ${mirror_list_length}; i++)); do
|
for ((i = 0; i < ${mirror_list_length}; i++)); do
|
||||||
@@ -1611,7 +1610,7 @@ function remove_original_mirrors() {
|
|||||||
mkdir -p "${Dir_YumRepos}"
|
mkdir -p "${Dir_YumRepos}"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
local repo_patterns=()
|
local -a repo_patterns=()
|
||||||
if [[ "${SYSTEM_JUDGMENT}" == "${SYSTEM_FEDORA}" ]]; then
|
if [[ "${SYSTEM_JUDGMENT}" == "${SYSTEM_FEDORA}" ]]; then
|
||||||
repo_patterns=(
|
repo_patterns=(
|
||||||
"fedora.repo"
|
"fedora.repo"
|
||||||
@@ -1849,7 +1848,7 @@ function change_mirrors_main() {
|
|||||||
print_diff
|
print_diff
|
||||||
fi
|
fi
|
||||||
## 更新软件源
|
## 更新软件源
|
||||||
local commands=()
|
local -a commands=()
|
||||||
case "${SYSTEM_FACTIONS}" in
|
case "${SYSTEM_FACTIONS}" in
|
||||||
"${SYSTEM_DEBIAN}" | "${SYSTEM_OPENKYLIN}")
|
"${SYSTEM_DEBIAN}" | "${SYSTEM_OPENKYLIN}")
|
||||||
commands+=("apt-get update")
|
commands+=("apt-get update")
|
||||||
@@ -1972,7 +1971,7 @@ function upgrade_software() {
|
|||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
local commands=()
|
local -a commands=()
|
||||||
case "${SYSTEM_FACTIONS}" in
|
case "${SYSTEM_FACTIONS}" in
|
||||||
"${SYSTEM_DEBIAN}" | "${SYSTEM_OPENKYLIN}")
|
"${SYSTEM_DEBIAN}" | "${SYSTEM_OPENKYLIN}")
|
||||||
commands+=("apt-get upgrade -y")
|
commands+=("apt-get upgrade -y")
|
||||||
@@ -2793,7 +2792,7 @@ function change_mirrors_openSUSE() {
|
|||||||
|
|
||||||
## 修改源
|
## 修改源
|
||||||
cd $Dir_ZYppRepos
|
cd $Dir_ZYppRepos
|
||||||
local opensuse_repo_files=()
|
local -a opensuse_repo_files=()
|
||||||
case "${SYSTEM_ID}" in
|
case "${SYSTEM_ID}" in
|
||||||
opensuse-leap)
|
opensuse-leap)
|
||||||
case "${SYSTEM_VERSION_ID_MAJOR}" in
|
case "${SYSTEM_VERSION_ID_MAJOR}" in
|
||||||
@@ -3071,8 +3070,8 @@ function get_package_manager() {
|
|||||||
|
|
||||||
function interactive_select_list() {
|
function interactive_select_list() {
|
||||||
_SELECT_RESULT=""
|
_SELECT_RESULT=""
|
||||||
eval "local __values=(\"\${${1}[@]}\")"
|
eval "local -a __values=(\"\${${1}[@]}\")"
|
||||||
local __labels=()
|
local -a __labels=()
|
||||||
local message="${2}"
|
local message="${2}"
|
||||||
local selected=0
|
local selected=0
|
||||||
local start=0
|
local start=0
|
||||||
@@ -3306,7 +3305,7 @@ function animate_exec() {
|
|||||||
exit 130
|
exit 130
|
||||||
}
|
}
|
||||||
function make_temp_file() {
|
function make_temp_file() {
|
||||||
local temp_dirs=("." "/tmp")
|
local -a temp_dirs=("." "/tmp")
|
||||||
local tmp_file=""
|
local tmp_file=""
|
||||||
for dir in "${temp_dirs[@]}"; do
|
for dir in "${temp_dirs[@]}"; do
|
||||||
[[ ! -d "${dir}" || ! -w "${dir}" ]] && continue
|
[[ ! -d "${dir}" || ! -w "${dir}" ]] && continue
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
## Author: SuperManito
|
## Author: SuperManito
|
||||||
## Modified: 2025-10-23
|
## Modified: 2025-11-01
|
||||||
## License: MIT
|
## License: MIT
|
||||||
## GitHub: https://github.com/SuperManito/LinuxMirrors
|
## GitHub: https://github.com/SuperManito/LinuxMirrors
|
||||||
## Website: https://linuxmirrors.cn
|
## Website: https://linuxmirrors.cn
|
||||||
@@ -697,7 +697,7 @@ function collect_system_info() {
|
|||||||
function choose_display_language() {
|
function choose_display_language() {
|
||||||
local result
|
local result
|
||||||
if command_exists tput; then
|
if command_exists tput; then
|
||||||
local lang_key_labels=()
|
local -a lang_key_labels=()
|
||||||
local language_text
|
local language_text
|
||||||
for ((i = 0; i < ${#MESSAGE_LANG_KEYS[@]}; i++)); do
|
for ((i = 0; i < ${#MESSAGE_LANG_KEYS[@]}; i++)); do
|
||||||
language_text="${MESSAGE_LANG_DISPLAY[${MESSAGE_LANG_KEYS[$i]}]}"
|
language_text="${MESSAGE_LANG_DISPLAY[${MESSAGE_LANG_KEYS[$i]}]}"
|
||||||
@@ -744,14 +744,13 @@ function choose_mirrors() {
|
|||||||
local text=$1
|
local text=$1
|
||||||
echo "${#text}"
|
echo "${#text}"
|
||||||
}
|
}
|
||||||
|
local -a list_arr=()
|
||||||
local list_arr=()
|
|
||||||
local list_arr_sum="$(eval echo \${#$1[@]})"
|
local list_arr_sum="$(eval echo \${#$1[@]})"
|
||||||
for ((i = 0; i < $list_arr_sum; i++)); do
|
for ((i = 0; i < $list_arr_sum; i++)); do
|
||||||
list_arr[$i]="$(eval echo \${$1[i]})"
|
list_arr[$i]="$(eval echo \${$1[i]})"
|
||||||
done
|
done
|
||||||
local name_width=${2:-"30"}
|
local name_width=${2:-"30"}
|
||||||
local list_labels=()
|
local -a list_labels=()
|
||||||
if [[ "${3}" ]]; then
|
if [[ "${3}" ]]; then
|
||||||
eval "list_labels=(\"\${${3}[@]}\")"
|
eval "list_labels=(\"\${${3}[@]}\")"
|
||||||
fi
|
fi
|
||||||
@@ -837,7 +836,7 @@ function choose_mirrors() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
local mirror_list_name mirror_list_length
|
local mirror_list_name mirror_list_length
|
||||||
local mirror_list_labels=()
|
local -a mirror_list_labels=()
|
||||||
local label_msg_index label_msg_content
|
local label_msg_index label_msg_content
|
||||||
if [[ -z "${SOURCE}" ]] && [[ "${ONLY_REGISTRY}" != "true" ]]; then
|
if [[ -z "${SOURCE}" ]] && [[ "${ONLY_REGISTRY}" != "true" ]]; then
|
||||||
mirror_list_name="mirror_list_docker_ce"
|
mirror_list_name="mirror_list_docker_ce"
|
||||||
@@ -1087,7 +1086,7 @@ function install_dependency_packages() {
|
|||||||
|
|
||||||
## 配置 Docker CE 源
|
## 配置 Docker CE 源
|
||||||
function configure_docker_ce_mirror() {
|
function configure_docker_ce_mirror() {
|
||||||
local commands=()
|
local -a commands=()
|
||||||
case "${SYSTEM_FACTIONS}" in
|
case "${SYSTEM_FACTIONS}" in
|
||||||
"${SYSTEM_DEBIAN}")
|
"${SYSTEM_DEBIAN}")
|
||||||
## 处理 GPG 密钥
|
## 处理 GPG 密钥
|
||||||
@@ -1277,7 +1276,7 @@ function install_docker_engine() {
|
|||||||
function install_main() {
|
function install_main() {
|
||||||
local target_docker_version
|
local target_docker_version
|
||||||
local pkgs=""
|
local pkgs=""
|
||||||
local commands=()
|
local -a commands=()
|
||||||
if [[ "${INSTALL_LATESTED_DOCKER}" == "true" ]]; then
|
if [[ "${INSTALL_LATESTED_DOCKER}" == "true" ]]; then
|
||||||
pkgs="docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin"
|
pkgs="docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin"
|
||||||
else
|
else
|
||||||
@@ -1295,7 +1294,7 @@ function install_docker_engine() {
|
|||||||
target_docker_version="${DESIGNATED_DOCKER_VERSION}"
|
target_docker_version="${DESIGNATED_DOCKER_VERSION}"
|
||||||
else
|
else
|
||||||
if [[ "${CAN_USE_ADVANCED_INTERACTIVE_SELECTION}" == "true" ]]; then
|
if [[ "${CAN_USE_ADVANCED_INTERACTIVE_SELECTION}" == "true" ]]; then
|
||||||
local version_list=(
|
local -a version_list=(
|
||||||
$(cat $File_DockerVersionTmp | sort -t '.' -k1,1nr -k2,2nr -k3,3nr | tr '\n' ' ' | sed 's/ $//')
|
$(cat $File_DockerVersionTmp | sort -t '.' -k1,1nr -k2,2nr -k3,3nr | tr '\n' ' ' | sed 's/ $//')
|
||||||
)
|
)
|
||||||
local mirror_list_name="version_list"
|
local mirror_list_name="version_list"
|
||||||
@@ -1526,7 +1525,7 @@ function only_change_docker_registry_mirror() {
|
|||||||
if ! command_exists jq; then
|
if ! command_exists jq; then
|
||||||
## 更新软件源
|
## 更新软件源
|
||||||
local package_manager
|
local package_manager
|
||||||
local commands=()
|
local -a commands=()
|
||||||
case "${SYSTEM_FACTIONS}" in
|
case "${SYSTEM_FACTIONS}" in
|
||||||
"${SYSTEM_DEBIAN}")
|
"${SYSTEM_DEBIAN}")
|
||||||
package_manager="apt-get"
|
package_manager="apt-get"
|
||||||
@@ -1582,7 +1581,6 @@ function only_change_docker_registry_mirror() {
|
|||||||
|
|
||||||
function handleRegistryMirrorsValue() {
|
function handleRegistryMirrorsValue() {
|
||||||
local content="$1"
|
local content="$1"
|
||||||
local delimiter=","
|
|
||||||
local result=""
|
local result=""
|
||||||
content="$(echo "${content}" | sed 's| ||g')"
|
content="$(echo "${content}" | sed 's| ||g')"
|
||||||
local -a items=(${content//,/ })
|
local -a items=(${content//,/ })
|
||||||
@@ -1669,8 +1667,8 @@ function get_package_manager() {
|
|||||||
|
|
||||||
function interactive_select_list() {
|
function interactive_select_list() {
|
||||||
_SELECT_RESULT=""
|
_SELECT_RESULT=""
|
||||||
eval "local __values=(\"\${${1}[@]}\")"
|
eval "local -a __values=(\"\${${1}[@]}\")"
|
||||||
local __labels=()
|
local -a __labels=()
|
||||||
local message="${2}"
|
local message="${2}"
|
||||||
local selected=0
|
local selected=0
|
||||||
local start=0
|
local start=0
|
||||||
@@ -1904,7 +1902,7 @@ function animate_exec() {
|
|||||||
exit 130
|
exit 130
|
||||||
}
|
}
|
||||||
function make_temp_file() {
|
function make_temp_file() {
|
||||||
local temp_dirs=("." "/tmp")
|
local -a temp_dirs=("." "/tmp")
|
||||||
local tmp_file=""
|
local tmp_file=""
|
||||||
for dir in "${temp_dirs[@]}"; do
|
for dir in "${temp_dirs[@]}"; do
|
||||||
[[ ! -d "${dir}" || ! -w "${dir}" ]] && continue
|
[[ ! -d "${dir}" || ! -w "${dir}" ]] && continue
|
||||||
|
|||||||
Reference in New Issue
Block a user