Files
gutenberg-mirror/html-to-epub.sh
2025-01-07 14:20:59 -08:00

27 lines
1.1 KiB
Bash
Executable File

#!/usr/bin/env bash
cd $LIBRARY_PATH
for srcdir in $(find html-src -name \*-h -type d)
do
srcfile=$(echo $srcdir/$(basename $srcdir).htm)
prefix=$(basename -s -h.htm $srcfile)
echo $prefix" " | tr "\n" "\r"
destpath=$(echo $(dirname $(dirname $srcfile)) | sed "s/^html-src/ebooks/")
mkdir -p $destpath
if [ $srcfile -nt $destpath/$prefix.epub ]
then
echo ""
docker run --rm -v $PWD:$PWD cr.gitlab.alfter.us/salfter/ebookmaker --make kindle.images --generate_cover --output-dir $PWD/$destpath $PWD/$srcfile 2>&1 >/dev/null
coverfile=$(ls $destpath/*.png)
if [ "$coverfile" != "" ]
then
docker run --rm -v $PWD:$PWD cr.gitlab.alfter.us/salfter/ebookmaker --make kindle.images --cover $coverfile --output-dir $PWD/$destpath $PWD/$srcfile 2>&1 >/dev/null
fi
rm -f $destpath/$prefix.epub $destpath/$prefix.mobi 2>&1 >/dev/null
mv $destpath/*.epub $destpath/$prefix.epub
mv $destpath/*.mobi $destpath/$prefix.mobi
rm -f $coverfile 2>&1 >/dev/null
echo update books set epub=1 where book_id=$prefix\; | mariadb -h $DB_HOST -u $DB_USER --password=$DB_PASS $DB_DATA
fi
done