added utility scripts to make publishing books easier
[project-aon.git] / common / scripts / copy-ebooks.sh
1 #!/usr/bin/env bash
2 #
3 # Copy ebook 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-ebooks.sh 05sots
9 #
10 #     list-bookcodes-by-series.sh gs | xargs copy-ebooks.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 BASE_DIR="$AONDIR/common/epub"
19 book_db="$AONDIR/common/sqlite/bookcodes.db"
20
21 for book in $@
22 do
23     row=($(sqlite3 -separator ' ' $book_db "select lang, series from bookcodes where book = '$book';"))
24
25     lang=${row[0]}
26     series=${row[1]}
27
28     source_dir="$BASE_DIR/$book"
29
30     for format in epub mobi fb2 pdb lrf
31     do
32         output_dir="$CURR_DIR/$lang/$format/$series"
33         mkdir -p "$output_dir"
34         cp -av "$source_dir/$book.$format" "$output_dir"
35     done
36 done