Newer
Older
#!/bin/bash
#
# for windows and Mac check the README
#
if ! which go &>/dev/null; then
echo "Go is not installed or is not in \$PATH"
echo "giving up..."
exit
fi
PATH=$PATH:$(go env GOPATH)/bin
GOPATH=$(go env GOPATH)
PROG_VERSION="1.0"
BUILDTIME=$(date -u '+%Y-%m-%d_%H:%M:%S')
REPO_DIR=$(dirname $0)
if [ "$REPO_DIR" = '.' ]; then
REPO_DIR=`pwd`
fi
ln -sf "$REPO_DIR" "${GOPATH}/src/"
REPO_NAME=$(basename "$REPO_DIR")
cd "${GOPATH}/src/$REPO_NAME"
usage() {
echo "Usage: $(basename $0)"
echo " -h | --help [Print this help and exit]"
echo "OS ARCH"; go tool dist list | column -t -s '/' --table-columns =======,=======
eval set -- "$OPTS"
while true; do
case "$1" in
-h | --help)
usage
;;
;;
--arch)
shift
ARCH="$1"
;;
--)
shift
break
;;
esac
shift
done
if [ -z $OS ] || [ -z $ARCH ]; then
echo -e "\nYou need to supply OS and Architecture\n"
# env GOOS=windows GOARCH=amd64 go build -ldflags "-s -w -X main.appVersion=${PROG_VERSION} -X main.buildTime=${BUILDTIME}" .
env GOOS=$OS GOARCH=$ARCH go get -ldflags "-s -w -X main.appVersion=${PROG_VERSION} -X main.buildTime=${BUILDTIME}" .
if [ $? -gt 0 ]; then
echo -e "\nthere was an error while compiling the code\n"
exit
fi
[ -f $EXECUTABLE_PATH ] || EXECUTABLE_PATH="${GOPATH}/bin/${BIN_NAME}"
run_upx() {
if ! which upx &>/dev/null; then
echo "please download upx here: https://github.com/upx/upx/releases"
echo "and store the executable within your \$PATH"
exit
fi
upx --brute "$EXECUTABLE_PATH"
}
while true; do
echo -e "\nUPX degrades performances but in the case of acme-downloader it is not noticeable"
echo -e "UPX does not work on some OS/Arch combination (I haven't tried them all)\n"
read -p "Do you wish to run upx against ${BIN_NAME}? (y/n) " yn
case $yn in
[Yy]*)
echo ""
run_upx
break
;;
[Nn]*) break ;;
*)
echo "Please answer Y|y or N|n."
;;
esac
done
echo -e "\nthe binary was compiled and it is avilable as:\n - \"$EXECUTABLE_PATH\"\n"