2017-05-26 10:09:07 +00:00
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
|
|
# set -x -u
|
|
|
|
|
# 任务节点打包, 生成压缩包 gocron-node.zip或gocron-node.tar.gz
|
|
|
|
|
# ./build-node.sh -p windows -a amd64
|
|
|
|
|
# 参数含义
|
|
|
|
|
# -p 指定平台(windows|linux|darwin)
|
|
|
|
|
# -a 指定体系架构(amd64|386), 默认amd64
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 目标平台 windows,linux,darwin
|
|
|
|
|
OS=''
|
|
|
|
|
# 目标平台架构
|
|
|
|
|
ARCH=''
|
|
|
|
|
# 应用名称
|
|
|
|
|
APP_NAME='gocron-node'
|
2017-10-01 13:49:46 +00:00
|
|
|
|
# 版本号
|
|
|
|
|
VERSION=''
|
2017-05-26 10:09:07 +00:00
|
|
|
|
# 可执行文件名
|
|
|
|
|
EXEC_NAME=''
|
|
|
|
|
# 压缩包名称
|
|
|
|
|
COMPRESS_FILE=''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# -p 平台 -a 架构
|
2017-10-01 13:49:46 +00:00
|
|
|
|
while getopts "p:a:v:" OPT;
|
2017-05-26 10:09:07 +00:00
|
|
|
|
do
|
|
|
|
|
case $OPT in
|
|
|
|
|
p) OS=$OPTARG
|
|
|
|
|
;;
|
|
|
|
|
a) ARCH=$OPTARG
|
|
|
|
|
;;
|
2017-10-01 13:49:46 +00:00
|
|
|
|
v) VERSION=$OPTARG
|
|
|
|
|
;;
|
2017-05-26 10:09:07 +00:00
|
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
if [[ -z $OS ]];then
|
|
|
|
|
echo "平台不能为空"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [[ $OS != 'windows' && $OS != 'linux' && $OS != 'darwin' ]];then
|
|
|
|
|
echo '平台错误,支持的平台 windows linux darmin(osx)'
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [[ -z $ARCH ]];then
|
|
|
|
|
ARCH='amd64'
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [[ $ARCH != '386' && $ARCH != 'amd64' ]];then
|
|
|
|
|
echo 'arch错误,仅支持 386 amd64'
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2017-10-01 13:49:46 +00:00
|
|
|
|
if [[ -z $VERSION ]];then
|
|
|
|
|
echo '版本号不能为空'
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2017-05-26 10:09:07 +00:00
|
|
|
|
if [[ $OS = 'windows' ]];then
|
|
|
|
|
EXEC_NAME=${APP_NAME}.exe
|
2017-10-01 13:49:46 +00:00
|
|
|
|
COMPRESS_FILE=${APP_NAME}-v${VERSION}-${OS}-${ARCH}.zip
|
2017-05-26 10:09:07 +00:00
|
|
|
|
else
|
|
|
|
|
EXEC_NAME=${APP_NAME}
|
2017-10-01 13:49:46 +00:00
|
|
|
|
COMPRESS_FILE=${APP_NAME}-v${VERSION}-${OS}-${ARCH}.tar.gz
|
2017-05-26 10:09:07 +00:00
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo '开始编译任务节点'
|
|
|
|
|
if [[ $OS = 'windows' ]];then
|
2017-07-22 00:54:42 +00:00
|
|
|
|
GOOS=$OS GOARCH=$ARCH go build -tags node -ldflags '-w' -o $EXEC_NAME
|
2017-05-26 10:09:07 +00:00
|
|
|
|
else
|
|
|
|
|
GOOS=$OS GOARCH=$ARCH go build -tags node -ldflags '-w' -o $EXEC_NAME
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [[ $? != 0 ]];then
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
echo '编译完成'
|
|
|
|
|
|
|
|
|
|
if [[ $OS = 'windows' ]];then
|
|
|
|
|
zip -rq $COMPRESS_FILE $EXEC_NAME
|
|
|
|
|
else
|
|
|
|
|
tar czf $COMPRESS_FILE $EXEC_NAME
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rm $EXEC_NAME
|
|
|
|
|
|
|
|
|
|
echo '打包完成'
|
|
|
|
|
echo '生成压缩文件--' $COMPRESS_FILE
|