photoprism/scripts/dist/install-go.sh

70 lines
1.5 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
2022-02-18 17:40:58 +01:00
# 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"
2022-02-18 17:40:58 +01:00
DESTDIR=$(realpath "${1:-/usr/local}")
2022-02-18 17:40:58 +01:00
# Abort if not executed as root.
2022-02-18 17:40:58 +01:00
if [[ $(id -u) != "0" ]]; then
echo "Usage: run ${0##*/} as root" 1>&2
2022-02-18 17:40:58 +01:00
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}\"..."
2022-02-18 17:40:58 +01:00
set -e
# Query architecture.
if [[ $PHOTOPRISM_ARCH ]]; then
SYSTEM_ARCH=$PHOTOPRISM_ARCH
else
SYSTEM_ARCH=$(uname -m)
fi
DESTARCH=${2:-$SYSTEM_ARCH}
2022-02-18 17:40:58 +01:00
mkdir -p "$DESTDIR"
2022-02-18 17:40:58 +01:00
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
2022-02-18 17:40:58 +01:00
exit 1
;;
esac
2022-02-18 17:40:58 +01:00
echo "Installing Go from \"$URL\". Please wait."
2022-02-18 17:40:58 +01:00
# 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
2022-02-18 17:40:58 +01:00
# Test if it works.
go version
2022-02-18 17:40:58 +01:00
echo "Done."