Last active
April 6, 2024 23:00
-
-
Save 808codist/fe5c8d2118afc1a05ed11d6b86da92b3 to your computer and use it in GitHub Desktop.
When *upgrading* your Go version to latest, use this script to download the latest version for your distro & arch. (This script assumes you already have Go installed.)
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 | |
# source: https://gist.github.com/808codist/fe5c8d2118afc1a05ed11d6b86da92b3 | |
set -o errexit # exit on 1st error | |
set -o nounset # referencing unset vars is an error | |
dlUrl='https://go.dev/dl/' | |
allVersionsUrl="$dlUrl?mode=json" | |
osArch="$(go env GOHOSTOS)-$(go env GOARCH)" | |
dlProperties=/tmp/goVersionDownloadProperties.txt | |
# get all versions and search for 1st line with $osArch plus 6 lines after | |
# (assuming 1st == latest) | |
curl -s "$allVersionsUrl" | grep -m 1 -A 6 "$osArch" > $dlProperties | |
# for all lines, ' "foo": "bar",' --> 'foo="bar"' | |
sed -i 's/[[:space:]]//g' $dlProperties # rm spaces | |
sed -i 's/^"//' $dlProperties # rm starting quote | |
sed -i 's/":/=/' $dlProperties # ": --> = | |
sed -i 's/,$//' $dlProperties # rm any trailing comma | |
# shellcheck disable=SC1090 | |
. $dlProperties # set filename and sha256 variables (among others) | |
rm -f "${filename:?}" # rm any tar ball | |
echo "SHA256 ($filename) = ${sha256:?}" > "/tmp/$filename.sum" # create checksum file | |
wget "$dlUrl/$filename" # download the tar ball | |
# verify check sum | |
sha256sum -c "/tmp/$filename.sum" && \ | |
echo "to install run:" && \ | |
echo " sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf ${filename}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment