From 148383b78dbdd103d0512a548bf2501fe2fef415 Mon Sep 17 00:00:00 2001 From: Scott Alfter Date: Mon, 7 Oct 2024 13:46:34 -0700 Subject: [PATCH] break hardcoded database credentials out of script --- .gitignore | 1 + db_update.sh | 6 ++++++ env.template | 4 ++++ gutenberg_mirror.sql | 1 + html_to_epub.sh | 7 ++++++- 5 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 db_update.sh create mode 100644 env.template diff --git a/.gitignore b/.gitignore index fa3c6f6..9177921 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ html-src/ ebooks/ *.csv +env diff --git a/db_update.sh b/db_update.sh new file mode 100644 index 0000000..cf0471a --- /dev/null +++ b/db_update.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +set -a +source ./env +set +a +user=$DB_USER password=$DB_PASSWORD host=$DB_HOST database=$DB_DATABASE ./db_update.py diff --git a/env.template b/env.template new file mode 100644 index 0000000..7245d19 --- /dev/null +++ b/env.template @@ -0,0 +1,4 @@ +DB_USER= +DB_PASSWORD= +DB_HOST= +DB_DATABASE= diff --git a/gutenberg_mirror.sql b/gutenberg_mirror.sql index e01004c..fd17f78 100644 --- a/gutenberg_mirror.sql +++ b/gutenberg_mirror.sql @@ -40,6 +40,7 @@ CREATE TABLE `books` ( `book_id` int(11) NOT NULL, `title` varchar(256) NOT NULL, `locc` varchar(16) DEFAULT NULL, + `epub` bit not null default 0, PRIMARY KEY (`book_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci; /*!40101 SET character_set_client = @saved_cs_client */; diff --git a/html_to_epub.sh b/html_to_epub.sh index d9fac25..41ebef6 100644 --- a/html_to_epub.sh +++ b/html_to_epub.sh @@ -1,5 +1,9 @@ #!/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) @@ -12,9 +16,10 @@ do 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 $destpath/$prefix.epub $destpath/$prefix.mobi 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