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
Plaintext
60 lines
1.4 KiB
Plaintext
5 years ago
|
#!/usr/bin/env bash
|
||
|
|
||
|
set -e
|
||
|
|
||
4 years ago
|
GO_VERSION=${GO_VERSION:-1.15.2}
|
||
5 years ago
|
|
||
|
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
|
||
4 years ago
|
echo unknown os: "$OSTYPE"
|
||
5 years ago
|
exit 1
|
||
|
fi
|
||
|
|
||
|
ARCH=
|
||
|
if [[ $(uname -m) == x86_64 ]]; then
|
||
|
ARCH=amd64
|
||
|
else
|
||
4 years ago
|
echo arch not yet supported: "$(uname -m)"
|
||
5 years ago
|
exit 1
|
||
|
fi
|
||
|
|
||
4 years ago
|
[[ -d ${GO_DEST_DIR} ]] || sudo mkdir -p "${GO_DEST_DIR}"
|
||
5 years ago
|
|
||
|
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
|
||
4 years ago
|
echo downloading go "$GO_VERSION" to temp directory "${TMP_DIR}"
|
||
|
curl --silent --output "${DEST_FILE}" "${URL}"
|
||
5 years ago
|
|
||
4 years ago
|
sudo tar xf "${DEST_FILE}" --directory "${GO_DEST_DIR}" --strip-components 1
|
||
|
sudo chown --recursive root:root "${GO_DEST_DIR}"
|
||
5 years ago
|
else
|
||
4 years ago
|
echo go "$GO_VERSION" already installed
|
||
5 years ago
|
fi
|
||
|
|
||
|
cd ${PREFIX_DIR}
|
||
|
[[ -s go ]] && sudo unlink go
|
||
4 years ago
|
sudo ln --symbolic "${GO_DEST_DIR}" go
|
||
|
echo current version set to "${GO_VERSION}"
|
||
5 years ago
|
|
||
|
[[ -f /etc/profile.d/go-path.sh ]] \
|
||
4 years ago
|
|| echo "export PATH=\$PATH:/usr/local/go/bin" \
|
||
5 years ago
|
| sudo tee /etc/profile.d/go-path.sh
|
||
|
|
||
|
if [[ $TMP_DIR != "" ]]; then
|
||
4 years ago
|
rm -rf "${TMP_DIR}"
|
||
|
echo removed up temp directory "${TMP_DIR}"
|
||
5 years ago
|
fi
|