Skip to content

Instantly share code, notes, and snippets.

@tonistiigi
Created September 25, 2018 04:17
Show Gist options
  • Save tonistiigi/8125e6044ca9bdc5ffe2732f1663be40 to your computer and use it in GitHub Desktop.
Save tonistiigi/8125e6044ca9bdc5ffe2732f1663be40 to your computer and use it in GitHub Desktop.
#!/usr/bin/env sh
set -eu -o pipefail
: ${TARGETPLATFORM=}
: ${TARGETOS=}
: ${TARGETARCH=}
: ${TARGETVARIANT=}
if [ ! -z "$TARGETPLATFORM" ]; then
os="$(echo $TARGETPLATFORM | cut -d"/" -f1)"
arch="$(echo $TARGETPLATFORM | cut -d"/" -f2)"
if [ ! -z "$os" ] && [ ! -z "$arch" ]; then
export GOOS="$os"
export GOARCH="$arch"
if [ "$arch" == "arm" ]; then
case "$(echo $TARGETPLATFORM | cut -d"/" -f3)" in
"v5")
export GOARM="5"
;;
"v6")
export GOARM="6"
;;
*)
export GOARM="7"
;;
esac
fi
fi
fi
if [ ! -z "$TARGETOS" ]; then
export GOOS="$TARGETOS"
fi
if [ ! -z "$TARGETARCH" ]; then
export GOARCH="$TARGETARCH"
fi
if [ ! -z "$TARGETVARIANT" ]; then
if [ "$GOARCH" == "arm" ]; then
case "$TARGETVARIANT" in
"v5")
export GOARM="5"
;;
"v6")
export GOARM="6"
;;
*)
export GOARM="7"
;;
esac
fi
fi
exec /usr/local/go/bin/go "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment