-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.sh
87 lines (72 loc) · 2.7 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env bash
OUTPUT_DIR=$1
if [[ -z ${OUTPUT_DIR} ]]; then
OUTPUT_DIR="build"
fi
BUILD_NUMBER=$(date -u '+%Y%m%d.%H%M.%S')
BUILD_COMMIT=$(git rev-list -1 HEAD)
BUILD_VERSION=$(git tag | tail -1)
BINARY_NAME="geoip"
function pack() {
PACKAGE_NAME=${BINARY_NAME}-${BUILD_VERSION}-${1}
PACKAGE_DIR=${OUTPUT_DIR}/${PACKAGE_NAME}
OUTPUT_BINARY=${OUTPUT_DIR}/${2}
echo "Signing ${OUTPUT_BINARY}"
mkdir ${PACKAGE_DIR}
md5sum ${OUTPUT_BINARY} | sed 's/\ .*\// /g' >> ${PACKAGE_DIR}/md5.hash
sha1sum ${OUTPUT_BINARY} | sed 's/\ .*\// /g' >> ${PACKAGE_DIR}/sha1.hash
sha256sum ${OUTPUT_BINARY} | sed 's/\ .*\// /g' >> ${PACKAGE_DIR}/sha256.hash
sha512sum ${OUTPUT_BINARY} | sed 's/\ .*\// /g' >> ${PACKAGE_DIR}/sha512.hash
echo "Packing ${PACKAGE_NAME}"
cp ${OUTPUT_BINARY} ${PACKAGE_DIR}
cp README.md ${PACKAGE_DIR}
cp LICENSE ${PACKAGE_DIR}
cp -r gui ${PACKAGE_DIR}
rm -r ${PACKAGE_DIR}/gui/.git
cd ${OUTPUT_DIR}
sync
tar --owner=0 --group=0 -czf ${PACKAGE_NAME}.tar.gz ${PACKAGE_NAME}
rm -rf ${PACKAGE_NAME}
cd - > /dev/null
}
echo "-------------------------------------"
echo "Build directory: ${OUTPUT_DIR}"
echo "Build version: ${BUILD_VERSION}"
echo "Build number: ${BUILD_NUMBER}"
echo "Build commit: ${BUILD_COMMIT}"
echo "-------------------------------------"
echo ""
echo "-------------------------------------"
echo "Build preparation"
echo "Generating assets.."
go generate
echo "-------------------------------------"
echo ""
echo "-------------------------------------"
echo "Building individual distributions"
echo "Building for Linux.."
go build -ldflags "-w -s -X main.buildNumber=${BUILD_NUMBER} -X main.buildVersion=${BUILD_VERSION}" -o ${OUTPUT_DIR}/${BINARY_NAME}
sleep 1
pack linux-amd64 ${BINARY_NAME}
echo "-------------------------------------"
echo ""
echo "Building for Windows 64bit.."
GOOS=windows GOARCH=amd64 go build -ldflags "-w -s -X main.buildNumber=${BUILD_NUMBER} -X main.buildVersion=${BUILD_VERSION}" -o ${OUTPUT_DIR}/${BINARY_NAME}_x86.exe
sleep 1
pack windows-x86 ${BINARY_NAME}_x86.exe
echo "-------------------------------------"
echo ""
echo "Building for Windows 32bit.."
GOOS=windows GOARCH=386 go build -ldflags "-w -s -X main.buildNumber=${BUILD_NUMBER} -X main.buildVersion=${BUILD_VERSION}" -o ${OUTPUT_DIR}/${BINARY_NAME}_i686.exe
sleep 1
pack windows-i686 ${BINARY_NAME}_i686.exe
echo "-------------------------------------"
echo ""
echo "Building for OsX 64bit.."
GOOS=darwin GOARCH=amd64 go build -ldflags "-w -s -X main.buildNumber=${BUILD_NUMBER} -X main.buildVersion=${BUILD_VERSION}" -o ${OUTPUT_DIR}/${BINARY_NAME}-darwin
sleep 1
pack darwin-amd64 ${BINARY_NAME}-darwin
echo "-------------------------------------"
echo ""
echo "Build finished!"
echo ""