refactor golang scripts a bit

Namely ensure the script fails if any step fails, only skip installing
if that particular version is installed, and retry if the download fails
This commit is contained in:
Mahmood Ali
2020-12-08 08:56:38 -05:00
parent a4aa80d9c0
commit e15fad5609

View File

@@ -1,16 +1,22 @@
#!/usr/bin/env bash
set -o errexit
function install_go() {
local go_version="1.15.5"
local download=
local download="https://storage.googleapis.com/golang/go${go_version}.linux-amd64.tar.gz"
download="https://storage.googleapis.com/golang/go${go_version}.linux-amd64.tar.gz"
if [ -d /usr/local/go ] ; then
if go version 2>&1 | grep -q "${go_version}"; then
return
fi
curl -sSL --fail -o /tmp/go.tar.gz ${download}
# 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}"
tar -C /tmp -xf /tmp/go.tar.gz
sudo mv /tmp/go /usr/local
@@ -18,7 +24,7 @@ function install_go() {
}
install_go
# Ensure that the GOPATH tree is owned by vagrant:vagrant
mkdir -p /opt/gopath
chown -R vagrant:vagrant /opt/gopath