2022-03-17 10:14:08 +01:00
|
|
|
#!/bin/bash
|
2022-02-18 17:40:58 +01:00
|
|
|
|
2022-03-23 08:33:44 +01:00
|
|
|
PATH="/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/scripts"
|
2022-02-18 17:40:58 +01:00
|
|
|
|
2022-05-16 19:58:04 +02:00
|
|
|
GOLANG_VERSION=1.18.2
|
2022-03-23 08:16:01 +01:00
|
|
|
DESTDIR=$(realpath "${1:-/usr/local}")
|
2022-02-18 17:40:58 +01:00
|
|
|
|
2022-03-01 13:55:05 +01:00
|
|
|
# abort if not executed as root
|
2022-02-18 17:40:58 +01:00
|
|
|
if [[ $(id -u) != "0" ]]; then
|
2022-02-25 16:33:46 +01:00
|
|
|
echo "Usage: run ${0##*/} as root" 1>&2
|
2022-02-18 17:40:58 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2022-02-25 16:33:46 +01:00
|
|
|
echo "Installing Go in \"$DESTDIR\"..."
|
|
|
|
|
2022-02-18 17:40:58 +01:00
|
|
|
set -e
|
|
|
|
|
2022-03-23 08:16:01 +01:00
|
|
|
SYSTEM_ARCH=$("$(dirname "$0")/arch.sh")
|
2022-02-25 16:33:46 +01:00
|
|
|
DESTARCH=${2:-$SYSTEM_ARCH}
|
2022-02-18 17:40:58 +01:00
|
|
|
|
2022-03-23 08:16:01 +01:00
|
|
|
mkdir -p "$DESTDIR"
|
|
|
|
|
2022-02-18 17:40:58 +01:00
|
|
|
set -eux;
|
|
|
|
|
2022-02-25 16:33:46 +01:00
|
|
|
if [[ $DESTARCH == "amd64" ]]; then
|
2022-02-18 17:40:58 +01:00
|
|
|
URL="https://go.dev/dl/go${GOLANG_VERSION}.linux-amd64.tar.gz"
|
2022-05-16 19:58:04 +02:00
|
|
|
CHECKSUM="e54bec97a1a5d230fc2f9ad0880fcbabb5888f30ed9666eca4a91c5a32e86cbc *go.tgz"
|
2022-02-25 16:33:46 +01:00
|
|
|
elif [[ $DESTARCH == "arm64" ]]; then
|
2022-02-18 17:40:58 +01:00
|
|
|
URL="https://go.dev/dl/go${GOLANG_VERSION}.linux-arm64.tar.gz"
|
2022-05-16 19:58:04 +02:00
|
|
|
CHECKSUM="fc4ad28d0501eaa9c9d6190de3888c9d44d8b5fb02183ce4ae93713f67b8a35b *go.tgz"
|
2022-02-25 16:33:46 +01:00
|
|
|
elif [[ $DESTARCH == "arm" ]]; then
|
2022-02-18 17:40:58 +01:00
|
|
|
URL="https://go.dev/dl/go${GOLANG_VERSION}.linux-armv6l.tar.gz"
|
2022-05-16 19:58:04 +02:00
|
|
|
CHECKSUM="570dc8df875b274981eaeabe228d0774985de42e533ffc8c7ff0c9a55174f697 *go.tgz"
|
2022-02-18 17:40:58 +01:00
|
|
|
else
|
2022-02-25 16:33:46 +01:00
|
|
|
echo "Unsupported Machine Architecture: $DESTARCH" 1>&2
|
2022-02-18 17:40:58 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Downloading Go from \"$URL\". Please wait."
|
|
|
|
|
2022-03-23 08:16:01 +01:00
|
|
|
wget -O go.tgz $URL
|
|
|
|
echo "$CHECKSUM" | sha256sum -c -
|
|
|
|
rm -rf /usr/local/go
|
|
|
|
tar -C /usr/local -xzf go.tgz
|
|
|
|
rm go.tgz
|
2022-02-18 17:40:58 +01:00
|
|
|
|
|
|
|
/usr/local/go/bin/go version
|
|
|
|
|
2022-02-19 15:32:52 +01:00
|
|
|
echo "Done."
|