#!/usr/bin/env bash # Installs latest Go on Linux # bash <(curl -s https://raw.githubusercontent.com/photoprism/photoprism/develop/scripts/dist/install-go.sh) PATH="/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/scripts:$PATH" DESTDIR=$(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 # Query version. if [[ -z $GOLANG_VERSION ]]; then GOLANG_VERSION=$(curl -fsSL https://go.dev/VERSION?m=text) fi echo "Installing ${GOLANG_VERSION} in \"${DESTDIR}\"..." set -e # Query architecture. if [[ $PHOTOPRISM_ARCH ]]; then SYSTEM_ARCH=$PHOTOPRISM_ARCH else SYSTEM_ARCH=$(uname -m) fi DESTARCH=${2:-$SYSTEM_ARCH} mkdir -p "$DESTDIR" set -eux; case $DESTARCH in amd64 | AMD64 | x86_64 | x86-64) URL="https://go.dev/dl/${GOLANG_VERSION}.linux-amd64.tar.gz" ;; arm64 | ARM64 | aarch64) URL="https://go.dev/dl/${GOLANG_VERSION}.linux-arm64.tar.gz" ;; arm | ARM | aarch | armv7l | armhf) URL="https://go.dev/dl/${GOLANG_VERSION}.linux-armv6l.tar.gz" ;; *) echo "Unsupported Machine Architecture: \"$BUILD_ARCH\"" 1>&2 exit 1 ;; esac echo "Installing Go from \"$URL\". Please wait." # Replace current installation in "/usr/local/go". rm -rf /usr/local/go wget -c https://go.dev/dl/go1.18.4.linux-amd64.tar.gz -O - | tar -xz -C /usr/local # Add symlink to go binary. ln -sf /usr/local/go/bin/go /usr/local/bin/go ln -sf /usr/local/go/bin/gofmt /usr/local/bin/gofmt # Test if it works. go version echo "Done."