adding abnormal termination for errors
[project-aon.git] / common / scripts / copy-svg.sh
1 #!/usr/bin/env bash
2 #
3 # Copy SVG files for the specified book(s) to a directory structure that's
4 # ready to be pushed to the public website.
5 #
6 # Examples:
7 #
8 #     copy-svg.sh 05sots
9 #
10 #     list-bookcodes-by-series.sh gs | xargs copy-svg.sh
11
12 if [ ! -d "$AONDIR" ]; then
13     >&2 echo "Please set the AONDIR environment variable"
14     exit 1
15 fi
16 CURR_DIR=`pwd`
17
18 if [ "$AONDIR" -ef "$CURR_DIR" ]; then
19     >&2 echo "Current directory is the same as AONDIR: giving up"
20     exit 1
21 fi
22
23 book_db="$AONDIR/common/sqlite/bookcodes.db"
24
25 for book in $@
26 do
27     row=($(sqlite3 -separator ' ' $book_db "select lang, series from bookcodes where book = '$book';"))
28
29     lang=${row[0]}
30     series=${row[1]}
31
32     source_dir="$AONDIR/$lang/svg/$series"
33     output_dir="$CURR_DIR/$lang/svg/$series"
34     mkdir -p "$output_dir"
35     cp -av "$source_dir/$book.svgz" "$output_dir"
36 done