1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- #!/bin/bash
- set -e
- show_usage="args: [--runmode=,--log-dir=]"
- #-o或--options选项后面是可接受的短选项,如ab:c::,表示可接受的短选项为-a -b -c,
- #其中-a选项不接参数,-b选项后必须接参数,-c选项的参数为可选的
- #-l或--long选项后面是可接受的长选项,用逗号分开,冒号的意义同短选项。
- #-n选项后接选项解析错误时提示的脚本名字
- ARGS=`getopt -o -h --long help,runmode:,log-dir: -n "$0" -- "$@"`
- if [ $? != 0 ]; then
- exit 1
- fi
- #将规范化后的命令行参数分配至位置参数($1,$2,...)
- eval set -- "${ARGS}"
- while [ -n "$1" ]
- do
- case "$1" in
- -h|--help)
- echo "$show_usage"; exit 1 ;;
- --runmode)
- RUNMODE=$2; shift ;;
- --log-dir)
- LOG_DIR=$2; shift ;;
- *) shift ;;
- esac
- done
- if [ -z $RUNMODE ];then
- RUNMODE="dev"
- fi
- if [ -z $LOG_DIR ];then
- LOG_DIR="logs"
- fi
- PROJECT_PATH=$(cd `dirname $0`; pwd)
- SERVICE_NAME="${PROJECT_PATH##*/}"
- APP_NAME="${PROJECT_PATH##*/}"
- #生成配置文件
- SPEC_FILE=app.spec
- APP_SERVICE=conf/app.service
- SH_APP=sh/app
- TOOLS_ROOT=`pwd`
- BUILD="${TOOLS_ROOT}/build"
- COMMONYAML=conf/common.yaml
- sed -e "s/%RUNMODE%/$RUNMODE/g" ${COMMONYAML}.in > ${COMMONYAML}
- echo ${LOG_DIR}
- sed -i "s#%LOGDIR%#${LOG_DIR}#g" ${COMMONYAML}
- sed -e "s/%APP_NAME%/$APP_NAME/g" ${APP_SERVICE}.in > conf/${SERVICE_NAME}.service
- sed -e "s/%APP_NAME%/$APP_NAME/g" ${SH_APP}.in > ${SH_APP}
- sed -i "s/%SERVICE_NAME%/$SERVICE_NAME/g" ${SH_APP}
- VERSION=`cat VERSION`
- make version=$VERSION
- mkdir -p $BUILD/buildroot/{BUILD,RPMS,S{RPMS,PECS,OURCES}}
- rm -f $BUILD/buildroot/SOURCES/*.tgz
- tar czf $BUILD/buildroot/SOURCES/${SERVICE_NAME}-$VERSION.tgz * .[!.]*
- sed -e "s/%VERSION%/$VERSION/g" ${SPEC_FILE}.in > ${SPEC_FILE}
- sed -i "s/%APP_NAME%/$APP_NAME/g" ${SPEC_FILE}
- sed -i "s/%SERVICE_NAME%/$SERVICE_NAME/g" ${SPEC_FILE}
- rpmbuild -bb ${SPEC_FILE} --define "_topdir $BUILD/buildroot/"
- rm -rf ./dist
- mkdir ./dist
- cp -rf $BUILD/buildroot/RPMS/* ./dist
- rm -rf $BUILD
|