reorganizing the repository
[project-aon.git] / common / scripts / build-xhtml.sh
1 #!/bin/sh
2 #
3 # Build all the xHTML 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 [ -z "$AONDIR" ] && AONDIR="../../"
14 [ -z "$LANGS" ]  && LANGS="en es"
15 LOGDIR="$CURDIR/logs/"
16 [ ! -e "$LOGDIR" ] && mkdir $LOGDIR
17
18 if [ -n "$1" ] ; then
19     BOOKS="$1"
20 else
21     BOOKS='*'
22 fi
23
24 generate_files() {
25     ls ${AONDIR}/${lang}/xml/$1.xml |
26     while read file ; do
27         if [ -r "$file" ]; then
28             xml=`basename $file | sed -e 's/\.xml//'`
29             # Look for the XML name in the metadata file
30             if grep -q ^$xml $METADATA; then
31                 echo -n "Generating XHTML for $xml ('$lang' language)..."
32                 LOGFILE=$LOGDIR/$xml.xhtml.log
33                 cd $AONDIR 
34                 set +e 
35                 perl common/scripts/gbtoxhtml.pl --language=$lang $xml >$LOGFILE 2>&1
36                 if [ $? -ne 0 ]; then
37                     echo " ERROR building Xhtml file (review $LOGFILE)"
38                 fi
39                 echo "...done"
40                 LOGFILE=$LOGDIR/$xml.xhtml-simple.log
41                 echo -n "Building XHTML simple"
42                 perl common/scripts/gbtoxhtml-simple.pl --language=$lang $xml >$LOGFILE 2>&1
43                 if [ $? -ne 0 ]; then
44                     echo " ERROR building xhtml simple file (review $LOGFILE)"
45                 fi
46                 echo "...done"
47                 LOGFILE=$LOGDIR/$xml.xhtml-less-simple.log
48                 echo -n "Building XHTML less simple"
49                 perl common/scripts/gbtoxhtml-less-simple.pl --language=$lang $xml >$LOGFILE 2>&1
50                 if [ $? -ne 0 ]; then
51                     echo " ERROR building xhtml less simple file (review $LOGFILE)"
52                 fi
53                 echo "...done"
54                 set -e 
55                 cd $CURDIR
56             else 
57                 echo "WARN: Do not find metadata for $xml in $METADATA"
58             fi
59         else
60             echo "ERROR: Cannot generate xhtml file for $xml (not readable)"
61         fi
62     done
63 }
64
65 for lang in $LANGS; do
66     METADATA=${AONDIR}/${lang}/.publisher/rules/simple
67     if [ -e "$METADATA" ] ; then
68         generate_files "$BOOKS"
69     else
70         echo "ERROR: Cannot find the publisher rules at $METADATA for $lang"
71     fi
72 done
73
74 exit 0