From 2793b10a6b75e7601f34928b27446be028ee80f2 Mon Sep 17 00:00:00 2001 From: Buddy Sandidge Date: Sat, 14 Mar 2020 17:55:25 -0700 Subject: [PATCH] Add go install script --- bin/install-go-system | 60 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100755 bin/install-go-system diff --git a/bin/install-go-system b/bin/install-go-system new file mode 100755 index 0000000..e3057c6 --- /dev/null +++ b/bin/install-go-system @@ -0,0 +1,60 @@ +#!/usr/bin/env bash + +set -e + +GO_VERSION=${GO_VERSION:-1.14} + +PREFIX_DIR=/usr/local +#BIN_DIR=${PREFIX_DIR}/bin + +GO_PREFIX_DIR=${PREFIX_DIR}/golang +GO_DEST_DIR=${GO_PREFIX_DIR}/${GO_VERSION} +GO_CURRENT=${PREFIX_DIR}/go + +OS= +if [[ $OSTYPE =~ linux ]]; then + OS=linux +elif [[ $OSTYPE =~ darwin ]]; then + OS=darwin +else + echo unknown os: $OSTYPE + exit 1 +fi + +ARCH= +if [[ $(uname -m) == x86_64 ]]; then + ARCH=amd64 +else + echo arch not yet supported: $(uname -m) + exit 1 +fi + +[[ -d ${GO_DEST_DIR} ]] || sudo mkdir -p ${GO_DEST_DIR} + +TMP_DIR= +if [[ ! -d ${GO_DEST_DIR}/bin ]]; then + TMP_DIR=$(mktemp --directory) + DEST_FILE=$TMP_DIR/go.tar.gz + URL=https://dl.google.com/go/go${GO_VERSION}.${OS}-${ARCH}.tar.gz + echo downloading go $GO_VERSION to temp directory ${TMP_DIR} + curl --silent --output ${DEST_FILE} ${URL} + + sudo tar xf ${DEST_FILE} --directory ${GO_DEST_DIR} --strip-components 1 + sudo chown --recursive root:root ${GO_DEST_DIR} +else + echo go $GO_VERSION already installed +fi + +cd ${PREFIX_DIR} +[[ -s go ]] && sudo unlink go +sudo ln --symbolic ${GO_DEST_DIR} go +echo current version set to ${GO_VERSION} + +[[ -f /etc/profile.d/go-path.sh ]] \ + || echo 'export PATH=$PATH:/usr/local/go/bin' \ + | sudo tee /etc/profile.d/go-path.sh + +if [[ $TMP_DIR != "" ]]; then + rm -rf ${TMP_DIR} + echo removed up temp directory ${TMP_DIR} +fi