-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·54 lines (38 loc) · 1.2 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
#!/bin/bash
export VERSION=$1
export SIGNER=$2
export PROGRAM_NAME=clipmerge
if [ -z "$VERSION" ]; then
echo "VERSION is not defined"
exit 1
fi
if [ -z "$SIGNER" ]; then
echo "SIGNER id is not defined"
exit 1
fi
build_go_program() {
currentDateTime=$(date '+%Y-%m-%d@%H:%M:%S-%Z')
builderArch=$(uname -m)
builderOS=$(uname -s)
echo "Building for ${GOOS} ${GOARCH}"
go build -ldflags "-X main.version=${VERSION} -X main.metaBuildTime=${currentDateTime} -X main.metaBuilderOS=${builderOS} -X main.metaBuilderArch=${builderArch}" -o bin/${PROGRAM_NAME}_${VERSION}_${GOOS}_${GOARCH}
checksum=$(sha256sum bin/${PROGRAM_NAME}_${VERSION}_${GOOS}_${GOARCH} | awk '{print $1}')
echo "${checksum} - ${PROGRAM_NAME}_${VERSION}_${GOOS}_${GOARCH}" >> "./bin/SHA256SUMS"
}
clean_bin() {
echo "Cleaning bin dir"
rm -r "./bin"
mkdir "./bin"
}
clean_bin
touch "./bin/SHA256SUMS"
# For Linux (64-bit)
GOOS=linux GOARCH=amd64
build_go_program
# For Windows (64-bit)
GOOS=windows GOARCH=amd64
build_go_program
# For FreeBSD (64-bit)
GOOS=freebsd GOARCH=amd64
build_go_program
gpg --armor --detach-sign --output "./bin/SHA256SUMS.asc" --default-key "$SIGNER" ./bin/SHA256SUMS