Blame Automation/Modules/Prepare/prepare_setRenderEnvironment.sh

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