Blame Scripts/Bash/Functions/Render/Docbook/docbook_expandLicenses.sh

86e000
#!/bin/bash
86e000
#
86e000
# docbook_expandLicenses.sh -- This function modifies the final
86e000
# DocBook instance to add license information. We are doing this way
86e000
# because using XInclude doesn't work and we want to reuse license
86e000
# information in all documents. So, if we cannot link the files, we
86e000
# modify the final instance and append the license information to it.
86e000
# Later, to reuse translation messages, the locale functionality takes
86e000
# care of merging po files related to licenses into documentation po
86e000
# file so changes made to licenses translations will also be available
86e000
# to documentation manuals in different languages.
86e000
#
077011
# Copyright (C) 2009, 2010, 2011, 2012 The CentOS Project
86e000
#
86e000
# This program is free software; you can redistribute it and/or modify
86e000
# it under the terms of the GNU General Public License as published by
86e000
# the Free Software Foundation; either version 2 of the License, or (at
86e000
# your option) any later version.
86e000
#
86e000
# This program is distributed in the hope that it will be useful, but
86e000
# WITHOUT ANY WARRANTY; without even the implied warranty of
86e000
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
86e000
# General Public License for more details.
86e000
#
86e000
# You should have received a copy of the GNU General Public License
86e000
# along with this program; if not, write to the Free Software
86e000
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
86e000
#
86e000
# ----------------------------------------------------------------------
86e000
# $Id$
86e000
# ----------------------------------------------------------------------
86e000
86e000
function docbook_expandLicenses {
86e000
86e000
    local INSTANCE=$1
86e000
819c26
    # Define absolute path to DocBook models.
819c26
    local DOCBOOK_MODELS="${TCAR_WORKDIR}/Documentation/Models/Docbook"
2321ce
86e000
    # Define list of files holding licenses you want to include. Note
86e000
    # even this files are not inside the documentation structure
86e000
    # itself, they are connected with it. The files holding license
86e000
    # information does contain id information used inside the
86e000
    # documentation structure at cross references.
2321ce
    local LICENSES="${DOCBOOK_MODELS}/Default/Licenses/gpl.docbook \
2321ce
        ${DOCBOOK_MODELS}/Default/Licenses/gfdl.docbook"
86e000
86e000
    # Define top level structure in the instance. This is the tag
86e000
    # defined in the second field of DOCTYPE definition.
86e000
    local DOCTYPE=$(egrep '^
86e000
        | gawk '{ print $2 }')
86e000
86e000
    # Define temporal file to store license block.
86e000
    local BLOCK=$(cli_getTemporalFile "licenses.docbook")
86e000
86e000
    # Build license block into memory.
86e000
    BLOCK="\n"
86e000
    BLOCK="${BLOCK}\n<part id=\"licenses\">\n"
86e000
    BLOCK="${BLOCK}\n<title>`gettext "Licenses"`</title>\n"
86e000
    BLOCK="${BLOCK}\n$(cat ${LICENSES} | sed -r '/<\?xml/,/]>/d')\n"
86e000
    BLOCK="${BLOCK}\n</part>\n"
86e000
    BLOCK="${BLOCK}\n\n"
86e000
86e000
    # Expand the licenses section. Remove everything in-between
86e000
    # Licenses and Back matter comment. Recreate the comments to
86e000
    # support further actualizations and concatenate license
86e000
    # information without their document type definitions preamble.
86e000
    # This is required in order to prevent validation errors and reuse
86e000
    # (through locale functionality) the translation messages already
86e000
    # available for these license files. Finally, close any open tag.
86e000
    sed -r -i -e "//,//c$(echo ${BLOCK})" $INSTANCE
86e000
86e000
}