Redhat更换在线YUM源脚本

作者: admin 分类: Linux,Shell脚本,系统 发布时间: 2018-03-07 09:25

环境:Redhat 6.7

Aliyun YUM源

#######################################################
# File Name: yum_redhat_aliyun.sh
# Author: 寻音
# E-mail: lnhxzwb@126.com
# Created Time: Tue 27 Feb 2018 03:06:07 PM CST
#================================================================== 
#!/bin/bash
read -p "您确定要把当前环境YUM源更换为阿里YUM源吗?(Y/N)" yum
if [ $yum == "y" ] || [ $yum == "Y" ];then
rpm -qa|grep yum|xargs rpm -e --nodeps &>/dev/null
if [ $? = 0 ];then
echo "原YUM程序已卸载完成,正在下载新的程序,请稍候...."
wget ftp://rpmfind.net/linux/centos/6.9/os/x86_64/Packages/yum-3.2.29-81.el6.centos.noarch.rpm &>/dev/null
wget ftp://rpmfind.net/linux/centos/6.9/os/x86_64/Packages/yum-metadata-parser-1.1.2-16.el6.x86_64.rpm &>/dev/null
wget ftp://rpmfind.net/linux/centos/6.9/os/x86_64/Packages/python-iniparse-0.3.1-2.1.el6.noarch.rpm &>/dev/null
wget ftp://rpmfind.net/linux/centos/6.9/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.30-40.el6.noarch.rpm &>/dev/null
if [ $? = 0 ];then
echo "程序已下载完成,正在安装,请稍候......"
rpm -Uh python-* &>/dev/null
rpm -Uh yum-* &>/dev/null
rpm -qa |grep yum &>/dev/null
if [ $? = 0 ];then
echo "程序安装成功,正在配置,请稍候......"
cd /etc/yum.repos.d/
mkdir yum_bak
mv * yum_bak &>/dev/null
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 makecache &>/dev/null
yum install epel-release -y &>/dev/null
if [ $? = 0 ];then
echo "============================<安装信息>============================"
echo "恭喜您!YUM源已安装完成,请放心使用"
else
echo "============================<安装信息>============================"
echo "安装程序不能自动完成,请检查环境或手动安装!"
fi
else
echo "程序安装失败,请手动检测安装!"
fi
else
echo "程序包下载失败,请检查相关链接是否有效!"
fi
else
echo "程序卸载失败,请检查相关程序"
fi
elif [ $yum == "n" ] || [ $yum == "N" ];then
echo "============================<安装信息>============================"
echo "感谢使用本程序,再见!"
fi

 

注:使用之前请检查安装包下载链接是否有效,且修改为自己所需环境参数!!

 


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

发表评论