diff --git a/build-binary-for-win-64.sh b/build-binary-for-win-64.sh deleted file mode 100755 index 2074964731725ad89b889e0f164c2ca4042f2a12..0000000000000000000000000000000000000000 --- a/build-binary-for-win-64.sh +++ /dev/null @@ -1,53 +0,0 @@ -#!/bin/bash -# -# for windows and Mac check the README -# -BIN_NAME=acme-downloader.exe -PATH=$PATH:$(go env GOPATH)/bin -GOPATH=$(go env GOPATH) -PROG_VERSION="1.0" -BUILDTIME=$(date -u '+%Y-%m-%d_%H:%M:%S') -export BIN_NAME PATH GOPATH PROG_VERSION BUILDTIME - -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" - -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 ${GOPATH}/bin/windows_amd64/${BIN_NAME} -} - - -# env GOOS=windows GOARCH=amd64 go build -ldflags "-s -w -X main.appVersion=${PROG_VERSION} -X main.buildTime=${BUILDTIME}" . -env GOOS=windows GOARCH=amd64 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 - -while true; do - echo -e "\nUPX degrades performances but in the case of acme-downloader it is not noticeable\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 - ${GOPATH}/bin/windows_amd64/${BIN_NAME}\n" diff --git a/build.sh b/build.sh new file mode 100755 index 0000000000000000000000000000000000000000..95ce1681419caa407178d11be265c5e363a494ee --- /dev/null +++ b/build.sh @@ -0,0 +1,95 @@ +#!/bin/bash +# +# for windows and Mac check the README +# +BIN_NAME=acme-downloader.exe +PATH=$PATH:$(go env GOPATH)/bin +GOPATH=$(go env GOPATH) +PROG_VERSION="1.0" +BUILDTIME=$(date -u '+%Y-%m-%d_%H:%M:%S') +export BIN_NAME PATH GOPATH PROG_VERSION BUILDTIME + +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 (Create binary for this OS)" + echo " --arch (Compile for this architecture)" + echo "" + echo " Below is a list of supported combinations (1st column: OS / 2nd column: Arch):" + go tool dist list|awk -F'/' '{printf "OS: "$1"\011=> Arch: "$2"\n"}' + exit +} + +OPTS=$(getopt -o "h" --longoptions "help,platform:,arch:" -- "$@") +eval set -- "$OPTS" + +while true; do + case "$1" in + -h | --help) + usage + ;; + --platform) + shift + PLATFORM="$1" + ;; + --arch) + shift + ARCH="$1" + ;; + --) + shift + break + ;; + esac + shift +done + +if [ -z $PLATFORM -o -z $ARCH ]; then + echo -e "\nYou need to supply platform and architecture\n" + usage +fi + +EXECUTABLE_PATH="${GOPATH}/bin/${PLATFORM}_${ARCH}/${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" +} + +# 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}" . +if [ $? -gt 0 ]; then + echo -e "\nthere was an error while compiling the code\n" + exit +fi + +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 them)\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"