added utility scripts to make publishing books easier
authorJonathan Blake <jonathan.blake@projectaon.org>
Thu, 15 Feb 2018 04:15:06 +0000 (04:15 +0000)
committerJonathan Blake <jonathan.blake@projectaon.org>
Thu, 15 Feb 2018 04:15:06 +0000 (04:15 +0000)
git-svn-id: https://projectaon.org/data/trunk@2692 f6f3e2d7-ff33-0410-aaf5-b4bee2cdac11

common/scripts/copy-all-formats.sh [new file with mode: 0755]
common/scripts/copy-ebooks.sh [new file with mode: 0755]
common/scripts/copy-svg.sh [new file with mode: 0755]
common/scripts/copy-xhtml.sh [new file with mode: 0755]
common/scripts/list-bookcodes-all.sh [new file with mode: 0755]
common/scripts/list-bookcodes-by-lang.sh [new file with mode: 0755]
common/scripts/list-bookcodes-by-series.sh [new file with mode: 0755]
common/sqlite/bookcodes.db [new file with mode: 0644]

diff --git a/common/scripts/copy-all-formats.sh b/common/scripts/copy-all-formats.sh
new file mode 100755 (executable)
index 0000000..3440ad9
--- /dev/null
@@ -0,0 +1,20 @@
+#!/usr/bin/env bash
+#
+# Copy all formats for the specified book(s) to a directory structure that's
+# ready to be pushed to the public website.
+#
+# Examples:
+#
+#     copy-all-formats.sh 05sots
+#
+#     list-bookcodes-by-series.sh gs | xargs copy-all-formats.sh
+
+if [ ! -d "$AONDIR" ]; then
+    >&2 echo "Please set the AONDIR environment variable"
+    exit
+fi
+BASE_DIR="$AONDIR/common/scripts"
+
+"$BASE_DIR/copy-xhtml.sh" "$@"
+"$BASE_DIR/copy-svg.sh" "$@"
+"$BASE_DIR/copy-ebooks.sh" "$@"
diff --git a/common/scripts/copy-ebooks.sh b/common/scripts/copy-ebooks.sh
new file mode 100755 (executable)
index 0000000..3c39738
--- /dev/null
@@ -0,0 +1,36 @@
+#!/usr/bin/env bash
+#
+# Copy ebook files for the specified book(s) to a directory structure that's
+# ready to be pushed to the public website.
+#
+# Examples:
+#
+#     copy-ebooks.sh 05sots
+#
+#     list-bookcodes-by-series.sh gs | xargs copy-ebooks.sh
+
+if [ ! -d "$AONDIR" ]; then
+    >&2 echo "Please set the AONDIR environment variable"
+    exit
+fi
+CURR_DIR=`pwd`
+
+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';"))
+
+    lang=${row[0]}
+    series=${row[1]}
+
+    source_dir="$BASE_DIR/$book"
+
+    for format in epub mobi fb2 pdb lrf
+    do
+        output_dir="$CURR_DIR/$lang/$format/$series"
+        mkdir -p "$output_dir"
+        cp -av "$source_dir/$book.$format" "$output_dir"
+    done
+done
diff --git a/common/scripts/copy-svg.sh b/common/scripts/copy-svg.sh
new file mode 100755 (executable)
index 0000000..f2b7e08
--- /dev/null
@@ -0,0 +1,31 @@
+#!/usr/bin/env bash
+#
+# Copy SVG files for the specified book(s) to a directory structure that's
+# ready to be pushed to the public website.
+#
+# Examples:
+#
+#     copy-svg.sh 05sots
+#
+#     list-bookcodes-by-series.sh gs | xargs copy-svg.sh
+
+if [ ! -d "$AONDIR" ]; then
+    >&2 echo "Please set the AONDIR environment variable"
+    exit
+fi
+CURR_DIR=`pwd`
+
+book_db="$AONDIR/common/sqlite/bookcodes.db"
+
+for book in $@
+do
+    row=($(sqlite3 -separator ' ' $book_db "select lang, series from bookcodes where book = '$book';"))
+
+    lang=${row[0]}
+    series=${row[1]}
+
+    source_dir="$AONDIR/$lang/svg/$series"
+    output_dir="$CURR_DIR/$lang/svg/$series"
+    mkdir -p "$output_dir"
+    cp -av "$source_dir/$book.svgz" "$output_dir"
+done
diff --git a/common/scripts/copy-xhtml.sh b/common/scripts/copy-xhtml.sh
new file mode 100755 (executable)
index 0000000..cce7ada
--- /dev/null
@@ -0,0 +1,39 @@
+#!/usr/bin/env bash
+#
+# Copy XHTML files for the specified book(s) to a directory structure that's
+# ready to be pushed to the public website.
+#
+# Examples:
+#
+#     copy-xhtml.sh 05sots
+#
+#     list-bookcodes-by-series.sh gs | xargs copy-xhtml.sh
+
+if [ ! -d "$AONDIR" ]; then
+    >&2 echo "Please set the AONDIR environment variable"
+    exit
+fi
+CURR_DIR=`pwd`
+
+book_db="$AONDIR/common/sqlite/bookcodes.db"
+
+for book in $@
+do
+    row=($(sqlite3 -separator ' ' $book_db "select lang, series from bookcodes where book = '$book';"))
+
+    lang=${row[0]}
+    series=${row[1]}
+
+    for format in xhtml xhtml-less-simple
+    do
+        source_dir="$AONDIR/$lang/$format/$series/$book"
+        output_dir="$CURR_DIR/$lang/$format/$series/$book"
+        mkdir -p "$output_dir"
+        cp -av "$source_dir"/* "$output_dir"
+    done
+
+    source_dir="$AONDIR/$lang/xhtml-simple/$series"
+    output_dir="$CURR_DIR/$lang/xhtml-simple/$series"
+    mkdir -p "$output_dir"
+    cp -av "$source_dir/$book".* "$output_dir"
+done
diff --git a/common/scripts/list-bookcodes-all.sh b/common/scripts/list-bookcodes-all.sh
new file mode 100755 (executable)
index 0000000..043835b
--- /dev/null
@@ -0,0 +1,12 @@
+#!/usr/bin/env bash
+#
+# List all bookcodes.
+
+if [ ! -d "$AONDIR" ]; then
+    >&2 echo "Please set the AONDIR environment variable"
+    exit
+fi
+
+book_db="$AONDIR/common/sqlite/bookcodes.db"
+
+sqlite3 -column -noheader "$book_db" "select book from bookcodes order by book"
diff --git a/common/scripts/list-bookcodes-by-lang.sh b/common/scripts/list-bookcodes-by-lang.sh
new file mode 100755 (executable)
index 0000000..edf62bf
--- /dev/null
@@ -0,0 +1,28 @@
+#!/usr/bin/env bash
+#
+# List all bookcodes that match given language.
+# 
+# Example:
+#     list-bookcodes-by-lang.sh en es
+
+if [ ! -d "$AONDIR" ]; then
+    >&2 echo "Please set the AONDIR environment variable"
+    exit
+fi
+
+book_db="$AONDIR/common/sqlite/bookcodes.db"
+
+for lang in $@
+do
+    if [[ ! $lang =~ ^[a-z][a-z]$ ]]; then
+        >&2 echo "invalid language"
+        exit
+    fi
+
+    sqlite3 -column -noheader "$book_db" <<EOF
+      select book 
+      from bookcodes 
+      where lang = '$lang'
+      order by book
+EOF
+done
diff --git a/common/scripts/list-bookcodes-by-series.sh b/common/scripts/list-bookcodes-by-series.sh
new file mode 100755 (executable)
index 0000000..88d9924
--- /dev/null
@@ -0,0 +1,28 @@
+#!/usr/bin/env bash
+#
+# List all bookcodes that match given series.
+# 
+# Example:
+#     list-bookcodes-by-series.sh lw gs
+
+if [ ! -d "$AONDIR" ]; then
+    >&2 echo "Please set the AONDIR environment variable"
+    exit
+fi
+
+book_db="$AONDIR/common/sqlite/bookcodes.db"
+
+for series in $@
+do
+    if [[ ! $series =~ ^[a-z][a-z]$ ]]; then
+        >&2 echo "invalid series"
+        exit
+    fi
+
+    sqlite3 -column -noheader "$book_db" <<EOF
+      select book 
+      from bookcodes 
+      where series = '$series'
+      order by book
+EOF
+done
diff --git a/common/sqlite/bookcodes.db b/common/sqlite/bookcodes.db
new file mode 100644 (file)
index 0000000..dc8898b
Binary files /dev/null and b/common/sqlite/bookcodes.db differ