Blame Automation/Scripts/tcar_setModuleEnvironment.sh

Alain Reguera Delgado 69f807
#!/bin/bash
Alain Reguera Delgado 69f807
######################################################################
Alain Reguera Delgado 69f807
#
Alain Reguera Delgado 788260
#   tcar_setModuleEnvironment.sh -- This function initiates
Alain Reguera Delgado 788260
#   first-level module (or simply, module) environments inside the
Alain Reguera Delgado 788260
#   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 69f807
    # Define module's name (MODULE_NAME) using the first argument
Alain Reguera Delgado 69f807
    # in the command-line.
Alain Reguera Delgado eb3010
    local MODULE_NAME=$(tcar_getRepoName "${1}" "-f" | cut -d '-' -f1)
Alain Reguera Delgado 69f807
Alain Reguera Delgado 69f807
    # Define regular expression to match available modules.
Alain Reguera Delgado 5824c8
    local MODULE_NAME_LIST=$(ls ${TCAR_SCRIPT_MODULES_BASEDIR} \
Alain Reguera Delgado 69f807
        | tr '\n' '|' | sed -r 's/\|$//' | tr '[[:upper:]]' '[[:lower:]]')
Alain Reguera Delgado 69f807
Alain Reguera Delgado 69f807
    # Check module's name possible values.
Alain Reguera Delgado 69f807
    if [[ ! ${MODULE_NAME} =~ "^(${MODULE_NAME_LIST})$" ]];then
Alain Reguera Delgado 788260
        tcar_printMessage "`eval_gettext "The module (\\\$MODULE_NAME) isn't supported yet."`" --as-error-line
Alain Reguera Delgado 69f807
    fi
Alain Reguera Delgado 69f807
Alain Reguera Delgado 2ae54a
    # Define module's directory.
Alain Reguera Delgado eb3010
    local MODULE_DIR=${TCAR_SCRIPT_MODULES_BASEDIR}/$(tcar_getRepoName "${MODULE_NAME}" "-d")
Alain Reguera Delgado 69f807
Alain Reguera Delgado 2ae54a
    # Define module's related directories.
Alain Reguera Delgado 2ae54a
    local MODULE_DIR_MODULES=${MODULE_DIR}/Modules
Alain Reguera Delgado 65f472
    local MODULE_DIR_MANUALS=${MODULE_DIR}/Manuals
Alain Reguera Delgado 14b1ad
    local MODULE_DIR_CONFIGS=${MODULE_DIR}/Configs
Alain Reguera Delgado 2ae54a
Alain Reguera Delgado 788260
    # Define the sub-module's base directory where sub-module
Alain Reguera Delgado 788260
    # processing will start from.
Alain Reguera Delgado 788260
    local SUBMODULE_BASEDIR=${MODULE_DIR_MODULES}
Alain Reguera Delgado 788260
Alain Reguera Delgado 2ae54a
    # Define module's initialization file.
Alain Reguera Delgado 69f807
    local MODULE_INIT_FILE=${MODULE_DIR}/${MODULE_NAME}.sh
Alain Reguera Delgado 69f807
Alain Reguera Delgado 69f807
    # Check function script execution rights.
Alain Reguera Delgado 786ac0
    tcar_checkFiles -ex ${MODULE_INIT_FILE}
Alain Reguera Delgado 69f807
Alain Reguera Delgado 69f807
    # Remove the first argument passed to centos-art.sh command-line
Alain Reguera Delgado 69f807
    # in order to build optional arguments inside functionalities. We
Alain Reguera Delgado 2ae54a
    # start counting from second argument on, inclusively.
Alain Reguera Delgado 69f807
    shift 1
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 788260
    tcar_setModuleEnvironmentScripts "${MODULE_DIR}" "${MODULE_NAME}" "${MODULE_INIT_FILE}"
Alain Reguera Delgado 69f807
Alain Reguera Delgado 2ae54a
    # Execute module-specific initialization script.
Alain Reguera Delgado 69f807
    ${MODULE_NAME} "${@}"
Alain Reguera Delgado 69f807
Alain Reguera Delgado 2e37b0
    # Unset the module environment.
Alain Reguera Delgado 2e37b0
    tcar_unsetModuleEnvironment "${MODULE_NAME}"
Alain Reguera Delgado 2e37b0
Alain Reguera Delgado 69f807
}