#!/bin/bash # 检查系统版本 if [ -f /etc/redhat-release ]; then OS_VERSION=$(grep -oE '[0-9]+\.[0-9]+' /etc/redhat-release) else echo "未找到 /etc/redhat-release 文件。请确保您运行的是 CentOS 系统。" exit 1 fi # 仅支持 CentOS 7 if [[ $OS_VERSION != "7."* ]]; then echo "此脚本仅支持 CentOS 7 系统。当前系统版本为:$OS_VERSION" exit 1 fi # 备份现有的YUM源配置文件 if [ -f /etc/yum.repos.d/CentOS-Base.repo ]; then cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak echo "现有的YUM源配置文件已备份为CentOS-Base.repo.bak" fi # 删除所有现有的YUM源配置文件 rm -f /etc/yum.repos.d/*.repo # 添加阿里云的CentOS源 cat > /etc/yum.repos.d/CentOS-Base-ali.repo < /etc/yum.repos.d/CentOS-Vault.repo <