feat(media): chaptarr hardlinks + keeps its own ebook copy

Chaptarr had /downloads, /ebooks and /audiobooks as separate bind mounts, so
hardlinks failed with EXDEV and every import was a full copy (each seeding
audiobook stored twice). Mount /storage1 once and symlink the old container
paths into it via an entrypoint wrapper, so nothing in chaptarr's DB changes.

/ebooks now points at /storage1/Media/Ebooks, chaptarr's own ebook folder.
A Custom Script hook hardlinks each new ebook into the CWA ingest folder, so
CWA deleting its ingest copy no longer makes chaptarr think the book is missing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ginnoir (outpost agent)andClaude Opus 5.5 committed 2026-12-03 03:57:34 -06:00
1 parent 417cd3165f
commit 5d70a4e825
4 files changed
+73 -8

No files matched your search

+27
View File
@@ -0,0 +1,27 @@
#!/bin/sh
# Chaptarr Connect → Custom Script ("CWA ingest"), On Import + On Upgrade.
#
# Chaptarr keeps its own ebook copy in /ebooks (= /storage1/Media/Ebooks) so it can see what
# it already has. This hands CWA a *hardlink* of each newly imported ebook through the ingest
# folder. CWA deletes its link once it has added the book to Calibre, and chaptarr's file is
# left alone.
[ "$Chaptarr_EventType" = "Download" ] || exit 0 # also covers the "Test" button
INGEST=/storage1/complete/books-ingest
IFS='|'
for p in $Chaptarr_AddedBookPaths $Chaptarr_BookFile_Path; do
case "$p" in
/ebooks/*) rel=${p#/ebooks/} ;;
/storage1/Media/Ebooks/*) rel=${p#/storage1/Media/Ebooks/} ;;
*) continue ;; # audiobooks etc.
esac
[ -f "$p" ] || continue
author=${rel%%/*}
dest="$INGEST/$author/$(basename "$p")"
[ -e "$dest" ] && continue # already queued (path listed twice)
mkdir -p "$INGEST/$author"
ln "$p" "$dest" 2>/dev/null || cp "$p" "$dest"
echo "cwa-ingest: queued $p"
done
exit 0
+25
View File
@@ -0,0 +1,25 @@
#!/bin/sh
# Chaptarr entrypoint wrapper (compose: entrypoint: /scripts/start.sh).
#
# /storage1 is mounted ONCE; /downloads, /audiobooks and /ebooks are symlinks into it.
# Separate bind mounts make link() fail with EXDEV, and chaptarr silently falls back to a
# full copy, so every seeding audiobook used to exist twice on disk. One mount → real hardlinks.
# The container paths stay the same, so nothing in chaptarr's DB had to change.
set -e
link() { # $1 = container path, $2 = target under /storage1
if [ -L "$1" ]; then
ln -sfn "$2" "$1"
elif [ -d "$1" ]; then
rmdir "$1" # fails loudly if something unexpected is in there
ln -s "$2" "$1"
else
ln -s "$2" "$1"
fi
}
link /downloads /storage1/complete
link /audiobooks /storage1/Media/Audiobooks
link /ebooks /storage1/Media/Ebooks
exec /entrypoint.sh "$@"