break hardcoded database credentials out of script

This commit is contained in:
2024-10-07 13:46:34 -07:00
parent fa7b845359
commit 148383b78d
5 changed files with 18 additions and 1 deletions

1
.gitignore vendored
View File

@@ -2,3 +2,4 @@
html-src/
ebooks/
*.csv
env

6
db_update.sh Normal file
View File

@@ -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

4
env.template Normal file
View File

@@ -0,0 +1,4 @@
DB_USER=<user>
DB_PASSWORD=<password>
DB_HOST=<server>
DB_DATABASE=<database>

View File

@@ -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 */;

View File

@@ -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