#!/bin/bash
cd /etc/yum.repos.d/
echo "【1】备份现在yum源"
mkdir bak
mv *.repo bak/
echo "    ----备份完成"

echo "【2】下载国内yum源"
curl -L -o "/etc/yum.repos.d/CentOS-Base.repo" -# "https://www.klquan.com/template/CentOS-Base.repo"
curl -L -o "/etc/yum.repos.d/epel.repo" -# "https://www.klquan.com/template/epel.repo"
curl -L -o "/etc/yum.repos.d/yylab.repo" -# "https://www.klquan.com/template/yylab.repo"


echo "【3】清理yum缓存"
if yum clean all > /dev/null 2>&1; then
    echo "    ----缓存清理完成"
else
    echo "警告：清理缓存时出现一些问题。" >&2
fi



echo "【4】加载yum缓存"
yum makecache
if yum makecache fast; then
    echo "    ----缓存建立完成,可执行 'yum repolist' 查看已启用的仓库列表。"
else
    echo -e "\n警告：重建缓存失败，请手动检查仓库配置！" >&2
    echo "可尝试："
    echo "  1. 检查网络连接"
    echo "  2. 查看 /etc/yum.repos.d/ 下的 .repo 文件"
    exit 1
fi
