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