-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.bash
executable file
·59 lines (50 loc) · 2.19 KB
/
build.bash
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
#!/bin/bash
set -ex
VERSION="$(git describe --tags)"
PACKAGE=$(basename ${PWD})
TARGET="bin"
build() {
if [[ -d ${TARGET} ]]; then
rm -rf ${TARGET}
fi
# Linux
export GOOS=linux GOARCH=amd64 CGO_ENABLED=0
go build -a -trimpath -ldflags="-X 'main.appVersion=${VERSION}' -X 'main.appBuildTime=$(date "+%FT%T%Z")' -X 'main.appCommit=$(git rev-parse HEAD)' -X 'main.appPlatform=${GOOS}/${GOARCH}' -X 'main.appGoVersion=$(go version | awk '{print $3}')'" -o ${TARGET}/${PACKAGE}_${VERSION}_${GOOS}_${GOARCH} cmd/*.go
export GOOS=linux GOARCH=arm64 CGO_ENABLED=0
go build -a -trimpath -ldflags="-X 'main.appVersion=${VERSION}' -X 'main.appBuildTime=$(date "+%FT%T%Z")' -X 'main.appCommit=$(git rev-parse HEAD)' -X 'main.appPlatform=${GOOS}/${GOARCH}' -X 'main.appGoVersion=$(go version | awk '{print $3}')'" -o ${TARGET}/${PACKAGE}_${VERSION}_${GOOS}_${GOARCH} cmd/*.go
# Mac
GOOS=darwin GOARCH=amd64 CGO_ENABLED=0
go build -a -trimpath -ldflags="-X 'main.appVersion=${VERSION}' -X 'main.appBuildTime=$(date "+%FT%T%Z")' -X 'main.appCommit=$(git rev-parse HEAD)' -X 'main.appPlatform=${GOOS}/${GOARCH}' -X 'main.appGoVersion=$(go version | awk '{print $3}')'" -o ${TARGET}/${PACKAGE}_${VERSION}_${GOOS}_${GOARCH} cmd/*.go
# Windows
GOOS=windows GOARCH=amd64 CGO_ENABLED=0
go build -a -trimpath -ldflags="-X 'main.appVersion=${VERSION}' -X 'main.appBuildTime=$(date "+%FT%T%Z")' -X 'main.appCommit=$(git rev-parse HEAD)' -X 'main.appPlatform=${GOOS}/${GOARCH}' -X 'main.appGoVersion=$(go version | awk '{print $3}')'" -o ${TARGET}/${PACKAGE}_${VERSION}_${GOOS}_${GOARCH} cmd/*.go
}
convert() {
local compressDir=upx
if [[ -d ${compressDir} ]]; then
rm -rf ${compressDir}
mkdir ${compressDir}
fi
for i in $(ls ${TARGET}); do upx -9 -o ${compressDir}/${i} ${TARGET}/${i}; done
rm -rf ${TARGET}
}
clean() {
go clean
rm -rf ${TARGET}
}
createService() {
cat <<'EOF' >/lib/systemd/system/gd.service
[Unit]
Description=Fetch DNS
After=network.target
After=mysql.service
[Service]
WorkingDirectory=/data/dns
ExecStart=/data/dns/gd -o hourly
ExecReload=/bin/kill -s HUP $MAINPID
Restart=always
[Install]
WantedBy=multi-user.target
EOF
}
$1