-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·56 lines (41 loc) · 1.38 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash -eu
SCRIPT_DIR=$(cd $(dirname $0); pwd)
VERSION=`cat ./global/version.go | grep -o "Version.*\".*\"" | sed -e 's/.*= //g' -e 's/"//g'`
BIN_BASENAME=zabbix-getter
ENTRYPOINT=zabbix-getter.go
BUILD_DIR=./build
BIN_DIR=${SCRIPT_DIR}/${BUILD_DIR}/bin
WORK_DIR=${SCRIPT_DIR}/${BUILD_DIR}/work
RELEASE_DIR=${SCRIPT_DIR}/${BUILD_DIR}/release
# delete build dir
rm -rf ${BUILD_DIR}
mkdir -p ${BIN_DIR}
mkdir -p ${RELEASE_DIR}
mkdir -p ${WORK_DIR}
cp LICENSE ${WORK_DIR}
cp README.md ${WORK_DIR}
function build_unixlike () {
# $1 OS $2 ARCH
echo Building $1 $2 binary
FINAL_PATH=${RELEASE_DIR}/${BIN_BASENAME}_${VERSION}_$1_$2.tar.gz
GOOS=$1 GOARCH=$2 CGO_ENABLED=0 go build -o ${BIN_DIR}/${BIN_BASENAME} ${ENTRYPOINT}
# copy bin to work
cp ${BIN_DIR}/${BIN_BASENAME} ${WORK_DIR}/
# copyback bin
cp ${BIN_DIR}/${BIN_BASENAME} ${BIN_DIR}/${BIN_BASENAME}_$1_$2
ORG_DIR=`pwd`
cd ${WORK_DIR}
tar -cvzf ${FINAL_PATH} --exclude "*.tar.gz" ./*
cd ${ORG_DIR}
echo "done => ${FINAL_PATH}"
}
# Windows
echo Building Windows binary
GOOS=windows GOARCH=386 go build -o ${BIN_DIR}/${BIN_BASENAME}.exe ${ENTRYPOINT}
zip ${RELEASE_DIR}/${BIN_BASENAME}_${VERSION}_win32.zip ${BIN_DIR}/${BIN_BASENAME}.exe
# Unixlike
build_unixlike linux amd64
build_unixlike linux arm
build_unixlike linux arm64
build_unixlike darwin amd64
build_unixlike darwin arm64