Make it possible to generate 29tsoc ebooks
[project-aon.git] / common / scripts / list-book-info.sh
1 #!/usr/bin/env bash
2 #
3 # List all book into that match given bookcode(s). If the bookcode is omitted,
4 # outputs data for all books.
5
6 # Examples:
7 #     list-book-info.sh 01fftd 02tfc
8 #
9 #     list-book-info.sh
10
11 if [ ! -d "$AONDIR" ]; then
12     >&2 echo "Please set the AONDIR environment variable"
13     exit 1
14 fi
15
16 book_db="$AONDIR/common/sqlite/bookcodes.db"
17
18 if [ -z "$1" ]; then
19     sqlite3 -column -noheader "$book_db" <<EOF
20         select 
21             book
22             , lang
23             , series
24             , subseries
25             , xml_file
26         from bookcodes
27         order by book
28 EOF
29     exit
30 fi
31
32
33 for book in $@
34 do
35     if [[ ! $book =~ ^[a-z0-9]+[a-z]$ ]]; then
36         >&2 echo "invalid book code"
37         exit
38     fi
39
40     sqlite3 -column -noheader "$book_db" <<EOF
41       select
42             book
43             , lang
44             , series
45             , subseries
46             , xml_file
47       from bookcodes 
48       where book = '$book'
49       order by book
50 EOF
51 done