telegraf/scripts/installgo_mac.sh

50 lines
1.6 KiB
Bash
Raw Normal View History

2021-03-17 03:23:44 +08:00
#!/bin/sh
set -eux
ARCH=$(uname -m)
2023-02-16 17:52:36 +08:00
GO_VERSION="1.20.1"
GO_VERSION_SHA_arm64="f1a8e06c7f1ba1c008313577f3f58132eb166a41ceb95ce6e9af30bc5a3efca4" # from https://golang.org/dl
GO_VERSION_SHA_amd64="a300a45e801ab459f3008aae5bb9efbe9a6de9bcd12388f5ca9bbd14f70236de" # from https://golang.org/dl
if [ "$ARCH" = 'arm64' ]; then
GO_ARCH="darwin-arm64"
GO_VERSION_SHA=${GO_VERSION_SHA_arm64}
elif [ "$ARCH" = 'x86_64' ]; then
GO_ARCH="darwin-amd64"
GO_VERSION_SHA=${GO_VERSION_SHA_amd64}
fi
# This path is cachable. (Saving in /usr/local/ would cause issues restoring the cache.)
2021-03-17 03:23:44 +08:00
path="/usr/local/Cellar"
sudo mkdir -p ${path}
2021-03-17 03:23:44 +08:00
# Download Go and verify Go tarball. (Note: we aren't using brew because
# it is slow to update and we can't pull specific minor versions.)
2021-03-17 03:23:44 +08:00
setup_go () {
echo "installing go"
curl -L https://golang.org/dl/go${GO_VERSION}.${GO_ARCH}.tar.gz --output go${GO_VERSION}.${GO_ARCH}.tar.gz
if ! echo "${GO_VERSION_SHA} go${GO_VERSION}.${GO_ARCH}.tar.gz" | shasum --algorithm 256 --check -; then
echo "Checksum failed" >&2
exit 1
fi
2021-10-21 22:40:03 +08:00
2021-03-17 03:23:44 +08:00
sudo rm -rf ${path}/go
sudo tar -C $path -xzf go${GO_VERSION}.${GO_ARCH}.tar.gz
sudo mkdir -p /usr/local/bin
sudo ln -sf ${path}/go/bin/go /usr/local/bin/go
sudo ln -sf ${path}/go/bin/gofmt /usr/local/bin/gofmt
2021-03-17 03:23:44 +08:00
}
if command -v go >/dev/null 2>&1; then
2021-03-17 03:23:44 +08:00
echo "Go is already installed"
v=$(go version | { read -r _ _ v _; echo "${v#go}"; })
echo "$v is installed, required version is ${GO_VERSION}"
if [ "$v" != ${GO_VERSION} ]; then
2021-03-17 03:23:44 +08:00
setup_go
go version
fi
else
setup_go
fi