forked from wgpsec/ENScan_GO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
55 lines (49 loc) · 1.39 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
#!/bin/bash
appName="enscan"
builtAt="$(date +'%F %T %z')"
goVersion=$(go version | sed 's/go version //')
gitAuthor=$(git show -s --format='format:%aN <%ae>' HEAD)
gitCommit=$(git log --pretty=format:"%h" -1)
if [ "$1" == "release" ]; then
gitTag=$(git describe --abbrev=0 --tags)
else
gitTag=build-next
fi
echo "build version: $gitTag"
ldflags="\
-w -s \
-X 'github.com/wgpsec/ENScan/common.BuiltAt=$builtAt' \
-X 'github.com/wgpsec/ENScan/common.GoVersion=$goVersion' \
-X 'github.com/wgpsec/ENScan/common.GitAuthor=$gitAuthor' \
-X 'github.com/wgpsec/ENScan/common.GitCommit=$gitCommit' \
-X 'github.com/wgpsec/ENScan/common.GitTag=$gitTag' \
"
if [ "$1" == "release" ]; then
xgo -out enscan -ldflags="$ldflags" .
else
xgo -targets=linux/amd64,windows/amd64,darwin/amd64 -out enscan -ldflags="$ldflags" .
fi
mkdir "build"
mv enscan-* build
cd build || exit
upx -9 ./*
find . -type f -print0 | xargs -0 md5sum > md5.txt
cat md5.txt
# compress file (release)
if [ "$1" == "release" ]; then
mkdir compress
mv md5.txt compress
for i in `find . -type f -name "$appName-linux-*"`
do
tar -czvf compress/"$i".tar.gz "$i"
done
for i in `find . -type f -name "$appName-darwin-*"`
do
tar -czvf compress/"$i".tar.gz "$i"
done
for i in `find . -type f -name "$appName-windows-*"`
do
zip compress/$(echo $i | sed 's/\.[^.]*$//').zip "$i"
done
fi
cd ../..