-
Notifications
You must be signed in to change notification settings - Fork 1
/
manage.sh
executable file
·82 lines (69 loc) · 2.06 KB
/
manage.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
#!/bin/bash
set -e
cmd="$1"
if test ! "$cmd"; then
echo "command required."
echo
echo "available commands:"
echo " build build project"
echo " clean removes generated files"
echo " deps.update update project dependencies"
echo " release build project for distribution"
exit 1
fi
shift
rest=$*
if test "$cmd" = "build"; then
# CGO_ENABLED=0 skips CGO and linking against glibc to build static binaries.
# -v 'verbose'
CGO_ENABLED=0 go build \
-v
exit 0
elif test "$cmd" = "clean"; then
# *--maintainers.txt - downloaded from repositories
# linux-amd64* linux-arm64* - generated by the 'release' command.
shopt -s nullglob # continue when glob below is empty
rm -fv *--maintainers.txt linux-amd64* linux-arm64*
exit 0
elif test "$cmd" = "deps.update"; then
# -u 'update modules [...] to use newer minor or patch releases when available'
go get -u
go mod tidy
./manage.sh build
exit 0
elif test "$cmd" = "release"; then
# GOOS is 'Go OS' and is being explicit in which OS to build for.
# CGO_ENABLED=0 skips CGO and linking against glibc to build static binaries.
# ld -s is 'disable symbol table'
# ld -w is 'disable DWARF generation'
# -trimpath removes leading paths to source files
# -v 'verbose'
# -o 'output'
GOOS=linux CGO_ENABLED=0 go build \
-ldflags="-s -w" \
-trimpath \
-v \
-o linux-amd64
sha256sum linux-amd64 > linux-amd64.sha256
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build \
-ldflags="-s -w" \
-trimpath \
-v \
-o linux-arm64
sha256sum linux-arm64 > linux-arm64.sha256
echo ---
echo "wrote linux-amd64"
echo "wrote linux-amd64.sha256"
echo "wrote linux-arm64"
echo "wrote linux-arm64.sha256"
exit 0
elif test "$cmd" = "update-deps"; then
# -u 'update modules [...] to use newer minor or patch releases when available'
go get -u
go mod tidy
./manage.sh build
exit 0
# ...
fi
echo "unknown command: $cmd"
exit 1