epic-s6ts
[kivitendo-erp.git] / scripts / build_doc.sh
1 #!/bin/bash
2
3 # Usage:
4 #   cd /path/to/kivitendo
5 #   ./scripts/build_doc.sh
6
7 set -e
8
9 if [[ ! -d doc ]]; then
10   echo "Please run this from the installation directory."
11   exit 1
12 fi
13
14 doc=${PWD}/doc
15
16 html=1
17 pdf=1
18 images=1
19
20 if [[ ! -z $1 ]] ; then
21   html=0
22   pdf=0
23   images=0
24   while [[ ! -z $1 ]] ; do
25     case $1 in
26       html)   html=1   ;;
27       pdf)    pdf=1    ;;
28       images) images=1 ;;
29       *)
30         echo "Unknown parameter $1"
31         exit 1
32         ;;
33     esac
34
35     shift
36   done
37 fi
38
39 dobudish=$(ls -d doc/build/dobudish* 2> /dev/null)
40
41 if [[ -z $dobudish ]] || [[ ! -d ${dobudish} ]]; then
42   echo "There's no dobudish directory inside doc/build OR more than one file / dir starting with dobudish (hint: zip file downloaded there?)."
43   exit 1
44 fi
45
46 cd ${dobudish}
47
48 base=documents/dokumentation
49 if [[ ! -d $base ]]; then
50   ./generator.sh dokumentation create book
51 fi
52
53 input=${base}/input
54 output=${base}/output
55 custom=${base}/custom-cfg
56
57 rm -rf ${input} ${custom}
58 mkdir ${input} ${input}/copy_to_output ${custom}
59
60 cp ${doc}/dokumentation.xml ${input}/
61 test -d ${doc}/images && cp -R ${doc}/images ${input}/copy_to_output/
62 cp -R ${doc}/build/custom-cfg/* ${custom}/
63
64 if [[ $pdf = 1 ]] ; then
65   ./generator.sh dokumentation pdf
66   cp ${output}/pdf/dokumentation.pdf ${doc}/kivitendo-Dokumentation.pdf
67 fi
68
69 if [[ $html = 1 ]]; then
70   ./generator.sh dokumentation html
71   rm -rf ${doc}/html
72   mkdir ${doc}/html
73   cp -R ${output}/html ${doc}/
74 fi
75
76 if [[ $images = 1 ]]; then
77   # copy system images from Dobudish directory
78   image_list=$(mktemp)
79   perl -nle 'print $1 while m{ (?: \.\./ )+ ( system/ [^\"]+ ) }xg' ${doc}/html/*.html | sort | uniq > $image_list
80   if [[ -s $image_list ]]; then
81     tar -c -f - -T $image_list | tar -x -f - -C ${doc}/html
82     perl -pi -e 's{ (\.\./)+ system }{system}xg' ${doc}/html/*.html
83   fi
84
85   rm $image_list
86 fi