zoukankan      html  css  js  c++  java
  • CS4.1 RPM打包函数分析

    shell举例说明:
    脚本名称叫test.sh 入参三个: 1 2 3
    运行test.sh 1 2 3后
    $*为"1 2 3"(一起被引号包住)
    $@为"1" "2" "3"(分别被包住)
    $#为3(参数数量)
     
    rpm包编译的脚本的所在目录/root/cs4.1/packaging/centos63,文件名称是package.sh
     
    image
     

    #!/bin/bash
    # Licensed to the Apache Software Foundation (ASF) under one
    # or more contributor license agreements.  See the NOTICE file
    # distributed with this work for additional information
    # regarding copyright ownership.  The ASF licenses this file
    # to you under the Apache License, Version 2.0 (the
    # "License"); you may not use this file except in compliance
    # with the License.  You may obtain a copy of the License at
    #
    #   http://www.apache.org/licenses/LICENSE-2.0
    #
    # Unless required by applicable law or agreed to in writing,
    # software distributed under the License is distributed on an
    # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    # KIND, either express or implied.  See the License for the
    # specific language governing permissions and limitations
    # under the License.
    # 该脚本文件用于编译CloudStack 的rpm 包

    #usage函数用于提供控制台输出帮助
    function usage() {
    echo ""
    echo "usage: ./package.sh [-p|--pack] [-h|--help] [ARGS]"
    echo ""
    echo "The commonly used Arguments are:"
    echo "oss|OSS             To package with only redistributable libraries (default)"
    echo "noredist|NOREDIST   To package with non-redistributable libraries"
    echo ""
    echo "Examples: ./package.sh -p|--pack oss|OSS"
    echo "          ./package.sh -p|--pack noredist|NOREDIST"
    echo "          ./package.sh (Default OSS)"
    exit 1
    }

    #rpm打包函数
    function packaging() {
        
    CWD=`pwd`
    RPMDIR=$CWD/../../dist/rpmbuild
    PACK_PROJECT=cloudstack
    if [ -n "$1" ] ; then
      DEFOSSNOSS="-D_ossnoss $packageval"
    fi


    VERSION=`(cd ../../; mvn org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.version) | grep '^[0-9].'`
    if echo $VERSION | grep SNAPSHOT ; then
      REALVER=`echo $VERSION | cut -d '-' -f 1`
      DEFVER="-D_ver $REALVER"
      DEFPRE="-D_prerelease 1"
      DEFREL="-D_rel SNAPSHOT"
    else
      REALVER=`echo $VERSION`
      DEFVER="-D_ver $REALVER"
      DEFREL="-D_rel 1"
    fi

    mkdir -p $RPMDIR/SPECS
    mkdir -p $RPMDIR/BUILD
    mkdir -p $RPMDIR/RPMS
    mkdir -p $RPMDIR/SRPMS
    mkdir -p $RPMDIR/SOURCES/$PACK_PROJECT-$VERSION


    (cd ../../; tar -c --exclude .git --exclude dist  .  | tar -C $RPMDIR/SOURCES/$PACK_PROJECT-$VERSION -x )
    (cd $RPMDIR/SOURCES/; tar -czf $PACK_PROJECT-$VERSION.tgz $PACK_PROJECT-$VERSION)

    cp cloud.spec $RPMDIR/SPECS

    (cd $RPMDIR; rpmbuild --define "_topdir $RPMDIR" "${DEFVER}" "${DEFREL}" ${DEFPRE+"${DEFPRE}"} ${DEFOSSNOSS+"$DEFOSSNOSS"} -bb SPECS/cloud.spec)

    exit
    }

    #如果前一个表达式小于后一个表达式,则结果为真
    if [ $# -lt 1 ] ; then

        packaging

    elif [ $# -gt 0 ] ; then

        SHORTOPTS="hp:"
        LONGOPTS="help,pack:"

        ARGS=$(getopt -s bash -u -a --options $SHORTOPTS  --longoptions $LONGOPTS --name $0 -- "$@" )
        eval set -- "$ARGS"

        while [ $# -gt 0 ] ; do
        case "$1" in
        -h | --help)
            usage
            exit 0
            ;;
        -p | --pack)
            echo "Doing CloudStack Packaging ....."
            packageval=$2
            if [ "$packageval" == "oss" -o "$packageval" == "OSS" ] ; then
                packaging
            elif [ "$packageval" == "noredist" -o "$packageval" == "NOREDIST" ] ; then
                packaging noredist
            else
                echo "Error: Incorrect value provided in package.sh script, Please see help ./package.sh --help|-h for more details."
                exit 1
            fi
            ;;
        -)
            echo "Unrecognized option..."
            usage
            exit 1
            ;;
        *)
            shift
            ;;
        esac
        done

    else
        echo "Incorrect choice.  Nothing to do." >&2
        echo "Please, execute ./package.sh --help for more help"
    fi

  • 相关阅读:
    计算页数
    DOS批量拷贝文件
    时间与日期处理
    MOUSE_OVER/MOUSE_OUT与ROLL_OVER/ROLL_OUT的区别
    vb程序改写方法。
    sqldmo备份还原sqlserver2000数据库
    终于有了自己的窝啦
    vb中创建Excel,把数据存入Excel
    提高vb 》excel数据的导入速度
    SQLServer2000数据库特有的1433端口号不能访问
  • 原文地址:https://www.cnblogs.com/heidsoft/p/3428986.html
Copyright © 2011-2022 走看看