2021-03-17 03:23:44 +08:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
2021-06-08 23:24:21 +08:00
|
|
|
set -eux
|
|
|
|
|
|
|
|
|
|
GO_ARCH="darwin-amd64"
|
2021-08-24 04:37:44 +08:00
|
|
|
GO_VERSION="1.17"
|
|
|
|
|
GO_VERSION_SHA="355bd544ce08d7d484d9d7de05a71b5c6f5bc10aa4b316688c2192aeb3dacfd1" # from https://golang.org/dl
|
2021-06-08 23:24:21 +08:00
|
|
|
|
|
|
|
|
# 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"
|
|
|
|
|
|
2021-06-08 23:24:21 +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"
|
2021-06-11 00:12:14 +08:00
|
|
|
curl -L https://golang.org/dl/go${GO_VERSION}.${GO_ARCH}.tar.gz --output go${GO_VERSION}.${GO_ARCH}.tar.gz
|
2021-09-15 05:42:59 +08:00
|
|
|
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-03-17 03:23:44 +08:00
|
|
|
sudo rm -rf ${path}/go
|
2021-06-08 23:24:21 +08:00
|
|
|
sudo tar -C $path -xzf go${GO_VERSION}.${GO_ARCH}.tar.gz
|
2021-03-17 03:23:44 +08:00
|
|
|
ln -sf ${path}/go/bin/go /usr/local/bin/go
|
|
|
|
|
ln -sf ${path}/go/bin/gofmt /usr/local/bin/gofmt
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-15 05:42:59 +08:00
|
|
|
if command -v go >/dev/null 2>&1; then
|
2021-03-17 03:23:44 +08:00
|
|
|
echo "Go is already installed"
|
2021-09-15 05:42:59 +08:00
|
|
|
v=$(go version | { read -r _ _ v _; echo "${v#go}"; })
|
2021-06-08 23:24:21 +08:00
|
|
|
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
|