added utility scripts to make publishing books easier
[project-aon.git] / common / scripts / list-bookcodes-by-lang.sh
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