Last active
December 15, 2023 05:58
-
-
Save hitalos/1165c8ddfa6d5002b57f1cfe12a15ebd to your computer and use it in GitHub Desktop.
Update Golang to latest version
This file contains 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
#!/bin/bash | |
source <(go env) | |
INFO=$(curl -sf 'https://go.dev/dl/?mode=json') | |
[[ "$?" -ne "0" ]] && echo "Error getting latest info" && exit 1 | |
FILEHASH=$(jq -r ".[0].files[] | select(.arch==\"$GOARCH\" and .os==\"$GOOS\") | \"\(.sha256) \(.filename)\"" <<< "$INFO") | |
FILENAME=${FILEHASH#* } | |
echo "Downloading $FILENAME" | |
curl --progress-bar -C - -fsLO "https://go.dev/dl/$FILENAME" | |
RESULT=$? | |
[[ "$RESULT" -eq "0" ]] || [[ "$RESULT" -eq "22" ]] && \ | |
sha256sum --check --quiet <<< "$FILEHASH" && \ | |
sudo rm -rf "$GOROOT" && \ | |
sudo tar -C "$(dirname \"$GOROOT\")" -xzf "$FILENAME" && \ | |
rm -f "$FILENAME" && \ | |
echo OK |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment