You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.4 KiB
Bash
60 lines
1.4 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
set -e
|
|
|
|
GO_VERSION=${GO_VERSION:-1.14.1}
|
|
|
|
PREFIX_DIR=/usr/local
|
|
#BIN_DIR=${PREFIX_DIR}/bin
|
|
|
|
GO_PREFIX_DIR=${PREFIX_DIR}/golang
|
|
GO_DEST_DIR=${GO_PREFIX_DIR}/${GO_VERSION}
|
|
|
|
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
|