Blame Scripts/Functions/Help/Backends/Docbook/docbook_updateOutputFilePdf.sh

1a4d0e
#!/bin/bash
1a4d0e
#
1a4d0e
# docbook_updateOutputFilePdf.sh -- This function uses the xsltproc
1a4d0e
# for transforming the repository documentation manual from DocBook to
1a4d0e
# PDF.
1a4d0e
#
1a4d0e
# Copyright (C) 2009, 2010, 2011 The CentOS Artwork SIG
1a4d0e
#
1a4d0e
# This program is free software; you can redistribute it and/or modify
1a4d0e
# it under the terms of the GNU General Public License as published by
1a4d0e
# the Free Software Foundation; either version 2 of the License, or
1a4d0e
# (at your option) any later version.
1a4d0e
#
1a4d0e
# This program is distributed in the hope that it will be useful, but
1a4d0e
# WITHOUT ANY WARRANTY; without even the implied warranty of
1a4d0e
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1a4d0e
# General Public License for more details.
1a4d0e
#
1a4d0e
# You should have received a copy of the GNU General Public License
1a4d0e
# along with this program; if not, write to the Free Software
1a4d0e
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1a4d0e
#
1a4d0e
# ----------------------------------------------------------------------
1a4d0e
# $Id$
1a4d0e
# ----------------------------------------------------------------------
1a4d0e
1a4d0e
function docbook_updateOutputFilePdf {
1a4d0e
1a4d0e
    # Print action message.
1a4d0e
    cli_printMessage "${MANUAL_BASEFILE}.pdf" --as-updating-line
1a4d0e
1a4d0e
    # Define name of temporal directory. This directory is where the
1a4d0e
    # transformation will take place.
1a4d0e
    local TMPDIR=$(cli_getTemporalFile "docbook2pdf")
1a4d0e
1a4d0e
    # Define absolute path to DocBook source file.
1a4d0e
    local SRC=${MANUAL_BACKEND}/${MANUAL_NAME}.docbook
1a4d0e
1a4d0e
    # Define absolute path to PDF target file.
1a4d0e
    local DST="${MANUAL_BASEFILE}.pdf"
1a4d0e
1a4d0e
    # Define absolute path of the XSLT file used to create the
1a4d0e
    # formatting object (.fo) file.
1a4d0e
    local XSLT=/usr/share/sgml/docbook/xsl-stylesheets/fo/docbook.xsl
1a4d0e
1a4d0e
    # Define file name of formatting object (.fo) file.
1a4d0e
    local FO=${MANUAL_NAME}.fo
1a4d0e
1a4d0e
    # Define file name of PDF file. 
1a4d0e
    local PDF=${MANUAL_NAME}.pdf
1a4d0e
1a4d0e
    # Verify temporal directory and create it if doesn't exist.
1a4d0e
    if [[ ! -d $TMPDIR ]];then
1a4d0e
        mkdir $TMPDIR
1a4d0e
    fi
1a4d0e
1a4d0e
    # Move inside temporal directory.
1a4d0e
    pushd $TMPDIR > /dev/null
1a4d0e
1a4d0e
    # Create formatting object supressing output from stderr.
1a4d0e
    xsltproc ${XSLT} ${SRC} 2> /dev/null > ${FO}
1a4d0e
1a4d0e
    # Create pdf format from formatting object. The pdfxmltex commad
1a4d0e
    # must be executed twice in order for cross-references to be built
1a4d0e
    # correctly.
1a4d0e
    if [[ $? -eq 0 ]];then
1a4d0e
        pdfxmltex ${FO} > /dev/null
1a4d0e
        pdfxmltex ${FO} > /dev/null
1a4d0e
    fi
1a4d0e
1a4d0e
    # Move PDF file from temporal directory to its target location.
1a4d0e
    if [[ $? -eq 0 ]];then
1a4d0e
        mv $PDF $DST
1a4d0e
    fi
1a4d0e
1a4d0e
    # Return to where we initially were.
1a4d0e
    popd > /dev/null
1a4d0e
1a4d0e
    # Remove temporal directory.
1a4d0e
    rm -r $TMPDIR
1a4d0e
1a4d0e
}