自动更换阿里YUM源脚本

作者: admin 分类: Linux,Shell脚本,系统 发布时间: 2018-02-27 16:24

环境:Centos7.4

#############################################################
# File Name: yum_aliyun.sh
# Author: 寻音
# E-mail: lnhxzwb@126.com
# Created Time: Tue 27 Feb 2018 03:06:07 PM CST
#==================================================================
#!/bin/bash
#当前环境为Centos7.X/6.x 环境,如果不能正确安装请手动操作!

num=$(cat /etc/redhat-release |awk '{print $4}'|cut -d. -f1)

yum_6()
{
wget -O Centos-aliyun.repo http://mirrors.aliyun.com/repo/Centos-6.repo &>/dev/null
sed -i 's/$releasever/6/g' Centos-aliyun.repo &>/dev/null
}

yum_7()
{
wget -O Centos-aliyun.repo http://mirrors.aliyun.com/repo/Centos-7.repo &>/dev/null
sed -i 's/$releasever/7/g' Centos-aliyun.repo &>/dev/null
}

read -p "您确定要把当前环境YUM源更换为阿里YUM源吗?(Y/N)" yum
if [ $yum == "y" ] || [ $yum == "Y" ];then
echo "正在执行操作,请稍等....."
ls /usr/bin/wget &>/dev/null
if [ $? != 0 ];then
yum install wget -y &>/dev/null
fi
cd /etc/yum.repos.d/
mkdir yum_bak
mv * yum_bak &>/dev/null
if [ $num == "7" ];then
yum_7
elif [ $num == "6" ];then
yum_6
else
echo "============================<安装信息>============================"
echo "安装程序不能自动完成,请检查环境或手动安装!"
fi
echo "nameserver 223.5.5.5" >>/etc/resolv.conf
echo "nameserver 223.6.6.6" >>/etc/resolv.conf
yum makecache &>/dev/null
yum install epel-release -y &>/dev/null
if [ $? = 0 ];then
echo "============================<安装信息>============================"
echo "恭喜您!YUM源已安装完成,请放心使用"
else
echo "============================<安装信息>============================"
echo "安装程序不能自动完成,请检查环境或手动安装!"
fi
elif [ $yum == "n" ] || [ $yum == "N" ];then
echo "============================<安装信息>============================"
echo "感谢使用本程序,再见!"
fi

 

 

 


温馨提示:如无特殊说明,本站文章均为作者原创,转载请注明出处!

发表评论