2016-10-26 17:55:37 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2022-07-06 22:05:23 +00:00
|
|
|
PREFERRED_GO_VERSION=go1.17.11
|
|
|
|
SUPPORTED_GO_VERSIONS='go1.1[567]'
|
2016-10-26 17:55:37 +00:00
|
|
|
|
2017-11-23 10:13:25 +00:00
|
|
|
GO_PKG_DARWIN=${PREFERRED_GO_VERSION}.darwin-amd64.pkg
|
2022-07-06 22:05:23 +00:00
|
|
|
GO_PKG_DARWIN_SHA=4f924c534230de8f0e1c7369f611c0310efd21fc2d9438b13bc2703af9dda25a
|
2016-10-26 17:55:37 +00:00
|
|
|
|
2017-11-23 10:13:25 +00:00
|
|
|
GO_PKG_LINUX=${PREFERRED_GO_VERSION}.linux-amd64.tar.gz
|
2022-07-06 22:05:23 +00:00
|
|
|
GO_PKG_LINUX_SHA=d69a4fe2694f795d8e525c72b497ededc209cb7185f4c3b62d7a98dd6227b3fe
|
2016-10-26 17:55:37 +00:00
|
|
|
|
|
|
|
export ROOTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"
|
|
|
|
cd $ROOTDIR
|
|
|
|
|
|
|
|
# If Go isn't installed globally, setup environment variables for local install.
|
2017-11-23 10:13:25 +00:00
|
|
|
if [ -z "$(which go)" ] || [ -z "$(go version | grep "$SUPPORTED_GO_VERSIONS")" ]; then
|
2019-08-11 12:04:04 +00:00
|
|
|
GODIR="$ROOTDIR/.vendor/golocal"
|
2016-10-26 17:55:37 +00:00
|
|
|
|
|
|
|
if [ $(uname -s) = "Darwin" ]; then
|
|
|
|
export GOROOT="$GODIR/usr/local/go"
|
|
|
|
else
|
|
|
|
export GOROOT="$GODIR/go"
|
|
|
|
fi
|
|
|
|
|
|
|
|
export PATH="$GOROOT/bin:$PATH"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Check if local install exists, and install otherwise.
|
2017-11-23 10:13:25 +00:00
|
|
|
if [ -z "$(which go)" ] || [ -z "$(go version | grep "$SUPPORTED_GO_VERSIONS")" ]; then
|
2016-10-26 17:55:37 +00:00
|
|
|
[ -d "$GODIR" ] && rm -rf $GODIR
|
|
|
|
mkdir -p "$GODIR"
|
|
|
|
cd "$GODIR";
|
|
|
|
|
|
|
|
if [ $(uname -s) = "Darwin" ]; then
|
2019-08-11 12:04:04 +00:00
|
|
|
curl -L -O https://dl.google.com/go/$GO_PKG_DARWIN
|
2016-10-26 17:55:37 +00:00
|
|
|
shasum -a256 $GO_PKG_DARWIN | grep $GO_PKG_DARWIN_SHA
|
|
|
|
xar -xf $GO_PKG_DARWIN
|
|
|
|
cpio -i < com.googlecode.go.pkg/Payload
|
|
|
|
else
|
2019-08-11 12:04:04 +00:00
|
|
|
curl -L -O https://dl.google.com/go/$GO_PKG_LINUX
|
2016-10-26 17:55:37 +00:00
|
|
|
shasum -a256 $GO_PKG_LINUX | grep $GO_PKG_LINUX_SHA
|
|
|
|
tar xf $GO_PKG_LINUX
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Prove we did something right
|
2017-11-23 10:13:25 +00:00
|
|
|
echo "$(go version) installed in $GODIR: Go Binary: $(which go)"
|
|
|
|
else
|
|
|
|
echo "$(go version) found in $GODIR: Go Binary: $(which go)"
|
2016-10-26 17:55:37 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
cd $ROOTDIR
|
|
|
|
|
|
|
|
# Configure the new go to be the first go found
|
|
|
|
export GOPATH=$ROOTDIR/.vendor
|