2022-07-23 13:16:10 +02:00
|
|
|
#!/usr/bin/env bash
|
2022-02-18 17:40:58 +01:00
|
|
|
|
2022-07-23 14:21:58 +02:00
|
|
|
# Installs latest Go on Linux
|
2022-07-23 13:55:05 +02:00
|
|
|
# bash <(curl -s https://raw.githubusercontent.com/photoprism/photoprism/develop/scripts/dist/install-go.sh)
|
|
|
|
|
2022-07-23 13:08:24 +02:00
|
|
|
PATH="/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/scripts:$PATH"
|
2022-02-18 17:40:58 +01:00
|
|
|
|
2022-03-23 08:16:01 +01:00
|
|
|
DESTDIR=$(realpath "${1:-/usr/local}")
|
2022-02-18 17:40:58 +01:00
|
|
|
|
2022-07-23 14:21:58 +02: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-07-23 14:21:58 +02:00
|
|
|
# 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-25 16:33:46 +01:00
|
|
|
|
2022-02-18 17:40:58 +01:00
|
|
|
set -e
|
|
|
|
|
2022-07-23 14:21:58 +02:00
|
|
|
# Query architecture.
|
2022-07-23 13:55:05 +02:00
|
|
|
if [[ $PHOTOPRISM_ARCH ]]; then
|
|
|
|
SYSTEM_ARCH=$PHOTOPRISM_ARCH
|
2022-07-23 13:08:24 +02:00
|
|
|
else
|
2022-07-23 13:55:05 +02:00
|
|
|
SYSTEM_ARCH=$(uname -m)
|
2022-07-23 13:08:24 +02:00
|
|
|
fi
|
|
|
|
|
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-07-23 13:55:05 +02:00
|
|
|
case $DESTARCH in
|
|
|
|
amd64 | AMD64 | x86_64 | x86-64)
|
2022-07-23 14:21:58 +02:00
|
|
|
URL="https://go.dev/dl/${GOLANG_VERSION}.linux-amd64.tar.gz"
|
2022-07-23 13:55:05 +02:00
|
|
|
;;
|
|
|
|
|
|
|
|
arm64 | ARM64 | aarch64)
|
2022-07-23 14:21:58 +02:00
|
|
|
URL="https://go.dev/dl/${GOLANG_VERSION}.linux-arm64.tar.gz"
|
2022-07-23 13:55:05 +02:00
|
|
|
;;
|
|
|
|
|
|
|
|
arm | ARM | aarch | armv7l | armhf)
|
2022-07-23 14:21:58 +02:00
|
|
|
URL="https://go.dev/dl/${GOLANG_VERSION}.linux-armv6l.tar.gz"
|
2022-07-23 13:55:05 +02:00
|
|
|
;;
|
|
|
|
|
|
|
|
*)
|
|
|
|
echo "Unsupported Machine Architecture: \"$BUILD_ARCH\"" 1>&2
|
2022-02-18 17:40:58 +01:00
|
|
|
exit 1
|
2022-07-23 13:55:05 +02:00
|
|
|
;;
|
|
|
|
esac
|
2022-02-18 17:40:58 +01:00
|
|
|
|
2022-07-23 14:21:58 +02:00
|
|
|
echo "Installing Go from \"$URL\". Please wait."
|
2022-02-18 17:40:58 +01:00
|
|
|
|
2022-07-23 14:21:58 +02:00
|
|
|
# Replace current installation in "/usr/local/go".
|
2022-03-23 08:16:01 +01:00
|
|
|
rm -rf /usr/local/go
|
2022-07-23 14:21:58 +02:00
|
|
|
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
|
|
|
|
2022-07-23 14:21:58 +02:00
|
|
|
# Test if it works.
|
|
|
|
go version
|
2022-02-18 17:40:58 +01:00
|
|
|
|
2022-02-19 15:32:52 +01:00
|
|
|
echo "Done."
|