#!/usr/bin/env bash set -x set -euo pipefail IFS=$'\n\t' function pack() { PKG_NAME=${1} PKG_VERSION=$(grep '^Version:' ${PKG_NAME}.spec | awk '{print $2}') cd .. PROJECT_NAME="${PKG_NAME}-${PKG_VERSION}" git archive --format=tar --prefix=$PROJECT_NAME/ HEAD | (tar xpf -) tar zcpf ${PROJECT_NAME}.tar.gz ${PROJECT_NAME} /bin/mv -f ${PROJECT_NAME}.tar.gz packaging/ rm -rf ${PKG_NAME}-${PKG_VERSION} cd - } function help() { echo "$0 build|pack" } # 检测rpmbuild是否可使用--nodebuginfo参数 function debuginfo() { local exist_debuginfo=`rpmbuild --help | grep 'nodebuginfo' | wc -l` if [ ${exist_debuginfo} -eq 1 ]; then echo "--nodebuginfo" else echo "" fi } function help() { echo "$0 build|pack" } if [ "$1" == "" ]; then help elif [ "$1" == "pack" ];then pack $2 elif [ "$1" == "debuginfo" ];then debuginfo elif [ "$1" == "test" ];then run_test else help fi