-
-
Save pivaldi/f153b36cf2c9bdeaacd37fbcf2d0a3ea to your computer and use it in GitHub Desktop.
update-golang.sh
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 | |
| set -e | |
| tmp=$(mktemp -d) | |
| pushd "$tmp" || exit 1 | |
| function cleanup { | |
| popd || exit 1 | |
| rm -rf "$tmp" | |
| } | |
| trap cleanup EXIT | |
| version=$(go tool dist version) | |
| release=$(wget -qO- "https://golang.org/VERSION?m=text") | |
| release_file="${release}.linux-amd64.tar.gz" | |
| if [[ $version == "$release" ]]; then | |
| echo "local Go version ${release} is latest." | |
| exit 0 | |
| else | |
| echo "local Go version ${version}, new release ${release} is available." | |
| fi | |
| echo "Downloading https://go.dev/dl/$release_file ..." | |
| curl -OL https://go.dev/dl/"$release_file" | |
| goroot=$(go env |grep GOROOT |cut -d'=' -f2 |tr -d '"') | |
| echo "removing folder $goroot" | |
| sudo rm -f "$goroot" | |
| sudo tar -C "${goroot//go}" -xzf "$release_file" | |
| version=$(go tool dist version) | |
| echo "local Go version is $version (latest)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment