diff --git a/docker/develop/jammy-slim/Dockerfile b/docker/develop/jammy-slim/Dockerfile index ddd8e14f4..8f468f898 100644 --- a/docker/develop/jammy-slim/Dockerfile +++ b/docker/develop/jammy-slim/Dockerfile @@ -52,13 +52,12 @@ RUN echo 'APT::Acquire::Retries "3";' > /etc/apt/apt.conf.d/80retries && \ x264 x265 libde265-dev libjpeg8 libvpx7 libwebm1 \ && \ /scripts/install-darktable.sh && \ + /scripts/install-libheif.sh && \ echo 'alias ll="ls -alh"' >> /etc/skel/.bashrc && \ echo 'export PS1="\u@$DOCKER_TAG:\w\$ "' >> /etc/skel/.bashrc && \ echo "ALL ALL=(ALL) NOPASSWD:SETENV: /scripts/entrypoint-init.sh" >> /etc/sudoers.d/init && \ cp /etc/skel/.bashrc /root/.bashrc && \ /scripts/create-users.sh && \ - (wget --inet4-only -c "https://dl.photoprism.app/dist/libheif/libheif.jammy.tar.gz" -O - | tar -xz -C /usr/local) && \ - ldconfig && \ install -d -m 0777 -o 1000 -g 1000 \ /photoprism/originals \ /photoprism/import \ diff --git a/docker/develop/jammy/Dockerfile b/docker/develop/jammy/Dockerfile index 3e845b683..05cad9915 100644 --- a/docker/develop/jammy/Dockerfile +++ b/docker/develop/jammy/Dockerfile @@ -68,6 +68,7 @@ RUN echo 'APT::Acquire::Retries "3";' > /etc/apt/apt.conf.d/80retries && \ /scripts/install-nodejs.sh && \ /scripts/install-tensorflow.sh && \ /scripts/install-darktable.sh && \ + /scripts/install-libheif.sh && \ /scripts/install-chrome.sh && \ /scripts/install-go.sh && \ /scripts/install-go-tools.sh && \ @@ -76,8 +77,6 @@ RUN echo 'APT::Acquire::Retries "3";' > /etc/apt/apt.conf.d/80retries && \ echo "ALL ALL=(ALL) NOPASSWD:SETENV: ALL" >> /etc/sudoers.d/all && \ cp /etc/skel/.bashrc /root/.bashrc && \ /scripts/create-users.sh && \ - (wget --inet4-only -c "https://dl.photoprism.app/dist/libheif/libheif.jammy.tar.gz" -O - | tar -xz -C /usr/local) && \ - ldconfig && \ install -d -m 0777 -o 1000 -g 1000 \ /photoprism/originals \ /photoprism/import \ diff --git a/scripts/dist/build-libheif.sh b/scripts/dist/build-libheif.sh index f7dce489b..5d15428a9 100755 --- a/scripts/dist/build-libheif.sh +++ b/scripts/dist/build-libheif.sh @@ -1,31 +1,58 @@ #!/usr/bin/env bash -# Abort if not executed as root. -if [[ $(id -u) != "0" ]]; then - echo "Usage: run ${0##*/} as root" 1>&2 - exit 1 -fi - # Build "heif-convert", "heif-enc", "heif-info", and "heif-thumbnailer" from source. CURRENT_DIR=$(pwd) -apt-get update -apt-get -qq install git autoconf automake cmake libtool libjpeg8 libjpeg8-dev libde265-dev + +# Query architecture. +if [[ $PHOTOPRISM_ARCH ]]; then + SYSTEM_ARCH=$PHOTOPRISM_ARCH +else + SYSTEM_ARCH=$(uname -m) +fi + +. /etc/os-release + +LATEST=$(curl --silent "https://api.github.com/repos/strukturag/libheif/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') +LIBHEIF_VERSION=${1:-$LATEST} +DESTARCH=${2:-$SYSTEM_ARCH} + +BUILD="libheif-$VERSION_CODENAME-$DESTARCH-$LIBHEIF_VERSION" + +DESTDIR="${CURRENT_DIR}/build/$BUILD" + +mkdir -p "$DESTDIR" + +ARCHIVE="${CURRENT_DIR}/build/$BUILD.tar.gz" + +echo "------------------------------------------------" +echo "VERSION: $LIBHEIF_VERSION" +echo "LATEST : $LATEST" +echo "ARCHIVE: $ARCHIVE" +echo "------------------------------------------------" + +echo "Installing build deps..." + +sudo apt-get -qq update +sudo apt-get -qq install build-essential gcc g++ gettext git autoconf automake cmake libtool libjpeg8 libjpeg8-dev libde265-dev + cd "/tmp" || exit rm -rf "/tmp/libheif" -git clone https://github.com/strukturag/libheif.git + +echo "Cloning git repository..." +git clone -c advice.detachedHead=false -b "$LIBHEIF_VERSION" --depth 1 https://github.com/strukturag/libheif.git libheif cd libheif || exit ./autogen.sh ./configure make # Install "heif-convert", "heif-enc", "heif-info", and "heif-thumbnailer" in "/usr/local". -make install-exec +echo "Installing binaries..." +DESTDIR=$DESTDIR make install-exec cd "$CURRENT_DIR" || exit rm -rf "/tmp/libheif" -# Create a tar archive to distribute the binaries on demand. -if [[ $1 ]]; then - echo "creating $1..." - (cd /usr/local && tar -czf "$1" lib/libheif.* bin/heif-convert bin/heif-enc bin/heif-info bin/heif-thumbnailer) -fi +# Create a tar archive to distribute the binaries. +echo "Creating $ARCHIVE..." +tar -czf "$ARCHIVE" -C "$DESTDIR/usr/local" bin lib +echo "Done." diff --git a/scripts/dist/install-libheif.sh b/scripts/dist/install-libheif.sh new file mode 100755 index 000000000..39071cdb5 --- /dev/null +++ b/scripts/dist/install-libheif.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash + +set -e + +LIBHEIF_VERSION=${1:-v1.13.0} +DESTDIR=$(realpath "${2:-/usr/local}") +SYSTEM_ARCH=$("$(dirname "$0")/arch.sh") +DESTARCH=${DESTARCH:-$SYSTEM_ARCH} + +. /etc/os-release + +# abort if not executed as root +if [[ $(id -u) != "0" ]] && [[ $DESTDIR == "/usr" || $DESTDIR == "/usr/local" ]]; then + echo "Error: Run ${0##*/} as root to install in a system directory!" 1>&2 + exit 1 +fi + +mkdir -p "$DESTDIR" + +ARCHIVE="libheif-${VERSION_CODENAME}-${DESTARCH}-${LIBHEIF_VERSION}.tar.gz" +URL="https://dl.photoprism.app/dist/libheif/${ARCHIVE}" + +echo "------------------------------------------------" +echo "VERSION: $LIBHEIF_VERSION" +echo "ARCHIVE: $ARCHIVE" +echo "DESTDIR: $DESTDIR" +echo "------------------------------------------------" + +echo "Extracting \"$URL\" to \"$DESTDIR\"." +wget --inet4-only -c "$URL" -O - | tar --overwrite --mode=755 -xz -C "$DESTDIR" + +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."