#!/bin/bash
#===============================================================================

FILE: yum-auto-create-option.sh

# USAGE: create yum repo script

# DESCRIPTION: To create yum repo automatically 包括base源和epel源

# BUGS: ---

NOTES: ---

AUTHOR: xxx

MAIL: xxx

CREATED: 04/03/2019 3:12 PM

VERSION: 1.0

#===============================================================================
function taiji_yum {
#创建yum备份文件目录
if [ -d /tmp/yum-bak ];then
echo "directory is ok"
else
echo "directory isnt ok, need mkdir"
mkdir /tmp/yum-bak
fi
#备份以前的yum源
mv /etc/yum.repos.d/* /tmp/yum-bak
#判断操作系统版本
test=​​cat /proc/version | awk '{print $3}'​

version=​​echo $test | sed "s/\..*//g"​

if [ $version -ge 3 ];then
echo "centos7.x yum building"
echo '[base]
name=CentOS-7 - Base
baseurl=http://实际IP地址填写/centos7/base
gpgcheck=0
#gpgkey=http://实际IP地址填写/centos7/base/RPM-GPG-KEY-CentOS-7
[epel]
name=CentOS-7 - epel
baseurl=http://实际IP地址填写/centos7/epel
gpgcheck=0
#gpgkey=
' > /etc/yum.repos.d/centos7_taiji.repo
else
echo "CentOS6.x yum building"
echo '[base]
name=CentOS-6 - Base
baseurl=http://实际IP地址填写/centos6/base
gpgcheck=0
gpgkey=http://实际IP地址填写/centos6/base/RPM-GPG-KEY-CentOS-7
[epel]
name=CentOS-6 - epel
baseurl=http://实际IP地址填写/centos6/epel
gpgcheck=0
#gpgkey=
' > /etc/yum.repos.d/centos6_taiji.repo
fi
#清除并重建yum cache
yum clean all
yum makecache
yum list
}
taiji_yum