]> git.lyx.org Git - lyx.git/blob - development/tools/generate_manuals_for_web.sh
oops, git is playing games with me.
[lyx.git] / development / tools / generate_manuals_for_web.sh
1 #!/bin/bash
2
3 # file manuals_for_web.sh
4 # This file is part of LyX, the document processor.
5 # Licence details can be found in the file COPYING.
6 #
7 # \author Tommaso Cucinotta
8 # \author Pavel Sanda
9 #
10 # Full author contact details are available in file CREDITS
11
12 # Usage:
13 # manuals_for_web.sh (just launch from the LyX git root folder)
14 #
15 # optional env vars that customize behavior:
16 #   $LYX - abs path to LyX executable
17 #   $OUT - final folder where all converted manuals are placed
18 #   $TOC - final index.html that links all converted manuals
19 #   $TMP - temporary folder where all the conversion is done
20
21 MAIN_DOCS=${MAIN_DOCS:-"Intro Tutorial UserGuide Math Additional Customization Shortcuts LFUNs"}
22 LYX=${LYX:-${PWD}/src/lyx}
23 OUT=${OUT:-$HOME/web/lyxdoc}
24 TOC=${TOC:-lyxdoc/index.html}
25 TMP=${TMP:-$(mktemp -d)}
26
27 echo LYX=$LYX
28 echo OUT=$OUT
29 echo TOC=$TOC
30 echo TMP=$TMP
31
32 mycpus=$(grep -c processor /proc/cpuinfo)
33 function pexec {
34     while [ $(pidof lyx | wc -w) -ge $[$mycpus*15/10] -o $(pidof lyx | wc -w) -ge $[$mycpus*15/10] ]; do
35         sleep $(echo "$RANDOM * 5 / 32767" | bc -l)
36     done
37     echo -e "\e[39mRunning $@ ..."
38     eval "$@ > /dev/null 2>&1 && echo -e ... \\\\e[32mDONE\\\\e[39m with $@ || echo -e ... \\\\e[31mERROR\\\\e[39m on $@" &
39 }
40
41 if [ ! -d lib/doc -o ! -f lib/doc/Intro.lyx ]; then
42     echo "Run me from the LyX top dir"
43     exit 1
44 fi
45
46 if [ ! -f $LYX ]; then
47     echo "Cannot find the LyX executable at: $LYX"
48     exit 1
49 fi
50
51 mkdir -p $TMP/lyxdoc
52
53 cp -a lib/doc/* $TMP
54 cd $TMP
55
56 echo ""
57 echo "Manuals being processed in $TMP"
58 echo "Index of built manuals available at: file://$TMP/$TOC"
59 echo ""
60
61 cat > $TOC <<EOF
62 <html>
63 <body>
64 <h1>LyX manuals</h1>
65
66 <table>
67 <tr><th>Manual</th><th>Browse Link(s)</th><th>PDF Download(s)</th></tr>
68 EOF
69
70 for m in $MAIN_DOCS; do
71     echo "<tr><td>$m</td><td>" >> $TOC
72     find . -name $m.lyx | while read f; do
73         if [ ! -f lyxdoc/${f%%.lyx}.html.LyXconv/$m.html ]; then
74             pexec $LYX -E xhtml lyxdoc/${f%%.lyx}.html $f;
75         else
76             echo "Skipping already existing lyxdoc/${f%%.lyx}.html"
77         fi
78         if echo $f | grep '/[a-zA-Z_]\+/' > /dev/null 2>&1; then
79             lang=$(echo $f | sed -e 's#.*/\([a-zA-Z_]\+\)/.*#\1#')
80         else
81             lang=en
82         fi
83         echo "<a href=\"${f%%.lyx}.html\">[$lang]</a>" >> $TOC
84     done
85     echo "</td><td>" >> $TOC
86     find . -name $m.lyx | while read f; do
87         if [ ! -f lyxdoc/${f%%.lyx}.pdf ]; then
88             pexec $LYX -E pdf lyxdoc/${f%%.lyx}.pdf $f;
89         else
90             echo "Skipping already existing lyxdoc/${f%%.lyx}.pdf"
91         fi
92         if echo $f | grep '/[a-zA-Z_]\+/' > /dev/null 2>&1; then
93             lang=$(echo $f | sed -e 's#.*/\([a-zA-Z_]\+\)/.*#\1#')
94         else
95             lang=en
96         fi
97         echo "<a href=\"${f%%.lyx}.pdf\">[$lang]</a>" >> $TOC
98     done
99     echo "</tr>" >> $TOC
100 done
101 echo "</table>" >> $TOC
102
103 echo "Waiting for child processes to complete..."
104 wait
105
106 echo ""
107 echo "Manuals processed in $TMP"
108 echo "Index of built manuals available at: file://$TMP/$TOC"
109 echo ""