-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sh
executable file
·83 lines (75 loc) · 1.44 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
#! /bin/sh
##
## build.sh --
## Build xcluster-cni.
##
## Commands;
##
prg=$(basename $0)
dir=$(dirname $0); dir=$(readlink -f $dir)
tmp=/tmp/${prg}_$$
die() {
echo "ERROR: $*" >&2
rm -rf $tmp
exit 1
}
help() {
grep '^##' $0 | cut -c3-
rm -rf $tmp
exit 0
}
test -n "$1" || help
echo "$1" | grep -qi "^help\|-h" && help
log() {
echo "$prg: $*" >&2
}
dbg() {
test -n "$__verbose" && echo "$prg: $*" >&2
}
findf() {
f=$ARCHIVE/$1
test -r $f || f=$HOME/Downloads/$1
test -r $f || die "Not found [$f]"
}
## env
## Print environment.
##
cmd_env() {
test "$cmd" = "env" && set | grep -E '^(__.*)='
}
## binaries [--version=]
## Build binaries in ./_output
cmd_binaries() {
cmd_env
cd $dir
mkdir -p _output
test -n "$__version" || __version=$(date +%Y.%m.%d-%H.%M.%S)
CGO_ENABLED=0 GOOS=linux go build \
-ldflags "-extldflags '-static' -X main.version=$__version $LDFLAGS" \
-o _output ./cmd/... || die "go build"
strip _output/*
}
##
# Get the command
cmd=$1
shift
grep -q "^cmd_$cmd()" $0 $hook || die "Invalid command [$cmd]"
while echo "$1" | grep -q '^--'; do
if echo $1 | grep -q =; then
o=$(echo "$1" | cut -d= -f1 | sed -e 's,-,_,g')
v=$(echo "$1" | cut -d= -f2-)
eval "$o=\"$v\""
else
o=$(echo "$1" | sed -e 's,-,_,g')
eval "$o=yes"
fi
shift
done
unset o v
long_opts=`set | grep '^__' | cut -d= -f1`
# Execute command
trap "die Interrupted" INT TERM
cmd_$cmd "$@"
status=$?
rm -rf $tmp
exit $status