Blame Automation/Modules/Render/Docbook/docbook_setExpansionLicenses.sh

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