-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.sh
70 lines (54 loc) · 1.73 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
#!/bin/bash
# Thanks to https://github.com/bettercap/bettercap/build.sh by @evilsocket
BUILD_FOLDER=build
VERSION=v$(cat cmd/root.go | grep Version | cut -d '"' -f 2)
create_exe_archive() {
OUTPUT=$1
echo "@ Creating archive $OUTPUT ..."
zip -j "$OUTPUT" hosty.exe ../README.md ../LICENSE > /dev/null
rm -rf hosty.exe
}
create_archive() {
OUTPUT=$1
echo "@ Creating archive $OUTPUT ..."
zip -j "$OUTPUT" hosty ../README.md ../LICENSE > /dev/null
rm -rf hosty
}
build_linux_amd64() {
echo "@ Building linux/amd64 ..."
GOOS="linux" GOARCH="amd64" go build -o hosty ..
}
build_windows_amd64() {
echo "@ Building windows/amd64"
GOOS="windows" GOARCH="amd64" go build -o hosty.exe ..
}
build_darwin_amd64() {
echo "@ Building darwin/amd64"
GOOS="darwin" GOARCH="amd64" go build -o hosty ..
}
# cleanup build environment
rm -rf $BUILD_FOLDER
mkdir $BUILD_FOLDER
cd $BUILD_FOLDER
# check arguments
if [ -z "$1" ]
then
WHAT=all
else
WHAT="$1"
fi
printf "@ Building for $WHAT ...\n\n"
if [[ "$WHAT" == "all" || "$WHAT" == "linux_amd64" ]]; then
build_linux_amd64 && create_archive hosty_linux_amd64_$VERSION.zip
sha256sum ./hosty_linux_amd64_$VERSION.zip > hosty_linux_amd64_$VERSION.sha256
fi
if [[ "$WHAT" == "all" || "$WHAT" == "darwin_amd64" ]]; then
build_darwin_amd64 && create_archive hosty_darwin_amd64_$VERSION.zip
sha256sum ./hosty_darwin_amd64_$VERSION.zip > hosty_darwin_amd64_$VERSION.sha256
fi
if [[ "$WHAT" == "all" || "$WHAT" == "windows" || "$WHAT" == "win" ]]; then
build_windows_amd64 && create_exe_archive hosty_windows_amd64_$VERSION.zip
sha256sum ./hosty_windows_amd64_$VERSION.zip > hosty_windows_amd64_$VERSION.sha256
fi
du -sh *
cd ..