From ce25867efdc9a93efd7f551b47c560c0cc7255c8 Mon Sep 17 00:00:00 2001 From: mikiher Date: Thu, 26 Nov 2026 21:17:59 +0200 Subject: [PATCH] Package the React client in the Debian build --- build/debian/DEBIAN/postinst | 6 ++++++ build/debian/DEBIAN/postrm | 10 ++++++++++ .../lib/systemd/system/audiobookshelf.service | 1 + build/linuxpackager | 17 +++++++---------- 4 files changed, 24 insertions(+), 10 deletions(-) create mode 100644 build/debian/DEBIAN/postrm diff --git a/build/debian/DEBIAN/postinst b/build/debian/DEBIAN/postinst index b80d18c68..1694aa63c 100644 --- a/build/debian/DEBIAN/postinst +++ b/build/debian/DEBIAN/postinst @@ -44,4 +44,10 @@ if [ ! -d "$ABS_LOG_DIR" ]; then chown -R 'audiobookshelf:audiobookshelf' "$ABS_LOG_DIR" fi +# Startup rewrites the React client's base-path placeholder and Next writes its cache under .next. +CLIENT_REACT_DIR="/usr/share/audiobookshelf/client-react" +if [ -d "$CLIENT_REACT_DIR" ]; then + chown -R 'audiobookshelf:audiobookshelf' "$CLIENT_REACT_DIR" +fi + start_service 'audiobookshelf' diff --git a/build/debian/DEBIAN/postrm b/build/debian/DEBIAN/postrm new file mode 100644 index 000000000..e11384d51 --- /dev/null +++ b/build/debian/DEBIAN/postrm @@ -0,0 +1,10 @@ +#!/bin/bash +set -e +set -o pipefail + +# dpkg removes the packaged files. This deletes the base-path snapshot and Next +# cache, which are created at runtime and are not in the package file list. +# postrm upgrade runs after the new package is unpacked, so leave the directory in place then. +if [ "$1" = "remove" ] || [ "$1" = "purge" ]; then + rm -rf /usr/share/audiobookshelf/client-react +fi diff --git a/build/debian/lib/systemd/system/audiobookshelf.service b/build/debian/lib/systemd/system/audiobookshelf.service index dd5be8770..bbb975020 100644 --- a/build/debian/lib/systemd/system/audiobookshelf.service +++ b/build/debian/lib/systemd/system/audiobookshelf.service @@ -12,6 +12,7 @@ Restart=always User=audiobookshelf Group=audiobookshelf Environment=HOME=/var/cache/audiobookshelf +Environment=REACT_CLIENT_PATH=/usr/share/audiobookshelf/client-react CacheDirectory=audiobookshelf [Install] diff --git a/build/linuxpackager b/build/linuxpackager index 622a00550..4f8f29f5b 100755 --- a/build/linuxpackager +++ b/build/linuxpackager @@ -11,15 +11,6 @@ VERSION="$( eval echo $( jq '.version' package.json) )" DESCRIPTION="$( eval echo $( jq '.description' package.json) )" OUTPUT_FILE="audiobookshelf_${VERSION}_amd64.deb" -echo ">>> Building Client" -echo "--------------------" - -cd client -rm -rf node_modules -npm ci -npm run generate -cd .. - echo ">>> Building Server" echo "--------------------" @@ -47,11 +38,17 @@ Description: $DESCRIPTION" echo "$controlfile" > dist/debian/DEBIAN/control; +echo ">>> Fetching React client runtime" +echo "--------------------" + +mkdir -p dist/debian/usr/share/audiobookshelf +node scripts/fetch-client-react-runtime.js --out dist/debian/usr/share/audiobookshelf/client-react + # Package contents: directories 0755, files 0644 (including the systemd unit). # Maintainer scripts must stay executable so dpkg can run them. find dist/debian -type d -exec chmod 755 {} + find dist/debian -type f -exec chmod 644 {} + -chmod 755 dist/debian/DEBIAN/preinst dist/debian/DEBIAN/postinst dist/debian/DEBIAN/prerm +chmod 755 dist/debian/DEBIAN/preinst dist/debian/DEBIAN/postinst dist/debian/DEBIAN/prerm dist/debian/DEBIAN/postrm # Package debian pkg --config package.json -t node24-linux-x64 -o dist/debian/usr/share/audiobookshelf/audiobookshelf dist-server/index.js