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