added utility scripts to make publishing books easier
[project-aon.git] / common / scripts / copy-xhtml.sh
1 #!/usr/bin/env bash
2 #
3 # Copy XHTML 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-xhtml.sh 05sots
9 #
10 #     list-bookcodes-by-series.sh gs | xargs copy-xhtml.sh
11
12 if [ ! -d "$AONDIR" ]; then
13     >&2 echo "Please set the AONDIR environment variable"
14     exit
15 fi
16 CURR_DIR=`pwd`
17
18 book_db="$AONDIR/common/sqlite/bookcodes.db"
19
20 for book in $@
21 do
22     row=($(sqlite3 -separator ' ' $book_db "select lang, series from bookcodes where book = '$book';"))
23
24     lang=${row[0]}
25     series=${row[1]}
26
27     for format in xhtml xhtml-less-simple
28     do
29         source_dir="$AONDIR/$lang/$format/$series/$book"
30         output_dir="$CURR_DIR/$lang/$format/$series/$book"
31         mkdir -p "$output_dir"
32         cp -av "$source_dir"/* "$output_dir"
33     done
34
35     source_dir="$AONDIR/$lang/xhtml-simple/$series"
36     output_dir="$CURR_DIR/$lang/xhtml-simple/$series"
37     mkdir -p "$output_dir"
38     cp -av "$source_dir/$book".* "$output_dir"
39 done