Blame Scripts/Modules/Prepare/prepare_setRenderEnvironment.sh

Alain Reguera Delgado 733076
#!/bin/bash
Alain Reguera Delgado 733076
######################################################################
Alain Reguera Delgado 733076
#
Alain Reguera Delgado 733076
#   prepare_setRenderEnvironment.sh -- This function provides a secure
Alain Reguera Delgado 733076
#   interface to render content outside the render module. You can use
Alain Reguera Delgado 733076
#   this function to call the render module from other modules,
Alain Reguera Delgado 733076
#   safely. 
Alain Reguera Delgado 733076
#
Alain Reguera Delgado 733076
#   This function builds a list of all available configuration files
Alain Reguera Delgado 733076
#   in locations passed as argument and reduces the list by applying
Alain Reguera Delgado 733076
#   regular expression patterns to each file in the list. Only files
Alain Reguera Delgado 733076
#   that match the regular expression pattern will remain in the final
Alain Reguera Delgado 733076
#   list. The regular expression patterns are applied to file's
Alain Reguera Delgado 733076
#   content, generally to find out if it has an specific option, value
Alain Reguera Delgado 733076
#   or combination of both inside.  Later, the resultant list of
Alain Reguera Delgado 733076
#   configuration files is passed to render module for processing.
Alain Reguera Delgado 733076
#
Alain Reguera Delgado 733076
#   This function verifies the search path provided to render module
Alain Reguera Delgado 733076
#   to grant it is inside the repository before passing it to render
Alain Reguera Delgado 733076
#   module for processing.
Alain Reguera Delgado 733076
#
Alain Reguera Delgado 733076
#   Written by:
Alain Reguera Delgado 733076
#   * Alain Reguera Delgado <al@centos.org.cu>, 2009-2013
Alain Reguera Delgado 733076
#
Alain Reguera Delgado 733076
# Copyright (C) 2009-2013 The CentOS Artwork SIG
Alain Reguera Delgado 733076
#
Alain Reguera Delgado 733076
# This program is free software; you can redistribute it and/or modify
Alain Reguera Delgado 733076
# it under the terms of the GNU General Public License as published by
Alain Reguera Delgado 733076
# the Free Software Foundation; either version 2 of the License, or (at
Alain Reguera Delgado 733076
# your option) any later version.
Alain Reguera Delgado 733076
#
Alain Reguera Delgado 733076
# This program is distributed in the hope that it will be useful, but
Alain Reguera Delgado 733076
# WITHOUT ANY WARRANTY; without even the implied warranty of
Alain Reguera Delgado 733076
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Alain Reguera Delgado 733076
# General Public License for more details.
Alain Reguera Delgado 733076
#
Alain Reguera Delgado 733076
# You should have received a copy of the GNU General Public License
Alain Reguera Delgado 733076
# along with this program; if not, write to the Free Software
Alain Reguera Delgado 733076
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Alain Reguera Delgado 733076
#
Alain Reguera Delgado 733076
######################################################################
Alain Reguera Delgado 733076
Alain Reguera Delgado 733076
function prepare_setRenderEnvironment {
Alain Reguera Delgado 733076
Alain Reguera Delgado 733076
    OPTIND=1
Alain Reguera Delgado 733076
    while getopts "o:,v:" OPTION "${@}"; do
Alain Reguera Delgado 733076
Alain Reguera Delgado 733076
        case "${OPTION}" in
Alain Reguera Delgado 733076
Alain Reguera Delgado 733076
            o )
Alain Reguera Delgado 733076
                # Define the name of the option you want to look
Alain Reguera Delgado 733076
                # configuration files for.
Alain Reguera Delgado 733076
                local OPTION_NAME=${OPTARG}
Alain Reguera Delgado 733076
                if [[ -z ${OPTION_NAME} ]];then
Alain Reguera Delgado 733076
                    tcar_printMessage "`gettext "The option name cannot be empty."`" --as-error-line
Alain Reguera Delgado 733076
                fi
Alain Reguera Delgado 733076
                ;;
Alain Reguera Delgado 733076
Alain Reguera Delgado 733076
            v )
