This repository has been archived by the owner on Oct 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#!/usr/bin/env bash | ||
|
||
name=plexStats | ||
|
||
checkCommand() { | ||
which "$1" >/dev/null 2>&1 | ||
if [ "$?" != "0" ]; then | ||
echo Please make sure the following command is available: "$1" >&2 | ||
exit "$?" | ||
fi | ||
} | ||
|
||
checkCommand go | ||
checkCommand tar | ||
checkCommand zip | ||
|
||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | ||
|
||
# NOTE: The build process is somewhat similar to https://github.com/syncthing/syncthing, thanks for that! | ||
platforms=( | ||
linux-amd64 windows-amd64 darwin-amd64 dragonfly-amd64 freebsd-amd64 netbsd-amd64 openbsd-amd64 solaris-amd64 | ||
freebsd-386 linux-386 netbsd-386 openbsd-386 windows-386 | ||
linux-arm linux-arm64 linux-ppc64 linux-ppc64le | ||
) | ||
|
||
cd "$DIR" | ||
commit="$(git rev-parse --short HEAD 2>/dev/null)" | ||
date="$(date --iso-8601=seconds)" | ||
|
||
if [ "$commit" == "" ]; then | ||
commit="unknown" | ||
fi | ||
|
||
if [ "$1" == "" ]; then | ||
echo You didn\'t provide a version string as the first parameter, setting version to \"unknown\". | ||
version="unknown" | ||
else | ||
version="$1" | ||
fi | ||
|
||
rm -Rf ./bin/ | ||
mkdir ./bin/ 2>/dev/null | ||
|
||
for plat in "${platforms[@]}"; do | ||
echo Building "$plat" ... | ||
|
||
GOOS="${plat%-*}" | ||
GOARCH="${plat#*-}" | ||
|
||
if [ "$GOOS" != "windows" ]; then | ||
tmpFile="/tmp/${name}/bin/${name}" | ||
else | ||
tmpFile="/tmp/${name}/bin/${name}.exe" | ||
fi | ||
|
||
GOOS="${plat%-*}" GOARCH="${plat#*-}" go build -ldflags '-X main.VERSION='"$version"' -X main.BUILD_COMMIT='"$commit"' -X main.BUILD_DATE='"$date" \ | ||
-o "$tmpFile" "$DIR"/*.go | ||
|
||
if [ "$?" != 0 ]; then | ||
echo Build failed! >&2 | ||
exit "$?" | ||
fi | ||
|
||
if [ "$GOOS" != "windows" ]; then | ||
tarPath="$DIR"/bin/${name}-"$plat".tar.gz | ||
echo Build succeeded, creating "$tarPath" ... | ||
tar -czf "$tarPath" -C "${tmpFile%/*}" ${name} | ||
else | ||
zipPath="$DIR"/bin/${name}-"$plat".zip | ||
echo Build succeeded, creating "$zipPath" ... | ||
zip -j "$zipPath" "$tmpFile" | ||
fi | ||
|
||
if [ "$?" != 0 ]; then | ||
echo Failed to pack the binary! >&2 | ||
exit "$?" | ||
fi | ||
echo Done! | ||
|
||
rm "$tmpFile" | ||
|
||
echo | ||
done |