Last active
April 3, 2025 08:01
-
-
Save theaog/e8923142320f57d2157dcb28b5cc6b0d 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 version |cut -d' ' -f3) | |
release=$(wget -qO- "https://golang.org/VERSION?m=text"| grep go) | |
release_file="${release}.linux-amd64.tar.gz" | |
if [[ $version == "$release" ]]; then | |
echo "local Go version ${release} is the 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 -rf "$goroot" | |
sudo tar -C "${goroot//go}" -xzf "$release_file" | |
version=$(go version |cut -d' ' -f3) | |
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
if you want to add to a cronjob: