123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- #!/bin/bash
- set -e
- show_usage="args: [--runmode=,--serve-addr=,--serve-port=,--etcd-addr=,--etcd-port=,--encrypt-key=,--log-dir=]"
- #-o或--options选项后面是可接受的短选项,如ab:c::,表示可接受的短选项为-a -b -c,
- #其中-a选项不接参数,-b选项后必须接参数,-c选项的参数为可选的
- #-l或--long选项后面是可接受的长选项,用逗号分开,冒号的意义同短选项。
- #-n选项后接选项解析错误时提示的脚本名字
- ARGS=`getopt -o -h --long help,runmode:,serve-addr:,serve-port:,etcd-addr:,etcd-port:,encrypt-key:,log-dir:,project-name: -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 ;;
- --serve-addr)
- SERVE_ADDR=$2; shift ;;
- --serve-port)
- SERVE_PORT=$2; shift ;;
- --etcd-addr)
- ETCD_ADDR=$2; shift ;;
- --etcd-port)
- ETCD_PORT=$2; shift ;;
- --encrypt-key)
- ENCRYPT_KEY=$2; shift ;;
- --log-dir)
- LOG_DIR=$2; shift ;;
- --project-name)
- PROJECT_NAME=$2; shift ;;
- *) shift ;;
- esac
- done
- if [ -z $SERVE_PORT ];then
- echo "The serve-port must be specified."
- exit 1
- fi
- if [ -z $PROJECT_NAME ];then
- echo "The project-name must be specified."
- exit 1
- fi
- if [ -z $RUNMODE ];then
- RUNMODE="dev"
- fi
- if [ -z $SERVE_ADDR ];then
- SERVE_ADDR="0.0.0.0"
- fi
- if [ -z $ETCD_ADDR ];then
- ETCD_ADDR="127.0.0.1"
- fi
- if [ -z $ETCD_PORT ];then
- ETCD_PORT="2379"
- fi
- if [ -z $ENCRYPT_KEY ];then
- ENCRYPT_KEY="a95cbb574bdc905f9bf457820f1fa602"
- fi
- if [ -z $LOG_DIR ];then
- LOG_DIR="logs"
- fi
- PROJECT_PATH=$(cd `dirname $0`; pwd)
- SERVICE_NAME="${PROJECT_PATH##*/}"
- APP_NAME="${PROJECT_PATH##*/}"
- APP_SERVICE=conf/app.service
- APP_CONF=conf/app.conf
- sed -e "s/%APP_NAME%/$APP_NAME/g" ${APP_CONF}.in > ${APP_CONF}
- sed -i "s/%APP_NAME%/$APP_NAME/g" ${APP_CONF}
- sed -i "s/%RUNMODE%/$RUNMODE/g" ${APP_CONF}
- sed -i "s/%SERVE_ADDR%/$SERVE_ADDR/g" ${APP_CONF}
- sed -i "s/%SERVE_PORT%/$SERVE_PORT/g" ${APP_CONF}
- sed -i "s/%ETCD_ADDR%/$ETCD_ADDR/g" ${APP_CONF}
- sed -i "s/%ETCD_PORT%/$ETCD_PORT/g" ${APP_CONF}
- sed -i "s/%ENCRYPT_KEY%/$ENCRYPT_KEY/g" ${APP_CONF}
- sed -i "s/%LOG_DIR%/$LOG_DIR/g" ${APP_CONF}
- sed -i "s/%SERVICE_NAME%/$SERVICE_NAME/g" ${APP_CONF}
- sed -i "s/%PROJECT_NAME%/$PROJECT_NAME/g" ${APP_CONF}
- cat ${APP_CONF}
|