2022-02-18 17:40:58 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
GOLANG_VERSION=1.17.7
|
|
|
|
|
|
|
|
DESTDIR=$(realpath "${1:-/usr/local}")
|
|
|
|
|
|
|
|
# abort if the user is not root
|
|
|
|
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
|
|
|
|
|
|
|
|
mkdir -p "$DESTDIR"
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
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"
|
|
|
|
CHECKSUM="02b111284bedbfa35a7e5b74a06082d18632eff824fd144312f6063943d49259 *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"
|
|
|
|
CHECKSUM="a5aa1ed17d45ee1d58b4a4099b12f8942acbd1dd09b2e9a6abb1c4898043c5f5 *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"
|
|
|
|
CHECKSUM="874774f078b182fa21ffcb3878467eb5cb7e78bbffa6343ea5f0fbe47983433b *go.tgz"
|
|
|
|
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."
|
|
|
|
|
|
|
|
wget -O go.tgz $URL
|
|
|
|
echo $CHECKSUM | sha256sum -c -
|
|
|
|
rm -rf /usr/local/go
|
|
|
|
tar -C /usr/local -xzf go.tgz
|
|
|
|
rm go.tgz
|
|
|
|
|
|
|
|
/usr/local/go/bin/go version
|
|
|
|
|
2022-02-19 15:32:52 +01:00
|
|
|
echo "Done."
|