为没有RHN的童鞋某福利,方便YUM源的替换

#!/bin/bash

#Get the OS release
B=`awk '{print $7}' /etc/redhat-release`
#delete RHEL yum soft
rpm -qa|grep yum|xargs rpm -e --nodeps
#Download Centos yum soft
A=`arch`
if [ $A = 'x86_64' ]
 then
   wget http://mirrors.163.com/centos/$B/os/x86_64/Packages/yum-3.2.29-30.el6.centos.noarch.rpm    
   wget http://mirrors.163.com/centos/$B/os/x86_64/Packages/yum-metadata-parser-1.1.2-16.el6.x86_64.rpm
   wget http://mirrors.163.com/centos/$B/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.30-14.el6.noarch.rpm
   wget http://mirrors.163.com/centos/$B/os/x86_64/Packages/python-iniparse-0.3.1-2.1.el6.noarch.rpm
else
   wget http://mirrors.163.com/centos/$B/os/i386/Packages/yum-3.2.29-30.el6.centos.noarch.rpm    
   wget http://mirrors.163.com/centos/$B/os/i386/Packages/yum-metadata-parser-1.1.2-16.el6.i686.rpm
   wget http://mirrors.163.com/centos/$B/os/i386/Packages/yum-plugin-fastestmirror-1.1.30-14.el6.noarch.rpm
   wget http://mirrors.163.com/centos/$B/os/i386/Packages/python-iniparse-0.3.1-2.1.el6.noarch.rpm
fi
#install Centos yum soft
rpm -ivh python*
rpm -ivh yum*
#Download 163's repo file
C=`echo $B|awk -F '.' '{print $1}'`
rm -rf /etc/yum.repos.d/*
wget http://mirrors.163.com/.help/CentOS$C-Base-163.repo -O /etc/yum.repos.d/CentOS$C-Base-163.repo
sed -i 's/$releasever/'$B'/g' /etc/yum.repos.d/CentOS$C-Base-163.repo
#yum test
yum clean all
yum makecache
yum repolist

以上为更换为163的CentOS源的代码,保存为脚本添加运行权限即可,支持RHEL4、5、6的所有版本。

由于163每个版本的源都只提供最新版本的YUM源升级,所以根据当前版本的最新版本进行修改,如RHEL6版本中,最新的6.4,所以163只有6.4的源,通用6版本,根据实际情况进行修改,谢谢!


附件为制作好的可执行文件