Files
gutenberg-mirror/html_to_epub.sh

26 lines
1.1 KiB
Bash

#!/usr/bin/env bash
set -a
source ./env
set +a
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
destpath=$(echo $(dirname $(dirname $srcfile)) | sed "s/^html-src/ebooks/")
mkdir -p $destpath
if [ $srcfile -nt $destpath/$prefix.epub ]
then
docker run -it --rm -v $(pwd):/data cr.gitlab.alfter.us/salfter/ebookmaker --make kindle.images --generate_cover --output-dir /data/$destpath /data/$srcfile 2>&1 >/dev/null
coverfile=$(ls $destpath/*.png)
docker run -it --rm -v $(pwd):/data cr.gitlab.alfter.us/salfter/ebookmaker --make kindle.images --cover /data/$coverfile --output-dir /data/$destpath /data/$srcfile 2>&1 >/dev/null
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_PASSWORD $DB_DATABASE
fi
done