一、需求:
- 一键式脚本更换国内的阿里源
二、脚本
#!/bin/bash
# 数据迁移备份
yum_bak='mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup'
# 查看当前仓库
yum_repo = "yum repolist|grep '*'|awk -F"[:.]" 'NR==1{print $3}'"
# 配置成功
determine(){
if [ $? -eq 0 ];then
echo "配置成功~~"
fi
}
# 判断是否存在wget
yum_wget=`rpm -qa|grep wget|awk -F"-" '{print $1}'`
if [ $yum_wget = "wget" ];then
echo "wget存在,直接淦!"
else
yum -y install wget
fi
# 1、甄别操作版本号
os_ve=`awk '{print $(NF-1)}' /etc/redhat-release`
determine
while true
do
if [ ${os_ve%%.*} -eq 6 ];then
$yum_bak #调用
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-6.10.repo
determine
if [ $yum_repo -ne "aliyun" ];then
systemctl restart network
else
let i++
if [ $i -eq 2 ];then
mail -s "`date +%F-%H-%M`_网络存在问题" [email protected] < /tmp/network.log > /dev/null
fi
break
fi
elif [ ${os_ve%%.*} -eq 6 ];then
$yum_back
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
determine
if [ $yum_repo1 -eq 1 ];then
systemctl restart network
else
let i++
if [ $i -eq 2 ];then
mail -s "`date +%F-%H-%M`_网络存在问题" [email protected] < /tmp/network.log > /dev/null
fi
break
fi
fi
done
# 2、判断centos系统是centos6还是centos7
if [ ${os_ve%%.*} -eq 6 ];then
$yum_bak #调用
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-6.10.repo
determine
elif [ ${os_ve%%.*} -eq 6 ];then
$yum_back
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
determine
fi
标签:仓库,eq,repo,etc,yum,fi,wget,更换
From: https://www.cnblogs.com/9Dusk/p/18365101