clear
for cmd in capitalize htidy rst2man rst2html5 java fop gs manheader cpdf lower;
do
if ! command -v "$cmd" &> /dev/null; then
echo "Error: $cmd not found in PATH" >&2
exit 1
fi
done
version=''
section=''
category=''
prog=`basename "$0"`
MAKE_PDF_2=1
if [ "$1" == "-h" -o "$1" == "--help" ]
then
echo -e "\n\tusage: $prog"
exit 0
fi
if [ -f ./version_* ]
then
version=$(echo ./version_* | cut -d_ -f2)
fi
if [ -f ./section_* ]
then
section=$(echo ./section_* | cut -d_ -f2)
fi
if [ -f ./category_* ]
then
category=$(echo ./category_* | cut -d_ -f2)
fi
for rst in ./*.rst
do
NAME=`basename "$rst" .rst`
echo "$NAME"
lower_name=$(lower "$NAME")
MAN="../man/$lower_name.$section"
HTML="../html/$lower_name.html"
CSS="../html/$lower_name.css"
PDFDIR="../pdf"
DOCUTILS=$(docutils --version|cut -d '(' -f2|cut -d, -f1)
echo -e "\t->creating $MAN"
rst2man --rfc-references --title=`capitalize "$NAME"` ./"$rst" "$MAN"
echo -e "\t->correcting man-page headers"
manheader "$MAN" "$section" "$version" "$category"
gzip -9 -f "$MAN"
echo -e "\t->creating $HTML"
rst2html5 --rfc-references --title=`capitalize "$NAME"` --xml-declaration --stylesheet="$CSS" ./"$rst" "$HTML"
echo "--- calling HTML tidy -----"
htidy omit "$HTML"
if [ -d $PDFDIR ]
then
PDF="$PDFDIR"/"$lower_name".pdf
echo -e "\t->creating $PDF ... This will take a while ...\n"
XSL="$HOME/prog/html2Pdf.xsl"
GS="Ghostscript $(gs --version)"
FOP="FOP $(fop -v|cut -d ' ' -f3)"
SAXON="Saxon 12.9"
VIM="Vim $(vim --version | grep 'Vi IMproved' | cut -d ' ' -f5)"
CPDF="$(cpdf -version|cut -d' ' -f1,4)"
PMETA="$HOME/prog/m.xml"
if [ -e "./stylesheet.xsl" ]
then
XSL="./stylesheet.xsl"
echo "using project specific style sheet $XSL"
fi
FOOUT=/tmp/foout.fo
echo "------- CALLING SAXON for html2FO --------"
java -jar ~/bin/saxon-12.9/saxon-he-12.9.jar -s:"$HTML" -xsl:"$XSL" -o:"$FOOUT" loglevel='debug'
echo "------- CALLING FOP for fo2PDF --------"
fop -c ~/bin/fop-2.11/fop/conf/fop.xconf -fo "$FOOUT" -pdf "$PDF"
if [ $MAKE_PDF_2 != 0 ]
then
PDF_2="$PDFDIR"/"$lower_name"_2.0.pdf
echo "------- CALLING Ghostscript for PDF version 2 --------"
/usr/local/bin/gs -dEmbedAllFonts=true -dSubsetFonts=false -dPDFSETTINGS=/prepress \
-sDEVICE=pdfwrite -dOmitXMP=true -dCompatibilityLevel=2.0 \
-dNOPAUSE -dBATCH -o "$PDF_2" "$PDF"
if [ -e $PDF_2 ]
then
mv "$PDF_2" "$PDF"
else
echo -e "ERROR! PDF version 2.0 could NOT be created"
fi
echo "------- CALLING cpdf and set meta data and compress --------"
cpdf "$PDF" -set-creator "$VIM, $DOCUTILS" AND \
-set-producer "$SAXON, $FOP, $GS, $CPDF" AND \
-set-author "<michael.uplawski at uplawski.eu>" AND \
-compress AND \
-squeeze AND \
-set-title "$NAME manual" AND\
-o "$PDF_2"
if [ -e $PDF_2 ]
then
mv "$PDF_2" "$PDF"
else
echo -e "ERROR! Could not set PDF attributes."
fi
fi
fi
done