78 lines
1.9 KiB
Bash
Executable File
78 lines
1.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -eo pipefail
|
|
|
|
declare -r GO_VERSION=1.18.1
|
|
|
|
# Hashes are from the table at https://golang.org/dl/
|
|
function go_hash () {
|
|
case $1 in
|
|
linux_amd64)
|
|
echo b3b815f47ababac13810fc6021eb73d65478e0b2db4b09d348eefad9581a2334
|
|
;;
|
|
linux_arm64)
|
|
echo 56a91851c97fb4697077abbca38860f735c32b38993ff79b088dac46e4735633
|
|
;;
|
|
mac)
|
|
echo 63e5035312a9906c98032d9c73d036b6ce54f8632b194228bd08fe3b9fe4ab01
|
|
;;
|
|
windows)
|
|
echo c30bc3f1f7314a953fe208bd9cd5e24bd9403392a6c556ced3677f9f70f71fe1
|
|
;;
|
|
esac
|
|
}
|
|
|
|
function install_go_linux () {
|
|
local -r arch=$(dpkg --print-architecture)
|
|
ARCHIVE=go${GO_VERSION}.linux-${arch}.tar.gz
|
|
wget https://golang.org/dl/${ARCHIVE}
|
|
echo "$(go_hash linux_${arch}) ${ARCHIVE}" | sha256sum --check --
|
|
tar -C $1 -xzf ${ARCHIVE}
|
|
rm ${ARCHIVE}
|
|
}
|
|
|
|
function install_go_mac () {
|
|
ARCHIVE=go${GO_VERSION}.darwin-amd64.tar.gz
|
|
wget https://golang.org/dl/${ARCHIVE}
|
|
echo "$(go_hash mac) ${ARCHIVE}" | shasum -a 256 --check -
|
|
tar -C $1 -xzf ${ARCHIVE}
|
|
rm ${ARCHIVE}
|
|
}
|
|
|
|
function install_go_windows () {
|
|
ARCHIVE=go${GO_VERSION}.windows-amd64.zip
|
|
wget https://golang.org/dl/${ARCHIVE}
|
|
echo "$(go_hash windows) ${ARCHIVE}" | sha256sum --check --
|
|
unzip -qq -d $1 ${ARCHIVE}
|
|
rm ${ARCHIVE}
|
|
}
|
|
|
|
function main () {
|
|
if [[ $# != 1 ]]; then
|
|
>&2 echo Usage: $0 '<install-dir>'
|
|
exit 1
|
|
fi
|
|
local -r install_dir=$1
|
|
|
|
rm -rf "$install_dir"
|
|
mkdir -p "$install_dir"
|
|
case $(uname) in
|
|
Linux)
|
|
install_go_linux "$install_dir"
|
|
;;
|
|
Darwin)
|
|
install_go_mac "$install_dir"
|
|
;;
|
|
MSYS_NT*)
|
|
install_go_windows "$install_dir"
|
|
;;
|
|
*)
|
|
>&2 echo Error: unknown OS $(uname)
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
"${install_dir}/go/bin/go" version
|
|
}
|
|
|
|
main ${@}
|