Add script to rsync the electronic books (epub et al) to the
[project-aon.git] / common / epub / build-epubs.sh
1 #!/bin/sh
2 #
3 # Build all the ePub files for Project Aon in a single run
4 #
5 # (c) 2011 Javier Fernandez-Sanguino <jfs@computer.org>
6 #
7 # This script is provided with the same license as that one
8 # used in the Aon Project
9
10 set -e
11
12 CURDIR=`pwd`
13 AONDIR="../../"
14 LOGDIR="$CURDIR/logs/"
15 [ ! -e "$LOGDIR" ] && mkdir $LOGDIR
16 LANGS="en es"
17 FONTDIR="../fontfiles/"
18
19 if [ ! -e "${AONDIR}${FONTDIR}" ] ; then
20     echo "The font directory (${AONDIR}${FONTDIR}) does not exist."
21     echo "Please create it and copy the Souvenir font to it "
22     echo "(or adjust this script to use an alternative directory)"
23     exit 1
24 fi
25
26 generate_files() {
27     ls ${AONDIR}/${lang}/xml/*.xml |
28     while read file ; do
29         if [ -r "$file" ]; then
30             xml=`basename $file | sed -e 's/\.xml//'`
31             # Look for the XML name in the ePub metadata
32             if grep -q ^$xml $EPUBDATA; then
33                 echo -n "Generating ePub file for $xml ('$lang' language)..."
34                 LOGFILE=$LOGDIR/$xml.epub.log
35                 cd $AONDIR 
36                 set +e 
37                 perl common/scripts/gbtoepub.pl --language=$lang --font-files=$FONTDIR $xml  >$LOGFILE 2>&1
38                 if [ $? -ne 0 ]; then
39                     echo " ERROR building file (review $LOGFILE)"
40                 fi
41                 set -e 
42                 cd $CURDIR
43                 echo "...done"
44             fi
45         else
46             echo "ERROR: Cannot generate ePub file for $xml (not readable)"
47         fi
48     done
49
50 }
51
52
53 for lang in $LANGS; do
54     EPUBDATA=${AONDIR}/${lang}/.publisher/rules/epub
55     if [ -e "$EPUBDATA" ] ; then
56        generate_files 
57     else
58         echo "ERROR: Cannot find the publisher rules at $EPUBDATA for $lang"
59     fi
60 done
61
62 exit 0