2017-09-08 23:59:03 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2020-12-08 13:56:38 +00:00
|
|
|
set -o errexit
|
|
|
|
|
2017-09-08 23:59:03 +00:00
|
|
|
function install_go() {
|
2021-12-10 15:47:50 +00:00
|
|
|
local go_version="1.17.5"
|
2020-12-08 13:56:38 +00:00
|
|
|
local download="https://storage.googleapis.com/golang/go${go_version}.linux-amd64.tar.gz"
|
2017-09-08 23:59:03 +00:00
|
|
|
|
2020-12-08 13:56:38 +00:00
|
|
|
if go version 2>&1 | grep -q "${go_version}"; then
|
2017-09-08 23:59:03 +00:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2020-12-08 13:56:38 +00:00
|
|
|
# remove previous older version
|
|
|
|
rm -rf /usr/local/go
|
|
|
|
|
|
|
|
# retry downloading on spurious failure
|
|
|
|
curl -sSL --fail -o /tmp/go.tar.gz \
|
|
|
|
--retry 5 --retry-connrefused \
|
|
|
|
"${download}"
|
2017-09-08 23:59:03 +00:00
|
|
|
|
2017-09-09 00:42:42 +00:00
|
|
|
tar -C /tmp -xf /tmp/go.tar.gz
|
2017-09-08 23:59:03 +00:00
|
|
|
sudo mv /tmp/go /usr/local
|
|
|
|
sudo chown -R root:root /usr/local/go
|
|
|
|
}
|
|
|
|
|
|
|
|
install_go
|
2020-12-08 13:56:38 +00:00
|
|
|
|
2017-09-08 23:59:03 +00:00
|
|
|
# Ensure that the GOPATH tree is owned by vagrant:vagrant
|
|
|
|
mkdir -p /opt/gopath
|
2017-12-12 01:06:07 +00:00
|
|
|
chown -R vagrant:vagrant /opt/gopath
|
2017-09-08 23:59:03 +00:00
|
|
|
|
|
|
|
# Ensure Go is on PATH
|
|
|
|
if [ ! -e /usr/bin/go ] ; then
|
|
|
|
ln -s /usr/local/go/bin/go /usr/bin/go
|
|
|
|
fi
|
|
|
|
if [ ! -e /usr/bin/gofmt ] ; then
|
|
|
|
ln -s /usr/local/go/bin/gofmt /usr/bin/gofmt
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# Ensure new sessions know about GOPATH
|
|
|
|
if [ ! -f /etc/profile.d/gopath.sh ] ; then
|
|
|
|
cat <<EOT > /etc/profile.d/gopath.sh
|
|
|
|
export GOPATH="/opt/gopath"
|
|
|
|
export PATH="/opt/gopath/bin:\$PATH"
|
|
|
|
EOT
|
|
|
|
chmod 755 /etc/profile.d/gopath.sh
|
|
|
|
fi
|