使用方法:1.下载系统版本对应的”deltarpm-version.el6.x86_64.rpm python-deltarpm-version.el6.x86_64.rpm createrepo-version.noarch.rpm”,放到脚本对应的同级目录。2.把需要做成源的rpm(建议把对应系统版本的32位和64位iso中的rpm都拿出来)放到一个目录下,如放到”/tmp/packages”,直接运行脚本即可。
代码如下,就不多说了
#!/bin/sh
#请下载系统版本对应的”deltarpm-version.el6.x86_64.rpm python-deltarpm-version.el6.x86_64.rpm #createrepo-version.noarch.rpm”,放到脚本对应的同级目录set -e
function CheckRoot(){#check if currect use is root userCUR_USER=`whoami`if [ $CUR_USER != ‘root’ ]then echo ‘The operation will modify system files,you should be root!’ exit 1fi}
function MkDir(){if [ ! -d $1 ]then mkdir $1 > /dev/nullfi}
function RollBack(){ORIG_DIR=`pwd`cd /etc/yum.repos.d > /dev/nullMkDir /ect/yum.repos.d/configYum_rbmv *.repo configYum_rb/ > /dev/nullmv backup/*.repo . > /dev/nullrm -fr backup/ configYum_rb/ > /dev/nullyum clean all > /dev/nullyum makecache > /dev/nullyum repolist all}
function Create(){echo ‘Begin to create local yum source … …’ORIG_DIR=`pwd`
#backup currect configif [ ! -d “/etc/yum.repos.d” ] then echo ‘/etc/yum.repos.d is not existed , please check your system!’ exit 1 fi
cd /etc/yum.repos.d > /dev/nullMkDir /etc/yum.repos.d/backupmv ./*.repo backup/
#create local.repocat >> local.repo << EOF[localrepo]name=localrepobaseurl=file://$1gpgcheck=0enabled=1EOF
retrpm=`rpm -qa | grep deltarpm`if [ -z “$retrpm” ]then rpm -ivh $ORIG_DIR/deltarpm-.*.rpm > /dev/null rpm -ivh $ORIG_DIR/python-deltarpm-.*.rpm > /dev/nullfi
#check if createrepo if existedwhich createrepo > /dev/null
if [ $? -eq 1 ]then rpm -ivh $ORIG_DIR/createrepo.*.noarch.rpm > /dev/null if [ $? -ne 0 ] then echo ‘Install createrepo failed !’ exit 1 fifi
createrepo $1 > /dev/null
if [ $? -ne 0]then echo ‘create repo failed !’ exit 1fi
yum clean all > /dev/nullyum makecache > /dev/nullyum repolist all}
function Help(){cat <<EOFThere are 2 ways to call this script, for example:1. To create a local Yum source: ./configYum.sh /tmp/packages2. To rollback previous operation: ./configYum.sh bEOF}
function Main(){if [ $# -ne 1 ]then Helpelif [ -d $1 ]then CheckRoot Create $*elif [ $1 = ‘b’ ]then CheckRoot RolllBackelse Helpfi}
Main $*
更多YUM相关教程见以下内容:
RedHat 6.2 Linux修改yum源免费使用CentOS源 http://www.68idc.cn/Linux/2013-07/87383.htm
配置EPEL YUM源 http://www.68idc.cn/Linux/2012-10/71850.htm
Redhat 本地yum源配置 http://www.68idc.cn/Linux/2012-11/75127.htm
yum的配置文件说明 http://www.68idc.cn/Linux/2013-04/83298.htm
RedHat 6.1下安装yum(图文) http://www.68idc.cn/Linux/2013-06/86535.htm
YUM 安装及清理 http://www.68idc.cn/Linux/2013-07/87163.htm
CentOS 6.4上搭建yum本地源 http://www.68idc.cn/Linux/2014-07/104533.htm
别人失去了信心,他却下决心实现自己的目标。