-
Notifications
You must be signed in to change notification settings - Fork 119
/
build.sh
executable file
·102 lines (77 loc) · 1.86 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash
#
# build.sh compiles dnote binary for target platforms
# it is resonsible for creating distributable files that can
# be released by a human or a script
# use: ./scripts/build.sh 0.4.8
set -eu
version="$1"
basedir="$GOPATH/src/github.com/dnote/cli"
TMP="$basedir/build"
command_exists () {
command -v "$1" >/dev/null 2>&1;
}
if ! command_exists shasum; then
echo "please install shasum"
exit 1
fi
if [ $# -eq 0 ]; then
echo "no version specified."
exit 1
fi
if [[ $1 == v* ]]; then
echo "do not prefix version with v"
exit 1
fi
build() {
# init build dir
rm -rf "$TMP"
mkdir "$TMP"
# fetch tool
go get -u github.com/karalabe/xgo
pushd "$basedir"
# build linux
xgo --targets="linux/amd64"\
-ldflags "-X main.apiEndpoint=https://api.dnote.io -X main.versionTag=$version" .
mkdir "$TMP/linux"
mv cli-linux-amd64 "$TMP/linux/dnote"
# build darwin
xgo --targets="darwin/amd64"\
-ldflags "-X main.apiEndpoint=https://api.dnote.io -X main.versionTag=$version" .
mkdir "$TMP/darwin"
mv cli-darwin-10.6-amd64 "$TMP/darwin/dnote"
# build windows
xgo --targets="windows/amd64"\
-ldflags "-X main.apiEndpoint=https://api.dnote.io -X main.versionTag=$version" .
mkdir "$TMP/windows"
mv cli-windows-4.0-amd64.exe "$TMP/windows/dnote.exe"
popd
}
get_buildname() {
os=$1
echo "dnote_${version}_${os}_amd64"
}
calc_checksum() {
os=$1
pushd "$TMP/$os"
buildname=$(get_buildname "$os")
mv dnote "$buildname"
shasum -a 256 "$buildname" >> "$TMP/dnote_${version}_checksums.txt"
mv "$buildname" dnote
popd
}
build_tarball() {
os=$1
buildname=$(get_buildname "$os")
pushd "$TMP/$os"
cp "$basedir/LICENSE" .
cp "$basedir/README.md" .
tar -zcvf "../${buildname}.tar.gz" ./*
popd
}
build
calc_checksum darwin
calc_checksum linux
build_tarball windows
build_tarball darwin
build_tarball linux