首頁 > 軟體

RHEL5.x&RHEL6.x更換CentOS yum源

2020-06-16 18:10:04

最近接觸的系統多數為RHEL,RHEL自帶的yum又不能聯網安裝,於是寫了個一鍵安裝的指令碼,支援RHEL5.x&RHEL6.x,選用的是網易的源。

#!/bin/sh
#author by thundermeng
 
. /etc/init.d/functions
bit=`getconf LONG_BIT`
release=`sed -r -n 's/(.*) ([[:digit:]]).([[:digit:]]) (.*)/2/p' /etc/RedHat-release`
 
if [ $UID -ne 0  ]
then
  echo "Please use root exec this shell"
  exit 1
fi
 
[ `rpm -qa |grep yum|wc -l` -ge 1  ] && { 
rpm -qa |grep yum | xargs rpm -e --nodeps

 
[ -e /tmp/yumupdate ] || mkdir /tmp/yumupdate
cd /tmp/yumupdate
 
rehl5() 
{
wget http://mirrors.163.com/.help/CentOS5-Base-163.repo -P /etc/yum.repos.d/
sed -i "s/$releasever/5/g" /etc/yum.repos.d/CentOS5-Base-163.repo
 
case $bit in
  32)
    wget http://mirrors.163.com/centos/5/os/i386/CentOS/yum-metadata-parser-1.1.2-4.el5.i386.rpm
    rpm -ivh yum-metadata-parser-1.1.2-4.el5.i386.rpm --nodeps
    ;;
  64)
    wget http://mirrors.163.com/centos/5/os/x86_64/CentOS/yum-metadata-parser-1.1.2-4.el5.x86_64.rpm
    rpm -ivh yum-metadata-parser-1.1.2-4.el5.x86_64.rpm --nodeps
    ;;
esac
 
wget http://mirrors.163.com/centos/5/os/x86_64/CentOS/yum-3.2.22-40.el5.centos.noarch.rpm
wget http://mirrors.163.com/centos/5/os/x86_64/CentOS/yum-fastestmirror-1.1.16-21.el5.centos.noarch.rpm
wget http://mirrors.163.com/centos/5/os/x86_64/CentOS/yum-updatesd-0.9-6.el5_10.noarch.rpm
 
rpm -ivh yum-3.2.22-40.el5.centos.noarch.rpm yum-fastestmirror-1.1.16-21.el5.centos.noarch.rpm
rpm -ivh yum-updatesd-0.9-6.el5_10.noarch.rpm
}
 
rehl6() 
{
#cd rehl6
#cp CentOS-Base.repo /etc/yum.repos.d/
wget http://mirrors.163.com/.help/CentOS6-Base-163.repo -P /etc/yum.repos.d/
sed -i "s/$releasever/6/g" /etc/yum.repos.d/CentOS6-Base-163.repo
 
wget http://mirrors.163.com/centos/6/os/x86_64/Packages/python-iniparse-0.3.1-2.1.el6.noarch.rpm
rpm -ivh Python-iniparse-0.3.1-2.1.el6.noarch.rpm
 
case $bit in
  32)
    wget http://mirrors.163.com/centos/6/os/i386/Packages/yum-metadata-parser-1.1.2-16.el6.i686.rpm
    rpm -ivh yum-metadata-parser-1.1.2-16.el6.i686.rpm
    ;;
  64)
    wget http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-metadata-parser-1.1.2-16.el6.x86_64.rpm
    rpm -ivh yum-metadata-parser-1.1.2-16.el6.x86_64.rpm
    ;;
esac
 
wget http://mirrors.163.com/centos/6/os/i386/Packages/yum-3.2.29-60.el6.centos.noarch.rpm
wget http://mirrors.163.com/centos/6/os/i386/Packages/yum-plugin-fastestmirror-1.1.30-30.el6.noarch.rpm                                         
                                             
rpm -ivh yum-3.2.29-60.el6.centos.noarch.rpm yum-plugin-fastestmirror-1.1.30-30.el6.noarch.rpm
}
 
if [ $release -eq 6  ]
  then   
    rehl6
elif [ $release -eq 5 ]
  then
    rehl5
else
    echo "This System Release Not Support!"
fi
         
if [ $? -eq 0  ]
  then
  action "yumupdate is sucessed" /bin/true
  else
  action "yumupdate is failed" /bin/false
  exit 1
fi
rm -rf /tmp/yumupdate
yum clean all
yum repolist

CentOS中將DVD作為預設yum源的設定方法  http://www.linuxidc.com/Linux/2015-01/111266.htm

RedHat 6.2 Linux修改yum源免費使用CentOS源 http://www.linuxidc.com/Linux/2013-07/87383.htm

設定EPEL YUM源 http://www.linuxidc.com/Linux/2012-10/71850.htm

Redhat 本地yum源設定 http://www.linuxidc.com/Linux/2012-11/75127.htm

yum的組態檔說明 http://www.linuxidc.com/Linux/2013-04/83298.htm

RedHat 6.1下安裝yum(圖文) http://www.linuxidc.com/Linux/2013-06/86535.htm

YUM 安裝及清理 http://www.linuxidc.com/Linux/2013-07/87163.htm

CentOS 6.4上搭建yum本地源 http://www.linuxidc.com/Linux/2014-07/104533.htm


IT145.com E-mail:sddin#qq.com