forked from laysense/rhelphp
Use Tsinghua Remi mirrors on all mainland EL releases
This commit is contained in:
+31
-12
@@ -43,20 +43,39 @@ fi
|
||||
|
||||
|
||||
# 判断服务器是否位于中国大陆
|
||||
is_china=$(curl -s ping0.cc/geo | grep -q '中国' && echo "yes" || echo "no") # 调用API接口检查地理位置是否在中国大陆
|
||||
|
||||
# 设置对应的安装源URL
|
||||
if [[ "$is_china" == "yes" && "$rhel_version" -eq 9 ]]; then
|
||||
# 如果是中国大陆且RHEL版本为9,使用特定的国内源
|
||||
repo_url="https://git.laysense.com/enoch/RemiTuna/raw/branch/main/remi-release-9.4-2.el9.remi.noarch.rpm"
|
||||
else
|
||||
# 否则使用TUNA的Remi源,根据RHEL版本动态选择
|
||||
repo_url="https://mirrors.tuna.tsinghua.edu.cn/remi/enterprise/remi-release-$rhel_version.rpm"
|
||||
location=$(curl -fsS --max-time 10 https://ping0.cc/geo | sed -n '2p')
|
||||
location=${location%% — *}
|
||||
is_china=no
|
||||
if [[ "$location" == 中国* && ! "$location" =~ 香港|澳门|澳門|台湾|臺灣|台灣|臺湾 ]]; then
|
||||
is_china=yes
|
||||
fi
|
||||
|
||||
# 安装 Remi 仓库
|
||||
echo "Installing Remi repository from $repo_url..." # 输出安装源信息
|
||||
yum -y install "$repo_url" # 使用yum安装指定的remi-release包
|
||||
# 安装对应系统版本的标准 Remi 仓库包
|
||||
remi_mirror="https://mirrors.tuna.tsinghua.edu.cn/remi"
|
||||
repo_url="$remi_mirror/enterprise/remi-release-$rhel_version.rpm"
|
||||
repo_install_options=()
|
||||
if [[ "$is_china" == "yes" ]]; then
|
||||
# 避免安装仓库包时访问机器上已有的 Remi 镜像列表
|
||||
repo_install_options+=("--disablerepo=remi*")
|
||||
fi
|
||||
|
||||
echo "Installing Remi repository from $repo_url..."
|
||||
if ! yum -y "${repo_install_options[@]}" install "$repo_url"; then
|
||||
echo "Failed to install the Remi repository package." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ "$is_china" == "yes" ]]; then
|
||||
# 启用 Remi RPM 提供的 baseurl,并保留各仓库原有的路径、变量和 GPG 配置。
|
||||
echo "Switching Remi repositories to the Tsinghua mirror..."
|
||||
if ! sed -E -i \
|
||||
-e "s|^[[:blank:]]*#?[[:blank:]]*baseurl[[:blank:]]*=[[:blank:]]*https?://rpms\.remirepo\.net/enterprise/|baseurl=$remi_mirror/enterprise/|" \
|
||||
-e 's/^([[:blank:]]*(mirrorlist|metalink)[[:blank:]]*=)/#\1/' \
|
||||
/etc/yum.repos.d/remi*.repo; then
|
||||
echo "Failed to switch Remi repositories to the Tsinghua mirror." >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# 提示用户输入PHP版本
|
||||
read -p "Enter the PHP version to install (e.g., 80, 8.0, php80, php8.0): " php_version
|
||||
|
||||
Reference in New Issue
Block a user