首页 Linux

linux CentOS 6/7/8 yum源自动切换脚本

2021-09-28 14:53

#!/bin/bash

release = `cat /etc/redhat-release | awk '{print $3}' | awk -F '.' '{print $1}'`

CENTOS_YUM()

{

    case "$release" in

    "6")

        echo "当前 CentOS 匹配版本为 6"

        repo = "/etc/yum.repos.d/centos6-epel.repo"

        if [ ! -e $repo ]; then

        yum install -y wget

        cd /etc/yum.repos.d/ && mkdir backup && mv ./* backup

        wget work.eisc.cn/ruanjian/rpm/yumrepo/centos6-epel.repo

        wget work.eisc.cn/ruanjian/rpm/yumrepo/centos6.repo

        yum clean all && yum makecache

        yum list

        else

        echo "yum已经切换"

        fi

   ;;

   "7")

        echo "当前 CentOS 匹配版本为 7"

        repo = "/etc/yum.repos.d/epel-7.repo"

        if [ ! -e $repo ]; then

        yum install -y wget

        cd /etc/yum.repos.d/ && mkdir backup && mv ./* backup

        wget work.eisc.cn/ruanjian/rpm/yumrepo/Centos-7.repo

        wget work.eisc.cn/ruanjian/rpm/yumrepo/epel-7.repo

        yum clean all && yum makecache

        yum list

        else

        echo "yum已经切换"

        fi

  ;;

  "8")

      echo "当前 CentOS 匹配版本为 8"

      repo = "/etc/yum.repos.d/Centos-8.repo"

      if [ ! -e $repo ]; then

      yum install -y wget

      cd /etc/yum.repos.d/ && mkdir backup && mv ./* backup

      wget -O /etc/repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo

      yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm

      wget work.eisc.cn/ruanjian/rpm/yumrepo/epel8.repo

      yum clean all && yum makecache

      yum list

      else

      echo "yum已经切换"

      fi

 ;;

*)

    echo "当前CentOS版本过低,退出!"

     ;;

esac

}

CENTOS_YUM

返回首页
返回顶部