ec3027990fcefd1adee3ea3ac37de768b3cf39d3
[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 book, lang, series
21         from bookcodes
22         order by book
23 EOF
24     exit
25 fi
26
27
28 for book in $@
29 do
30     if [[ ! $book =~ ^[a-z0-9]+[a-z]$ ]]; then
31         >&2 echo "invalid book code"
32         exit
33     fi
34
35     sqlite3 -column -noheader "$book_db" <<EOF
36       select book, lang, series
37       from bookcodes 
38       where book = '$book'
39       order by book
40 EOF
41 done