48 lines
No EOL
1.2 KiB
Bash
Executable file
48 lines
No EOL
1.2 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
GOLANG_VERSION=1.18
|
|
|
|
DESTDIR=$(/usr/bin/realpath "${1:-/usr/local}")
|
|
|
|
# abort if not executed as root
|
|
if [[ $(id -u) != "0" ]]; then
|
|
echo "Usage: run ${0##*/} as root" 1>&2
|
|
exit 1
|
|
fi
|
|
|
|
echo "Installing Go in \"$DESTDIR\"..."
|
|
|
|
set -e
|
|
|
|
/bin/mkdir -p "$DESTDIR"
|
|
|
|
SYSTEM_ARCH=$("$(/usr/bin/dirname "$0")/arch.sh")
|
|
DESTARCH=${2:-$SYSTEM_ARCH}
|
|
|
|
set -eux;
|
|
|
|
if [[ $DESTARCH == "amd64" ]]; then
|
|
URL="https://go.dev/dl/go${GOLANG_VERSION}.linux-amd64.tar.gz"
|
|
CHECKSUM="e85278e98f57cdb150fe8409e6e5df5343ecb13cebf03a5d5ff12bd55a80264f *go.tgz"
|
|
elif [[ $DESTARCH == "arm64" ]]; then
|
|
URL="https://go.dev/dl/go${GOLANG_VERSION}.linux-arm64.tar.gz"
|
|
CHECKSUM="7ac7b396a691e588c5fb57687759e6c4db84a2a3bbebb0765f4b38e5b1c5b00e *go.tgz"
|
|
elif [[ $DESTARCH == "arm" ]]; then
|
|
URL="https://go.dev/dl/go${GOLANG_VERSION}.linux-armv6l.tar.gz"
|
|
CHECKSUM="a80fa43d1f4575fb030adbfbaa94acd860c6847820764eecb06c63b7c103612b *go.tgz"
|
|
else
|
|
echo "Unsupported Machine Architecture: $DESTARCH" 1>&2
|
|
exit 1
|
|
fi
|
|
|
|
echo "Downloading Go from \"$URL\". Please wait."
|
|
|
|
/usr/bin/wget -O go.tgz $URL
|
|
echo $CHECKSUM | /usr/bin/sha256sum -c -
|
|
/bin/rm -rf /usr/local/go
|
|
/bin/tar -C /usr/local -xzf go.tgz
|
|
/bin/rm go.tgz
|
|
|
|
/usr/local/go/bin/go version
|
|
|
|
echo "Done." |