diff --git a/build.sh b/build.sh index b94f3695d3cbf5b2b229d8f23c392261fc466baf..ade9464d78327026c9b80959820ec539caa37e0d 100755 --- a/build.sh +++ b/build.sh @@ -2,6 +2,11 @@ # # 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 BIN_NAME=acme-downloader PATH=$PATH:$(go env GOPATH)/bin GOPATH=$(go env GOPATH) @@ -21,14 +26,14 @@ usage() { echo "Usage: $(basename $0)" echo " -h | --help [Print this help and exit]" echo " --os=OS (Compile binary for this OS)" - echo " --arch=ARCH (Compile binary for this architecture)" + echo " --arch=ARCH (Compile binary for this Architecture)" echo "" - echo " Below is a list of supported combinations (1st column: OS / 2nd column: Arch):" + echo " Below is a list of supported OS/Arch combinations:" echo "OS ARCH"; go tool dist list | column -t -s '/' --table-columns =======,======= exit } -OPTS=$(getopt -o "h" --longoptions "help,platform:,arch:" -- "$@") +OPTS=$(getopt -o "h" --longoptions "help,os:,arch:" -- "$@") eval set -- "$OPTS" while true; do @@ -36,9 +41,9 @@ while true; do -h | --help) usage ;; - --platform) + --os) shift - PLATFORM="$1" + OS="$1" ;; --arch) shift @@ -52,28 +57,28 @@ while true; do shift done -if [ -z $PLATFORM -o -z $ARCH ]; then - echo -e "\nYou need to supply platform and architecture\n" +if [ -z $OS ] || [ -z $ARCH ]; then + echo -e "\nYou need to supply OS and Architecture\n" usage fi -if [ "$PLATFORM" == "windows" ]; then +if [ "$OS" == "windows" ]; then BIN_NAME="${BIN_NAME}.exe" fi # env GOOS=windows GOARCH=amd64 go build -ldflags "-s -w -X main.appVersion=${PROG_VERSION} -X main.buildTime=${BUILDTIME}" . -env GOOS=$PLATFORM GOARCH=$ARCH go get -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 -EXECUTABLE_PATH="${GOPATH}/bin/${PLATFORM}_${ARCH}/${BIN_NAME}" +EXECUTABLE_PATH="${GOPATH}/bin/${OS}_${ARCH}/${BIN_NAME}" [ -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 "please download upx here: https://github.com/upx/upx/releases" echo "and store the executable within your \$PATH" exit fi @@ -82,7 +87,7 @@ run_upx() { while true; do echo -e "\nUPX degrades performances but in the case of acme-downloader it is not noticeable" - echo -e "UPX may or may not work for a specific platform (I haven't tried all the combinations)\n" + 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]*)