|
Alain Reguera Delgado |
c554f1 |
#!/bin/bash
|
|
Alain Reguera Delgado |
c554f1 |
######################################################################
|
|
Alain Reguera Delgado |
c554f1 |
#
|
|
Alain Reguera Delgado |
77084b |
# tcar - The CentOS Artwork Repository automation tool.
|
|
Alain Reguera Delgado |
77084b |
# Copyright © 2014 The CentOS Artwork SIG
|
|
Alain Reguera Delgado |
77084b |
#
|
|
Alain Reguera Delgado |
77084b |
# This program is free software; you can redistribute it and/or
|
|
Alain Reguera Delgado |
77084b |
# modify it under the terms of the GNU General Public License as
|
|
Alain Reguera Delgado |
77084b |
# published by the Free Software Foundation; either version 2 of the
|
|
Alain Reguera Delgado |
77084b |
# License, or (at your option) any later version.
|
|
Alain Reguera Delgado |
77084b |
#
|
|
Alain Reguera Delgado |
77084b |
# This program is distributed in the hope that it will be useful,
|
|
Alain Reguera Delgado |
77084b |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Alain Reguera Delgado |
77084b |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Alain Reguera Delgado |
77084b |
# General Public License for more details.
|
|
Alain Reguera Delgado |
77084b |
#
|
|
Alain Reguera Delgado |
77084b |
# You should have received a copy of the GNU General Public License
|
|
Alain Reguera Delgado |
77084b |
# along with this program; if not, write to the Free Software
|
|
Alain Reguera Delgado |
77084b |
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
Alain Reguera Delgado |
77084b |
#
|
|
Alain Reguera Delgado |
77084b |
# Alain Reguera Delgado <al@centos.org.cu>
|
|
Alain Reguera Delgado |
77084b |
# 39 Street No. 4426 Cienfuegos, Cuba.
|
|
Alain Reguera Delgado |
c554f1 |
#
|
|
Alain Reguera Delgado |
c554f1 |
######################################################################
|
|
Alain Reguera Delgado |
c554f1 |
|
|
Alain Reguera Delgado |
77084b |
# Provide a secure interface to render content outside the render
|
|
Alain Reguera Delgado |
77084b |
# module. You can use this function to call the render module from
|
|
Alain Reguera Delgado |
77084b |
# other modules, safely.
|
|
Alain Reguera Delgado |
77084b |
#
|
|
Alain Reguera Delgado |
77084b |
# This function builds a list of all available configuration files in
|
|
Alain Reguera Delgado |
77084b |
# locations passed as argument and reduces the list by applying
|
|
Alain Reguera Delgado |
77084b |
# regular expression patterns to each file in the list. Only files
|
|
Alain Reguera Delgado |
77084b |
# that match the regular expression pattern will remain in the final
|
|
Alain Reguera Delgado |
77084b |
# list. The regular expression patterns are applied to file's content,
|
|
Alain Reguera Delgado |
77084b |
# generally to find out if it has an specific option, value or
|
|
Alain Reguera Delgado |
77084b |
# combination of both inside. Later, the resultant list of
|
|
Alain Reguera Delgado |
77084b |
# configuration files is passed to render module for processing.
|
|
Alain Reguera Delgado |
77084b |
#
|
|
Alain Reguera Delgado |
77084b |
# This function verifies the search path provided to render module to
|
|
Alain Reguera Delgado |
77084b |
# grant it is inside the repository before passing it to render module
|
|
Alain Reguera Delgado |
77084b |
# for processing.
|
|
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 |
02dad8 |
# Clean-up the search path. This location must point to a
|
|
Alain Reguera Delgado |
02dad8 |
# directory inside the workplace.
|
|
Alain Reguera Delgado |
02dad8 |
DIRECTORY=$(tcar_checkWorkDirSource ${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 |
ca84d5 |
# be outside the workplace directory structure.
|
|
Alain Reguera Delgado |
c554f1 |
CONFIGURATION_FILES[++${#CONFIGURATION_FILES[*]}]=$(tcar_getFilesList \
|
|
Alain Reguera Delgado |
ca84d5 |
-p '.+\.conf$' -t 'l' ${DIRECTORY} \
|
|
Alain Reguera Delgado |
74bc19 |
| 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 |
}
|