Alain Reguera Delgado 733076
                # Define the value of the option you want to look
Alain Reguera Delgado 733076
                # configuration files for.
Alain Reguera Delgado 733076
                local OPTION_VALUE=${OPTARG}
Alain Reguera Delgado 733076
                if [[ -z ${OPTION_VALUE} ]];then
Alain Reguera Delgado 733076
                    tcar_printMessage "`gettext "The option value cannot be empty."`" --as-error-line
Alain Reguera Delgado 733076
                fi
Alain Reguera Delgado 733076
                ;;
Alain Reguera Delgado 733076
Alain Reguera Delgado 733076
        esac
Alain Reguera Delgado 733076
Alain Reguera Delgado 733076
    done
Alain Reguera Delgado 733076
Alain Reguera Delgado 733076
    # Clean up positional parameters to reflect the fact that options
Alain Reguera Delgado 733076
    # have been processed already.
Alain Reguera Delgado 733076
    shift $(( ${OPTIND} - 1 ))
Alain Reguera Delgado 733076
Alain Reguera Delgado 733076
    # Now that option arguments have been removed from positional
Alain Reguera Delgado 733076
    # parameter, verify all other remaining arguments (the search
Alain Reguera Delgado 733076
    # paths) do exist. They are required to search.
Alain Reguera Delgado 733076
    if [[ -z ${@} ]];then
Alain Reguera Delgado 733076
        tcar_printMessage "`gettext "The search path cannot be empty."`" --as-error-line
Alain Reguera Delgado 733076
    fi
Alain Reguera Delgado 733076
Alain Reguera Delgado 733076
    # Define array variable to store configuration file paths.
Alain Reguera Delgado 733076
    local -a CONFIGURATION_FILES
Alain Reguera Delgado 733076
Alain Reguera Delgado 733076
    # Define final filter regular expression. This regular expression
Alain Reguera Delgado 733076
    # must match the option = "value" format we are using inside
Alain Reguera Delgado 733076
    # configuration files.
Alain Reguera Delgado 733076
    local CONFIGURATION_PATTERN="^${OPTION_NAME}[[:space:]]*=[[:space:]]*\"${OPTION_VALUE}\"$"
Alain Reguera Delgado 733076
Alain Reguera Delgado 733076
    for DIRECTORY in ${@};do
Alain Reguera Delgado 733076
Alain Reguera Delgado 733076
        # Clean-up the search path. This location must point a
Alain Reguera Delgado 733076
        # directory inside the repository. References to directories
Alain Reguera Delgado 733076
        # outside the repository are not supported.
Alain Reguera Delgado 733076
        DIRECTORY=$(tcar_checkRepoDirSource ${DIRECTORY})
Alain Reguera Delgado 733076
Alain Reguera Delgado 733076
        # Verify the search path. It must exist and being a directory.
Alain Reguera Delgado 733076
        tcar_checkFiles -ed ${DIRECTORY}
Alain Reguera Delgado 733076
Alain Reguera Delgado 733076
        # Define the list of configuration files the render module
Alain Reguera Delgado 733076
        # will use as reference to produce documentation. At this
Alain Reguera Delgado 733076
        # point it is very difficult that DIRECTORY doesn't exist or
Alain Reguera Delgado 733076
        # be outside the repository directory structure.
Alain Reguera Delgado 733076
        CONFIGURATION_FILES[++${#CONFIGURATION_FILES[*]}]=$(tcar_getFilesList \
Alain Reguera Delgado 733076
            ${DIRECTORY} --pattern='.+\.conf$' --type='f' \
Alain Reguera Delgado 733076
            | xargs egrep ${CONFIGURATION_PATTERN} | cut -d: -f1 | sort | uniq)
Alain Reguera Delgado 733076
Alain Reguera Delgado 733076
    done
Alain Reguera Delgado 733076
Alain Reguera Delgado 733076
    # Process the list of configuration files using the render module.
Alain Reguera Delgado 733076
    tcar_setModuleEnvironment -m "render" -t "parent" ${CONFIGURATION_FILES[*]}
Alain Reguera Delgado 733076
}