Last active
February 22, 2021 22:12
-
-
Save ianfoo/b40c5ff644280c85f59f397a6d75e62b to your computer and use it in GitHub Desktop.
Get the latest version of Go from golang.org for macOS (tested on amd64)
This file contains hidden or 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
| #!/usr/bin/env bash | |
| # | |
| # Drop this in your path and make it executable to install the latest | |
| # macOS version of Go from golang.org/dl. | |
| set -Eeuo pipefail | |
| go-get-latest-version-httpie () { | |
| http -F golang.org/VERSION m==text | |
| } | |
| go-get-latest-package-httpie () { | |
| local package=$1 | |
| http -q --download golang.org/dl/${package} | |
| } | |
| go-get-latest-version-curl () { | |
| curl -L "https://golang.org/VERSION?m=text" | |
| } | |
| go-get-latest-package-curl () { | |
| local package=$1 | |
| curl -sLO "https://golang.org/dl/${package}" | |
| } | |
| cleanup () { | |
| local package=${1:-} | |
| if [[ $package != "" ]]; then | |
| rm -f $1 | |
| fi | |
| cd - | |
| } | |
| install-latest () { | |
| cd $TMPDIR | |
| trap cleanup EXIT | |
| local arch=$1 | |
| local client=httpie | |
| if ! http --version >&/dev/null; then | |
| client=curl | |
| fi | |
| local version=$(go-get-latest-version-$client) | |
| [[ -z $version ]] && return 1 | |
| local package=${version}.darwin-${arch}.pkg | |
| go-get-latest-package-$client "$package" || return 1 | |
| trap "cleanup $package" EXIT | |
| sudo installer -pkg "$package" -target / | |
| } | |
| arch=amd64 | |
| if [[ $(uname -m) != 'x86_64' ]]; then | |
| arch=arm64 | |
| fi | |
| install-latest $arch |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment