2022-07-23 13:16:10 +02:00
|
|
|
#!/usr/bin/env bash
|
2022-04-17 16:28:34 +02:00
|
|
|
|
2022-07-23 15:09:29 +02:00
|
|
|
# Installs Go tools on Linux
|
2022-07-23 13:55:05 +02:00
|
|
|
# bash <(curl -s https://raw.githubusercontent.com/photoprism/photoprism/develop/scripts/dist/install-go-tools.sh)
|
|
|
|
|
2022-07-23 13:08:24 +02:00
|
|
|
PATH="/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/scripts:/usr/local/go/bin:/go/bin:$PATH"
|
2022-04-17 16:28:34 +02:00
|
|
|
|
|
|
|
# abort if not executed as root
|
|
|
|
if [[ $(id -u) != "0" ]]; then
|
|
|
|
echo "Usage: run ${0##*/} as root" 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2022-07-23 15:02:28 +02:00
|
|
|
if ! command -v go &> /dev/null
|
|
|
|
then
|
2022-08-12 20:17:17 +02:00
|
|
|
echo "Go must be installed to run this."
|
2022-07-23 15:02:28 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2022-07-23 13:55:05 +02:00
|
|
|
if [[ $PHOTOPRISM_ARCH ]]; then
|
|
|
|
SYSTEM_ARCH=$PHOTOPRISM_ARCH
|
|
|
|
else
|
|
|
|
SYSTEM_ARCH=$(uname -m)
|
|
|
|
fi
|
|
|
|
|
2022-04-18 14:14:32 +02:00
|
|
|
DESTARCH=${2:-$SYSTEM_ARCH}
|
|
|
|
|
2022-07-23 15:09:29 +02:00
|
|
|
if [ -d "/go" ]; then
|
|
|
|
GOPATH="/go"
|
|
|
|
elif [[ -z $GOPATH ]]; then
|
|
|
|
GOPATH=$(go env GOPATH)
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Installing Go tools for ${DESTARCH^^} in $GOPATH..."
|
2022-04-17 16:28:34 +02:00
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2022-07-23 15:02:28 +02:00
|
|
|
mkdir -p "$GOPATH/src"
|
2022-04-18 14:14:32 +02:00
|
|
|
|
2022-07-23 14:57:17 +02:00
|
|
|
# Install gosu in "/usr/local/sbin".
|
|
|
|
echo "Installing gosu in /usr/local/sbin..."
|
|
|
|
GOBIN="/usr/local/sbin" go install github.com/tianon/gosu@latest
|
|
|
|
chown root:root /usr/local/sbin/gosu
|
|
|
|
chmod 755 /usr/local/sbin/gosu
|
2022-04-18 14:14:32 +02:00
|
|
|
|
2022-07-23 14:57:17 +02:00
|
|
|
# Install remaining tools in "/usr/local/bin".
|
2022-07-23 13:55:05 +02:00
|
|
|
case $DESTARCH in
|
|
|
|
arm | ARM | aarch | armv7l | armhf)
|
|
|
|
# no additional tools on ARMv7 to reduce build time
|
|
|
|
echo "Skipping installation of goimports, go-mod-outdated, exif-read-tool and richgo."
|
|
|
|
;;
|
|
|
|
|
|
|
|
*)
|
2022-07-23 14:57:17 +02:00
|
|
|
echo "Installing goimports, go-mod-outdated, exif-read-tool and richgo in /usr/local/bin..."
|
|
|
|
GOBIN="/usr/local/bin" go install golang.org/x/tools/cmd/goimports@latest
|
|
|
|
GOBIN="/usr/local/bin" go install github.com/psampaz/go-mod-outdated@latest
|
|
|
|
GOBIN="/usr/local/bin" go install github.com/dsoprea/go-exif/v3/command/exif-read-tool@latest
|
|
|
|
GOBIN="/usr/local/bin" go install github.com/mikefarah/yq/v4@latest
|
|
|
|
GOBIN="/usr/local/bin" go install github.com/kyoh86/richgo@latest
|
2022-07-23 13:55:05 +02:00
|
|
|
;;
|
|
|
|
esac
|
2022-04-18 14:14:32 +02:00
|
|
|
|
|
|
|
chmod -R a+rwX "$GOPATH"
|
|
|
|
|
|
|
|
echo "Done."
|