【shell脚本】自动配置yum源auto_yum_config.sh

[root@rhel8 shell]# cat auto_yum_config.sh 
#!/bin/bash
##########################################################################
# yum config case                                                        #
# by author tanbaobao 2020/06/16                                         #
##########################################################################

YUM_IP=本机ip
# CentOS系统:`cat /etc/redhat-release | awk '{print $4}' | awk -F"." '{print $1"."$2}'`
OS_VERSION=`cat /etc/redhat-release | awk '{print $6}' | awk -F"." '{print $1"."$2}'`
YUM_DIR=/etc/yum.repos.d

# 如果目录不存在,则执行后面语句
[ -d "$YUM_DIR" ] || mkdir -p $YUM_DIR/bak
mv $YUM_DIR/*.repo $YUM_DIR/bak

case "$OS_VERSION" in
    8.1)
        cat >$YUM_DIR/repo8u1.repo <<-EOF
        [repo8u1]
        name=repo8u1
        baseurl=ftp://$YUM_IP/repo8u1
        gpgcheck=0
        EOF
        echo "8.1 yum configure.."
        ;;
    7.3)
        cat >$YUM_DIR/repo8u1.repo <<-EOF
        [centos7u3]
        name=centos7u3
            baseurl=file:///centos7u3
            gpgcheck=0
        EOF
        ;;    
    6.8)
        wget -O $YUM_DIR/centos6u8.repo http://mirrors.aliyun.com/repo/Centos-6.repo
        ;;
    5.9)
        curl -o $YUM_DIR/CentOS_Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo
        ;;
    *)
        echo -e "\033[34mError\033[0m"
esac

 

posted @ 2020-06-19 19:58  HeiDi_BoKe  阅读(296)  评论(0编辑  收藏  举报