-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sh
executable file
·101 lines (89 loc) · 1.52 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/sh
set -eu
build() {
VERSION=$(git describe --tags)
BUILD=$(date +%FT%T%z)
ARCHLIST="$1"
OSLIST="$2"
BUILD_DIR="$3"
echo "$VERSION"
echo "$BUILD"
mkdir -p "$BUILD_DIR"
cd "$CUR_PATH/cmd/dnsbl-check"
for os in $OSLIST
do
for arch in $ARCHLIST
do
echo "building $os.$arch"
if go tool dist list | grep -q "^${os}/${arch}$"
then
GOOS="$os" GOARCH="$arch" go build -ldflags "-w -s -X main.version=${VERSION} -X main.build=${BUILD}" -o "$BUILD_DIR/$FILE_NAME.$os.$arch"
fi
done
done
}
remove() {
BUILD_DIR="$1"
for os in $OSLIST
do
for arch in $ARCHLIST
do
if [ -f "$BUILD_DIR/$FILE_NAME.$os.$arch" ]
then
echo "removing $os.$arch"
rm "$BUILD_DIR/$FILE_NAME.$os.$arch"
fi
done
done
}
REMOVE=0
OSLIST="linux darwin"
ARCHLIST="amd64 arm64 arm"
CUR_PATH="$(dirname "$(realpath "$0")")"
BUILD_DIR="$CUR_PATH/build"
FILE_NAME="dnsbl-check"
BUILD=0
if [ $# -lt 1 ];then
echo "Command required, available commands are \"test\" and \"build\"" >&2
exit 1
fi
subcommand="$1"
shift
case "$subcommand" in
"test")
go test -v -tags test ./...
return
;;
"build")
BUILD=1;
;;
*)
echo "Invalid command, available commands are \"test\" and \"build\"" >&2
exit 1
;;
esac
while getopts "ra:o:s:b:" opt
do
case "$opt" in
"r")
REMOVE=1
;;
"a")
ARCHLIST="$OPTARG"
;;
"o")
OSLIST="$OPTARG"
;;
"b")
BUILD_DIR="$OPTARG"
;;
[?])
exit 1
;;
esac
done
if [ $REMOVE -eq 1 ];then
remove "$BUILD_DIR"
else
build "$ARCHLIST" "$OSLIST" "$BUILD_DIR"
fi