]> git.lyx.org Git - features.git/blob - development/tools/generate_manuals_for_web.sh
Push Tommaso script for manuals generation.
[features.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
23 LYX=${LYX:-$(abspath src/lyx)}
24 OUT=${OUT:-$HOME/web/lyxdoc}
25 TOC=${TOC:-lyxdoc/index.html}
26 TMP=${TMP:-$(mktemp -d)}
27
28 echo LYX=$LYX
29 echo OUT=$OUT
30 echo TOC=$TOC
31 echo TMP=$TMP
32
33 mycpus=$(grep -c processor /proc/cpuinfo)
34 function pexec {
35     while [ $(pidof lyx | wc -w) -ge $[$mycpus*15/10] -o $(pidof lyx | wc -w) -ge $[$mycpus*15/10] ]; do
36         sleep $(echo "$RANDOM * 5 / 32767" | bc -l)
37     done
38     echo -e "\e[39mRunning $@ ..."
39     eval "$@ > /dev/null 2>&1 && echo -e ... \\\\e[32mDONE\\\\e[39m with $@ || echo -e ... \\\\e[31mERROR\\\\e[39m on $@" &
40 }
41
42 if [ ! -d lib/doc -o ! -f lib/doc/Intro.lyx ]; then
43     echo "Run me from the LyX top dir"
44     exit 1
45 fi
46
47 if [ ! -f $LYX ]; then
48     echo "Cannot find the LyX executable at: $LYX"
49     exit 1
50 fi
51
52 mkdir -p $TMP/lyxdoc
53
54 cp -a lib/doc/* $TMP
55 cd $TMP
56
57 echo ""
58 echo "Manuals being processed in $TMP"
59 echo "Index of built manuals available at: file://$TMP/$TOC"
60 echo ""
61
62 cat > $TOC <<EOF
63 <html>
64 <body>
65 <h1>LyX manuals</h1>
66
67 <table>
68 <tr><th>Manual</th><th>Browse Link(s)</th><th>PDF Download(s)</th></tr>
69 EOF
70
71 for m in $MAIN_DOCS; do
72     echo "<tr><td>$m</td><td>" >> $TOC
73     find . -name $m.lyx | while read f; do
74         if [ ! -f lyxdoc/${f%%.lyx}.html.LyXconv/$m.html ]; then
75             pexec $LYX -E html lyxdoc/${f%%.lyx}.html $f;
76         else
77             echo "Skipping already existing lyxdoc/${f%%.lyx}.html"
78         fi
79         if echo $f | grep '/[a-zA-Z_]\+/' > /dev/null 2>&1; then
80             lang=$(echo $f | sed -e 's#.*/\([a-zA-Z_]\+\)/.*#\1#')
81         else
82             lang=en
83         fi
84         echo "<a href=\"${f%%.lyx}.html.LyXconv/$m.html\">[$lang]</a>" >> $TOC
85     done
86     echo "</td><td>" >> $TOC
87     find . -name $m.lyx | while read f; do
88         if [ ! -f lyxdoc/${f%%.lyx}.pdf ]; then
89             pexec $LYX -E pdf lyxdoc/${f%%.lyx}.pdf $f;
90         else
91             echo "Skipping already existing lyxdoc/${f%%.lyx}.pdf"
92         fi
93         if echo $f | grep '/[a-zA-Z_]\+/' > /dev/null 2>&1; then
94             lang=$(echo $f | sed -e 's#.*/\([a-zA-Z_]\+\)/.*#\1#')
95         else
96             lang=en
97         fi
98         echo "<a href=\"${f%%.lyx}.pdf\">[$lang]</a>" >> $TOC
99     done
100     echo "</tr>" >> $TOC
101 done
102 echo "</table>" >> $TOC
103
104 echo "Waiting for child processes to complete..."
105 wait
106
107 echo ""
108 echo "Manuals processed in $TMP"
109 echo "Index of built manuals available at: file://$TMP/$TOC"
110 echo ""