zoukankan      html  css  js  c++  java
  • centos建立本地yum源shell脚本

    使用方法:

    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 user
    CUR_USER=`whoami`
    if [ $CUR_USER != 'root' ]
    then
          echo 'The operation will modify system files,you should be  root!'
      exit 1
    fi
    }
    
    function MkDir()
    {
    if [ ! -d $1 ]
    then
      mkdir $1 > /dev/null
    fi
    }
    
    function RollBack()
    {
    ORIG_DIR=`pwd`
    cd /etc/yum.repos.d > /dev/null
    MkDir /ect/yum.repos.d/configYum_rb
    mv *.repo configYum_rb/ > /dev/null
    mv backup/*.repo . > /dev/null
    rm -fr backup/ configYum_rb/ > /dev/null
    yum clean all > /dev/null
    yum makecache > /dev/null
    yum repolist all
    }
    
    function Create()
    {
    echo 'Begin to create local yum source ... ...'
    ORIG_DIR=`pwd`
    
    #backup currect config
    if [ ! -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/null
    MkDir /etc/yum.repos.d/backup
    mv ./*.repo backup/
    
    #create local.repo
    cat >> local.repo << EOF
    [localrepo]
    name=localrepo
    baseurl=file://$1
    gpgcheck=0
    enabled=1
    EOF
    
    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/null
    fi
    
    #check if createrepo if existed
    which 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
      fi
    fi
    
    createrepo $1 > /dev/null
    
    if [ $? -ne 0]
    then
      echo 'create repo failed !'
      exit 1
    fi
    
    yum clean all > /dev/null
    yum makecache > /dev/null
    yum repolist all
    }
    
    function Help()
    {
    cat <<EOF
    There are 2 ways to call this script, for example:
    1. To create a local Yum source: ./configYum.sh /tmp/packages
    2. To rollback previous operation: ./configYum.sh b
    EOF
    }
    
    function Main()
    {
    if [ $# -ne 1 ]
    then
      Help
    elif [ -d $1 ]
    then
      CheckRoot
      Create $*
    elif [ $1 = 'b' ]
    then
      CheckRoot
      RolllBack
    else
      Help
    fi
    }
    
    Main $*    
  • 相关阅读:
    1069: [SCOI2007]最大土地面积
    Kettle 解决数据锁的问题(事务(进程 ID 51)与另一个进程被死锁在 锁 资源上)
    Kettle配合Windows执行计划实现定时实行作业
    把本地项目同步到码云
    IDEA通过Maven WebApp archetype 创建Spring boot项目骨架
    从零开始完整搭建 Spring-Boot 项目开发框架的教程
    使用IDEA搭建Spring Boot入门项目
    Win10激活失败并提示错误代码0xC004C003的解决方法
    javascript (JS组成、书写位置、基本概念、作用域、内存问题、变量)
    HTML基础之标签
  • 原文地址:https://www.cnblogs.com/foxsir/p/5371342.html
Copyright © 2011-2022 走看看