Last active
July 25, 2024 07:43
-
-
Save zhangyoufu/6c60829af1ac61f80484c954360882a1 to your computer and use it in GitHub Desktop.
Download latest Go release and install to /opt
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
#!/bin/sh | |
not_available() { echo -- "$1 is not available"; exit 1; } | |
ensure_command_available() { which -- "$1" >/dev/null && return; not_available "$1"; } | |
ensure_gnu_tar() { tar --version | grep -F 'GNU tar' >/dev/null || not_available 'GNU tar'; } | |
ensure_command_available curl | |
ensure_command_available jq | |
ensure_gnu_tar | |
FILENAME=$(curl -fsSL 'https://golang.google.cn/dl/?mode=json' | jq -r 'map(select(.stable)) | .[0].files | map(select(.os == "linux" and .arch == "amd64")) | .[0].filename') | |
rm -rf /opt/go | |
echo "Downloading ${FILENAME}" | |
curl -fSL "https://dl.google.com/go/${FILENAME}" | tar --extract --gzip --directory=/opt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment