added new script to list all book info from bookcodes.db
authorJonathan Blake <jonathan.blake@projectaon.org>
Thu, 15 Feb 2018 15:45:50 +0000 (15:45 +0000)
committerJonathan Blake <jonathan.blake@projectaon.org>
Thu, 15 Feb 2018 15:45:50 +0000 (15:45 +0000)
adjusted the copy-* scripts to use the new script

git-svn-id: https://projectaon.org/data/trunk@2695 f6f3e2d7-ff33-0410-aaf5-b4bee2cdac11

common/scripts/copy-ebooks.sh
common/scripts/copy-svg.sh
common/scripts/copy-xhtml.sh
common/scripts/list-book-info.sh [new file with mode: 0755]

index 1e76fc5..651c0c5 100755 (executable)
@@ -21,14 +21,13 @@ if [ "$AONDIR" -ef "$CURR_DIR" ]; then
 fi
 
 BASE_DIR="$AONDIR/common/epub"
-book_db="$AONDIR/common/sqlite/bookcodes.db"
 
 for book in $@
 do
-    row=($(sqlite3 -separator ' ' $book_db "select lang, series from bookcodes where book = '$book';"))
+    row=( $($AONDIR/common/scripts/list-book-info.sh $book) )
 
-    lang=${row[0]}
-    series=${row[1]}
+    lang=${row[1]}
+    series=${row[2]}
 
     source_dir="$BASE_DIR/$book"
 
index a057dc4..532af7c 100755 (executable)
@@ -20,14 +20,12 @@ if [ "$AONDIR" -ef "$CURR_DIR" ]; then
     exit 1
 fi
 
-book_db="$AONDIR/common/sqlite/bookcodes.db"
-
 for book in $@
 do
-    row=($(sqlite3 -separator ' ' $book_db "select lang, series from bookcodes where book = '$book';"))
+    row=( $($AONDIR/common/scripts/list-book-info.sh $book) )
 
-    lang=${row[0]}
-    series=${row[1]}
+    lang=${row[1]}
+    series=${row[2]}
 
     source_dir="$AONDIR/$lang/svg/$series"
     output_dir="$CURR_DIR/$lang/svg/$series"
index 0dde264..49ec516 100755 (executable)
@@ -20,14 +20,12 @@ if [ "$AONDIR" -ef "$CURR_DIR" ]; then
     exit 1
 fi
 
-book_db="$AONDIR/common/sqlite/bookcodes.db"
-
 for book in $@
 do
-    row=($(sqlite3 -separator ' ' $book_db "select lang, series from bookcodes where book = '$book';"))
+    row=( $($AONDIR/common/scripts/list-book-info.sh $book) )
 
-    lang=${row[0]}
-    series=${row[1]}
+    lang=${row[1]}
+    series=${row[2]}
 
     for format in xhtml xhtml-less-simple
     do
diff --git a/common/scripts/list-book-info.sh b/common/scripts/list-book-info.sh
new file mode 100755 (executable)
index 0000000..4d9473c
--- /dev/null
@@ -0,0 +1,41 @@
+#!/usr/bin/env bash
+#
+# List all book into that match given bookcode(s). If the bookcode is omitted,
+# outputs data for all books.
+# 
+# Examples:
+#     list-book-info.sh lw gs
+#
+#     list-book-info.sh
+
+if [ ! -d "$AONDIR" ]; then
+    >&2 echo "Please set the AONDIR environment variable"
+    exit 1
+fi
+
+book_db="$AONDIR/common/sqlite/bookcodes.db"
+
+if [ -z "$1" ]; then
+    sqlite3 -column -noheader "$book_db" <<EOF
+        select book, lang, series
+        from bookcodes
+        order by book
+EOF
+    exit
+fi
+
+
+for book in $@
+do
+    if [[ ! $book =~ ^[a-z0-9]+[a-z]$ ]]; then
+        >&2 echo "invalid book code"
+        exit
+    fi
+
+    sqlite3 -column -noheader "$book_db" <<EOF
+      select book, lang, series
+      from bookcodes 
+      where book = '$book'
+      order by book
+EOF
+done