|
Alain Reguera Delgado |
69f807 |
#!/bin/bash
|
|
Alain Reguera Delgado |
69f807 |
######################################################################
|
|
Alain Reguera Delgado |
69f807 |
#
|
|
Alain Reguera Delgado |
06ab0f |
# tcar_setModuleEnvironment.sh -- This function initiates module
|
|
Alain Reguera Delgado |
06ab0f |
# environments inside the centos-art.sh script.
|
|
Alain Reguera Delgado |
69f807 |
#
|
|
Alain Reguera Delgado |
0e5ba0 |
# Written by:
|
|
Alain Reguera Delgado |
69f807 |
# * Alain Reguera Delgado <al@centos.org.cu>, 2009-2013
|
|
Alain Reguera Delgado |
69f807 |
#
|
|
Alain Reguera Delgado |
0e5ba0 |
# Copyright (C) 2009-2013 The CentOS Artwork SIG
|
|
Alain Reguera Delgado |
69f807 |
#
|
|
Alain Reguera Delgado |
69f807 |
# This program is free software; you can redistribute it and/or modify
|
|
Alain Reguera Delgado |
69f807 |
# it under the terms of the GNU General Public License as published by
|
|
Alain Reguera Delgado |
69f807 |
# the Free Software Foundation; either version 2 of the License, or (at
|
|
Alain Reguera Delgado |
69f807 |
# your option) any later version.
|
|
Alain Reguera Delgado |
69f807 |
#
|
|
Alain Reguera Delgado |
69f807 |
# This program is distributed in the hope that it will be useful, but
|
|
Alain Reguera Delgado |
69f807 |
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Alain Reguera Delgado |
69f807 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Alain Reguera Delgado |
69f807 |
# General Public License for more details.
|
|
Alain Reguera Delgado |
69f807 |
#
|
|
Alain Reguera Delgado |
69f807 |
# You should have received a copy of the GNU General Public License
|
|
Alain Reguera Delgado |
69f807 |
# along with this program; if not, write to the Free Software
|
|
Alain Reguera Delgado |
69f807 |
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
Alain Reguera Delgado |
69f807 |
#
|
|
Alain Reguera Delgado |
69f807 |
######################################################################
|
|
Alain Reguera Delgado |
69f807 |
|
|
Alain Reguera Delgado |
9c1e5e |
function tcar_setModuleEnvironment {
|
|
Alain Reguera Delgado |
69f807 |
|
|
Alain Reguera Delgado |
06ab0f |
local ARG_MODULE_NAME=''
|
|
Alain Reguera Delgado |
06ab0f |
local ARG_MODULE_TYPE=''
|
|
Alain Reguera Delgado |
06ab0f |
local ARG_MODULE_ARGS=''
|
|
Alain Reguera Delgado |
69f807 |
|
|
Alain Reguera Delgado |
06ab0f |
# Retrieve module's name and module's type from arguments passed
|
|
Alain Reguera Delgado |
06ab0f |
# through this function positional parameters.
|
|
Alain Reguera Delgado |
06ab0f |
OPTIND=1
|
|
Alain Reguera Delgado |
06ab0f |
while getopts "m:,t:,g:" OPTION "${@}"; do
|
|
Alain Reguera Delgado |
06ab0f |
case "${OPTION}" in
|
|
Alain Reguera Delgado |
06ab0f |
m ) ARG_MODULE_NAME="${OPTARG}" ;;
|
|
Alain Reguera Delgado |
06ab0f |
t ) ARG_MODULE_TYPE="${OPTARG}" ;;
|
|
Alain Reguera Delgado |
06ab0f |
g ) ARG_MODULE_ARGS="${OPTARG} ${ARG_MODULE_ARGS}" ;;
|
|
Alain Reguera Delgado |
06ab0f |
esac
|
|
Alain Reguera Delgado |
06ab0f |
done
|
|
Alain Reguera Delgado |
69f807 |
|
|
Alain Reguera Delgado |
06ab0f |
# Clean up positional parameters to reflect the fact that options
|
|
Alain Reguera Delgado |
06ab0f |
# have been processed already.
|
|
Alain Reguera Delgado |
06ab0f |
shift $(( ${OPTIND} - 1 ))
|
|
Alain Reguera Delgado |
06ab0f |
|
|
Alain Reguera Delgado |
06ab0f |
# Define default values for module name and type passed from
|
|
Alain Reguera Delgado |
06ab0f |
# arguments.
|
|
Alain Reguera Delgado |
06ab0f |
ARG_MODULE_NAME=${ARG_MODULE_NAME:-`gettext "Unknown"`}
|
|
Alain Reguera Delgado |
06ab0f |
ARG_MODULE_TYPE=${ARG_MODULE_TYPE:-'top-module'}
|
|
Alain Reguera Delgado |
06ab0f |
ARG_MODULE_ARGS=${ARG_MODULE_ARGS:-''}
|
|
Alain Reguera Delgado |
06ab0f |
|
|
Alain Reguera Delgado |
06ab0f |
# Initialize module's global counter.
|
|
Alain Reguera Delgado |
06ab0f |
TCAR_MODULE_COUNT=${TCAR_MODULE_COUNT:-0}
|
|
Alain Reguera Delgado |
06ab0f |
|
|
Alain Reguera Delgado |
06ab0f |
tcar_printMessage "FUNCNAME : ${FUNCNAME[1]} ( ${ARG_MODULE_NAME}, ${ARG_MODULE_TYPE} )" --as-debugger-line
|
|
Alain Reguera Delgado |
06ab0f |
|
|
Alain Reguera Delgado |
06ab0f |
# Define module's base directory. This is the directory where the
|
|
Alain Reguera Delgado |
06ab0f |
# initialization script is stored in.
|
|
Alain Reguera Delgado |
06ab0f |
local TCAR_MODULE_BASEDIR=${TCAR_SCRIPT_MODULES_BASEDIR}
|
|
Alain Reguera Delgado |
06ab0f |
if [[ ${#TCAR_MODULE_BASEDIRS[*]} -gt 0 ]];then
|
|
Alain Reguera Delgado |
06ab0f |
if [[ ${ARG_MODULE_TYPE} == "top-module" ]];then
|
|
Alain Reguera Delgado |
06ab0f |
TCAR_MODULE_BASEDIR=${TCAR_SCRIPT_MODULES_BASEDIR}
|
|
Alain Reguera Delgado |
06ab0f |
elif [[ ${ARG_MODULE_TYPE} == "sib-module" ]];then
|
|
Alain Reguera Delgado |
06ab0f |
TCAR_MODULE_BASEDIR=${TCAR_MODULE_BASEDIRS[((${TCAR_MODULE_COUNT}-1))]}
|
|
Alain Reguera Delgado |
06ab0f |
else
|
|
Alain Reguera Delgado |
06ab0f |
TCAR_MODULE_BASEDIR=${TCAR_MODULE_BASEDIRS[${TCAR_MODULE_COUNT}]}
|
|
Alain Reguera Delgado |
06ab0f |
fi
|
|
Alain Reguera Delgado |
69f807 |
fi
|
|
Alain Reguera Delgado |
06ab0f |
tcar_printMessage "TCAR_MODULE_BASEDIR : ${TCAR_MODULE_BASEDIR}" --as-debugger-line
|
|
Alain Reguera Delgado |
06ab0f |
|
|
Alain Reguera Delgado |
06ab0f |
# Define module's name.
|
|
Alain Reguera Delgado |
06ab0f |
TCAR_MODULE_NAMES[${TCAR_MODULE_COUNT}]=$(tcar_getRepoName "${ARG_MODULE_NAME}" "-f" | cut -d '-' -f1)
|
|
Alain Reguera Delgado |
06ab0f |
local TCAR_MODULE_NAME=${TCAR_MODULE_NAMES[${TCAR_MODULE_COUNT}]}
|
|
Alain Reguera Delgado |
06ab0f |
tcar_printMessage "TCAR_MODULE_NAME : [${TCAR_MODULE_COUNT}]=${TCAR_MODULE_NAME} | ${#TCAR_MODULE_NAMES[*]}" --as-debugger-line
|
|
Alain Reguera Delgado |
06ab0f |
|
|
Alain Reguera Delgado |
06ab0f |
# Define module's arguments. This variable is used in different
|
|
Alain Reguera Delgado |
06ab0f |
# module environments to pass positional parameters from one
|
|
Alain Reguera Delgado |
06ab0f |
# environment to another using local definitions.
|
|
Alain Reguera Delgado |
06ab0f |
TCAR_MODULE_ARGUMENTS[${TCAR_MODULE_COUNT}]="${ARG_MODULE_ARGS} ${@}"
|
|
Alain Reguera Delgado |
06ab0f |
local TCAR_MODULE_ARGUMENT=${TCAR_MODULE_ARGUMENTS[${TCAR_MODULE_COUNT}]}
|
|
Alain Reguera Delgado |
06ab0f |
tcar_printMessage "TCAR_MODULE_ARGUMENT : ${TCAR_MODULE_ARGUMENT}" --as-debugger-line
|
|
Alain Reguera Delgado |
06ab0f |
|
|
Alain Reguera Delgado |
06ab0f |
# Check module's name possible values.
|
|
Alain Reguera Delgado |
06ab0f |
tcar_checkModuleName
|
|
Alain Reguera Delgado |
69f807 |
|
|
Alain Reguera Delgado |
2ae54a |
# Define module's directory.
|
|
Alain Reguera Delgado |
06ab0f |
TCAR_MODULE_DIRS[${TCAR_MODULE_COUNT}]=${TCAR_MODULE_BASEDIR}/$(tcar_getRepoName "${TCAR_MODULE_NAME}" "-d")
|
|
Alain Reguera Delgado |
06ab0f |
local TCAR_MODULE_DIR=${TCAR_MODULE_DIRS[${TCAR_MODULE_COUNT}]}
|
|
Alain Reguera Delgado |
06ab0f |
tcar_printMessage "TCAR_MODULE_DIR : ${TCAR_MODULE_DIR}" --as-debugger-line
|
|
Alain Reguera Delgado |
69f807 |
|
|
Alain Reguera Delgado |
2ae54a |
# Define module's related directories.
|
|
Alain Reguera Delgado |
06ab0f |
TCAR_MODULE_DIRS_MODULES[${TCAR_MODULE_COUNT}]=${TCAR_MODULE_DIR}/Modules
|
|
Alain Reguera Delgado |
06ab0f |
local TCAR_MODULE_DIR_MODULES=${TCAR_MODULE_DIRS_MODULES[${TCAR_MODULE_COUNT}]}
|
|
Alain Reguera Delgado |
06ab0f |
tcar_printMessage "TCAR_MODULE_DIR_MODULES : ${TCAR_MODULE_DIR_MODULES}" --as-debugger-line
|
|
Alain Reguera Delgado |
06ab0f |
|
|
Alain Reguera Delgado |
06ab0f |
TCAR_MODULE_DIRS_MANUALS[${TCAR_MODULE_COUNT}]=${TCAR_MODULE_DIR}/Manuals
|
|
Alain Reguera Delgado |
06ab0f |
local TCAR_MODULE_DIR_MANUALS=${TCAR_MODULE_DIRS_MANUALS[${TCAR_MODULE_COUNT}]}
|
|
Alain Reguera Delgado |
06ab0f |
tcar_printMessage "TCAR_MODULE_DIR_MANUALS : ${TCAR_MODULE_DIR_MANUALS}" --as-debugger-line
|
|
Alain Reguera Delgado |
2ae54a |
|
|
Alain Reguera Delgado |
06ab0f |
TCAR_MODULE_DIRS_LOCALES[${TCAR_MODULE_COUNT}]=${TCAR_MODULE_DIR}/Locales
|
|
Alain Reguera Delgado |
06ab0f |
local TCAR_MODULE_DIR_LOCALES=${TCAR_MODULE_DIRS_LOCALES[${TCAR_MODULE_COUNT}]}
|
|
Alain Reguera Delgado |
06ab0f |
tcar_printMessage "TCAR_MODULE_DIR_LOCALES : ${TCAR_MODULE_DIR_LOCALES}" --as-debugger-line
|
|
Alain Reguera Delgado |
06ab0f |
|
|
Alain Reguera Delgado |
06ab0f |
TCAR_MODULE_DIRS_CONFIGS[${TCAR_MODULE_COUNT}]=${TCAR_MODULE_DIR}/Configs
|
|
Alain Reguera Delgado |
06ab0f |
local TCAR_MODULE_DIR_CONFIGS=${TCAR_MODULE_DIRS_CONFIGS[${TCAR_MODULE_COUNT}]}
|
|
Alain Reguera Delgado |
06ab0f |
tcar_printMessage "TCAR_MODULE_DIR_CONFIGS : ${TCAR_MODULE_DIR_CONFIGS}" --as-debugger-line
|
|
Alain Reguera Delgado |
788260 |
|
|
Alain Reguera Delgado |
2ae54a |
# Define module's initialization file.
|
|
Alain Reguera Delgado |
06ab0f |
TCAR_MODULE_INIT_FILES[${TCAR_MODULE_COUNT}]=${TCAR_MODULE_DIR}/${TCAR_MODULE_NAME}.sh
|
|
Alain Reguera Delgado |
06ab0f |
local TCAR_MODULE_INIT_FILE=${TCAR_MODULE_INIT_FILES[${TCAR_MODULE_COUNT}]}
|
|
Alain Reguera Delgado |
06ab0f |
tcar_printMessage "TCAR_MODULE_INIT_FILE : ${TCAR_MODULE_INIT_FILE}" --as-debugger-line
|
|
Alain Reguera Delgado |
69f807 |
|
|
Alain Reguera Delgado |
06ab0f |
# Increment module's counter just before creating next module's
|
|
Alain Reguera Delgado |
06ab0f |
# base directory.
|
|
Alain Reguera Delgado |
06ab0f |
TCAR_MODULE_COUNT=$(( ${TCAR_MODULE_COUNT} + 1 ))
|
|
Alain Reguera Delgado |
06ab0f |
tcar_printMessage "TCAR_MODULE_COUNT: ${TCAR_MODULE_COUNT}" --as-debugger-line
|
|
Alain Reguera Delgado |
69f807 |
|
|
Alain Reguera Delgado |
06ab0f |
# Define next module's base directory.
|
|
Alain Reguera Delgado |
06ab0f |
TCAR_MODULE_BASEDIRS[${TCAR_MODULE_COUNT}]=${TCAR_MODULE_DIR_MODULES}
|
|
Alain Reguera Delgado |
06ab0f |
|
|
Alain Reguera Delgado |
06ab0f |
# Check function script execution rights.
|
|
Alain Reguera Delgado |
06ab0f |
tcar_checkFiles -ex ${TCAR_MODULE_INIT_FILE}
|
|
Alain Reguera Delgado |
69f807 |
|
|
Alain Reguera Delgado |
2ae54a |
# Load module-specific (function) scripts into current execution
|
|
Alain Reguera Delgado |
2ae54a |
# environment. Keep the tcar_setModuleEnvironmentScripts function
|
|
Alain Reguera Delgado |
2ae54a |
# call after all variables and arguments definitions.
|
|
Alain Reguera Delgado |
06ab0f |
tcar_setModuleEnvironmentScripts
|
|
Alain Reguera Delgado |
69f807 |
|
|
Alain Reguera Delgado |
06ab0f |
# Execute module's initialization script.
|
|
Alain Reguera Delgado |
06ab0f |
tcar_printMessage "`gettext "Opening module"`: ${TCAR_MODULE_NAME} ${TCAR_MODULE_ARGUMENT}" --as-debugger-line
|
|
Alain Reguera Delgado |
06ab0f |
${TCAR_MODULE_NAME} ${TCAR_MODULE_ARGUMENT}
|
|
Alain Reguera Delgado |
69f807 |
|
|
Alain Reguera Delgado |
06ab0f |
# Unset module-specific environment.
|
|
Alain Reguera Delgado |
06ab0f |
tcar_printMessage "`gettext "Closing module"`: ${TCAR_MODULE_NAME}" --as-debugger-line
|
|
Alain Reguera Delgado |
06ab0f |
tcar_unsetModuleEnvironment
|
|
Alain Reguera Delgado |
2e37b0 |
|
|
Alain Reguera Delgado |
06ab0f |
# Decrement module counter just after unset unused module
|
|
Alain Reguera Delgado |
06ab0f |
# environments.
|
|
Alain Reguera Delgado |
06ab0f |
TCAR_MODULE_COUNT=$(( ${TCAR_MODULE_COUNT} - 1 ))
|
|
Alain Reguera Delgado |
06ab0f |
tcar_printMessage "TCAR_MODULE_COUNT: ${TCAR_MODULE_COUNT}" --as-debugger-line
|
|
Alain Reguera Delgado |
06ab0f |
|
|
Alain Reguera Delgado |
06ab0f |
# Unset array and non-array variables used in this function.
|
|
Alain Reguera Delgado |
06ab0f |
if [[ ${TCAR_MODULE_COUNT} -eq 0 ]];then
|
|
Alain Reguera Delgado |
06ab0f |
tcar_printMessage "`gettext "Closing variables"`: " --as-debugger-line
|
|
Alain Reguera Delgado |
06ab0f |
unset TCAR_MODULE_NAMES
|
|
Alain Reguera Delgado |
06ab0f |
unset TCAR_MODULE_BASEDIRS
|
|
Alain Reguera Delgado |
06ab0f |
unset TCAR_MODULE_DIRS
|
|
Alain Reguera Delgado |
06ab0f |
unset TCAR_MODULE_DIRS_MODULES
|
|
Alain Reguera Delgado |
06ab0f |
unset TCAR_MODULE_DIRS_MANUALS
|
|
Alain Reguera Delgado |
06ab0f |
unset TCAR_MODULE_DIRS_LOCALES
|
|
Alain Reguera Delgado |
06ab0f |
unset TCAR_MODULE_DIRS_CONFIGS
|
|
Alain Reguera Delgado |
06ab0f |
unset TCAR_MODULE_NAME
|
|
Alain Reguera Delgado |
06ab0f |
unset TCAR_MODULE_DIR
|
|
Alain Reguera Delgado |
06ab0f |
unset TCAR_MODULE_DIR_MODULES
|
|
Alain Reguera Delgado |
06ab0f |
unset TCAR_MODULE_DIR_MANUALS
|
|
Alain Reguera Delgado |
06ab0f |
unset TCAR_MODULE_DIR_LOCALES
|
|
Alain Reguera Delgado |
06ab0f |
unset TCAR_MODULE_DIR_CONFIGS
|
|
Alain Reguera Delgado |
06ab0f |
fi
|
|
Alain Reguera Delgado |
69f807 |
}
|