yum源仓库更换脚本

一、需求:

  • 一键式脚本更换国内的阿里源

二、脚本

#!/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`_网络存在问题" 157191547452@163.com < /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`_网络存在问题" 15719154792@163.com < /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
  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值