2022-02-19 15:32:52 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2022-02-25 16:33:46 +01:00
|
|
|
TF_VERSION=${TF_VERSION:-1.15.2}
|
2022-02-19 15:32:52 +01:00
|
|
|
|
2022-02-25 16:33:46 +01:00
|
|
|
SYSTEM_ARCH=$("$(dirname "$0")/arch.sh")
|
|
|
|
DESTARCH=${DESTARCH:-$SYSTEM_ARCH}
|
|
|
|
|
|
|
|
if [[ $1 == "auto" ]]; then
|
|
|
|
TF_DRIVER="auto";
|
|
|
|
DESTDIR="/usr";
|
|
|
|
else
|
|
|
|
DESTDIR=$(realpath "${1:-/usr}")
|
|
|
|
fi
|
2022-02-19 15:32:52 +01:00
|
|
|
|
2022-02-25 16:33:46 +01:00
|
|
|
TMPDIR=${TMPDIR:-/tmp}
|
2022-02-19 15:32:52 +01:00
|
|
|
|
|
|
|
# abort if the user is not root
|
|
|
|
if [[ $(id -u) != "0" ]] && [[ $DESTDIR == "/usr" || $DESTDIR == "/usr/local" ]]; then
|
2022-02-25 16:33:46 +01:00
|
|
|
echo "Error: Run ${0##*/} as root to install in a system directory!" 1>&2
|
2022-02-19 15:32:52 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
mkdir -p "$DESTDIR"
|
|
|
|
|
2022-02-25 16:33:46 +01:00
|
|
|
if [[ $TF_DRIVER == "auto" ]]; then
|
|
|
|
echo "Detecting driver..."
|
|
|
|
TF_DRIVER=$("$(dirname "$0")/tensorflow-driver.sh")
|
|
|
|
fi
|
2022-02-19 15:32:52 +01:00
|
|
|
|
2022-02-25 16:33:46 +01:00
|
|
|
if [[ -z $TF_DRIVER ]]; then
|
2022-02-25 17:08:17 +01:00
|
|
|
echo "Installing TensorFlow ${TF_VERSION} for ${DESTARCH^^} in \"$DESTDIR\"..."
|
2022-02-25 16:33:46 +01:00
|
|
|
INSTALL_FILE="${DESTARCH}/libtensorflow-${DESTARCH}-${TF_VERSION}.tar.gz"
|
2022-02-19 15:32:52 +01:00
|
|
|
else
|
2022-02-25 17:08:17 +01:00
|
|
|
echo "Installing TensorFlow ${TF_VERSION} for ${DESTARCH^^}-${TF_DRIVER^^} in \"$DESTDIR\"..."
|
2022-02-25 16:33:46 +01:00
|
|
|
INSTALL_FILE="${DESTARCH}/libtensorflow-${DESTARCH}-${TF_DRIVER}-${TF_VERSION}.tar.gz"
|
2022-02-19 15:32:52 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -f "$TMPDIR/$INSTALL_FILE" ]; then
|
|
|
|
URL="https://dl.photoprism.app/tensorflow/${INSTALL_FILE}"
|
2022-02-25 16:33:46 +01:00
|
|
|
echo "Downloading ${DESTARCH} libs from \"$URL\". Please wait."
|
2022-02-19 15:32:52 +01:00
|
|
|
curl --create-dirs -fsSL -o "$TMPDIR/$INSTALL_FILE" "$URL"
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Extracting \"$TMPDIR/$INSTALL_FILE\" to \"$DESTDIR\"..."
|
|
|
|
|
|
|
|
if [ -f "$TMPDIR/$INSTALL_FILE" ]; then
|
|
|
|
tar --overwrite --mode=755 -C "$DESTDIR" -xzf "$TMPDIR/$INSTALL_FILE"
|
|
|
|
else
|
2022-02-25 16:33:46 +01:00
|
|
|
echo "Fatal: \"$TMPDIR/$INSTALL_FILE\" not found"
|
2022-02-19 15:32:52 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ $DESTDIR == "/usr" || $DESTDIR == "/usr/local" ]]; then
|
|
|
|
echo "Running ldconfig..."
|
|
|
|
ldconfig
|
|
|
|
else
|
|
|
|
echo "Running \"ldconfig -n $DESTDIR/lib\"."
|
|
|
|
ldconfig -n "$DESTDIR/lib"
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Done."
|