Blame Automation/Scripts/tcar_setSubModuleEnvironment.sh

Alain Reguera Delgado 788260
#!/bin/bash
Alain Reguera Delgado 788260
######################################################################
Alain Reguera Delgado 788260
#
Alain Reguera Delgado 788260
#   tcar_setSubModuleEnvironment.sh -- This function initiates
Alain Reguera Delgado 788260
#   modules' sub-module environments inside the centos-art.sh script.
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 788260
# Copyright (C) 2013 The CentOS Project
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 tcar_setSubModuleEnvironment {
Alain Reguera Delgado 788260
Alain Reguera Delgado 788260
    # Define sub-module's name (SUBMODULE_NAME) using the first
Alain Reguera Delgado 788260
    # argument in the command-line.
Alain Reguera Delgado 788260
    local SUBMODULE_NAME=$(tcar_getRepoName "${1}" "-f" | cut -d '-' -f1)
Alain Reguera Delgado 788260
Alain Reguera Delgado 788260
    # Define regular expression to match available sub-modules.
Alain Reguera Delgado 788260
    local SUBMODULE_NAME_LIST=$(ls ${SUBMODULE_BASEDIR} \
Alain Reguera Delgado 788260
        | tr '\n' '|' | sed -r 's/\|$//' | tr '[[:upper:]]' '[[:lower:]]')
Alain Reguera Delgado 788260
Alain Reguera Delgado 788260
    # Check sub-module's name possible values.
Alain Reguera Delgado 788260
    if [[ ! ${SUBMODULE_NAME} =~ "^(${SUBMODULE_NAME_LIST})$" ]];then
Alain Reguera Delgado 788260
        tcar_printMessage "`eval_gettext "The sub-module (\\\$SUBMODULE_NAME) isn't supported yet."`" --as-error-line
Alain Reguera Delgado 788260
    fi
Alain Reguera Delgado 788260
Alain Reguera Delgado 788260
    # Define sub-module's directory.
Alain Reguera Delgado 788260
    local SUBMODULE_DIR=${SUBMODULE_BASEDIR}/$(tcar_getRepoName "${SUBMODULE_NAME}" "-d")
Alain Reguera Delgado 788260
Alain Reguera Delgado 788260
    # Define sub-module's related directories.
Alain Reguera Delgado 788260
    local SUBMODULE_DIR_MODULES=${SUBMODULE_DIR}/Modules
Alain Reguera Delgado 788260
    local SUBMODULE_DIR_MANUALS=${SUBMODULE_DIR}/Manuals
Alain Reguera Delgado 788260
    local SUBMODULE_DIR_CONFIGS=${SUBMODULE_DIR}/Configs
Alain Reguera Delgado 788260
Alain Reguera Delgado 788260
    # Reset sub-module's current directory.
Alain Reguera Delgado 788260
    local SUBMODULE_BASEDIR=${SUBMODULE_DIR_MODULES}
Alain Reguera Delgado 788260
Alain Reguera Delgado 788260
    # Define sub-module's initialization file.
Alain Reguera Delgado 788260
    local SUBMODULE_INIT_FILE=${SUBMODULE_DIR}/${SUBMODULE_NAME}.sh
Alain Reguera Delgado 788260
Alain Reguera Delgado 788260
    # Check function script execution rights.
Alain Reguera Delgado 788260
    tcar_checkFiles -ex ${SUBMODULE_INIT_FILE}
Alain Reguera Delgado 788260
Alain Reguera Delgado 788260
    # Remove the first argument passed to centos-art.sh command-line
Alain Reguera Delgado 788260
    # in order to build optional arguments inside functionalities. We
Alain Reguera Delgado 788260
    # start counting from second argument on, inclusively.
Alain Reguera Delgado 788260
    shift 1
Alain Reguera Delgado 788260
Alain Reguera Delgado 788260
    # Verify the number of arguments passed to centos-art.sh script.
Alain Reguera Delgado 788260
    # By default, to all sub-modules, when no argument is provided
Alain Reguera Delgado 788260
    # after the sub-module name, use the current directory as default
Alain Reguera Delgado 788260
    # directory to look for configuration files.
Alain Reguera Delgado 788260
    if [[ $# -eq 0 ]];then
Alain Reguera Delgado 788260
        set -- ${PWD}
Alain Reguera Delgado 788260
    fi
Alain Reguera Delgado 788260
Alain Reguera Delgado 788260
    # Load sub-module-specific (function) scripts into current
Alain Reguera Delgado 788260
    # execution environment.
Alain Reguera Delgado 788260
    tcar_setModuleEnvironmentScripts "${SUBMODULE_DIR}" "${SUBMODULE_NAME}" "${SUBMODULE_INIT_FILE}"
Alain Reguera Delgado 788260
Alain Reguera Delgado 788260
    # Execute sub-module-specific initialization script.
Alain Reguera Delgado 788260
    ${SUBMODULE_NAME} "${@}"
Alain Reguera Delgado 788260
Alain Reguera Delgado 788260
    # Unset the sub-module environment.
Alain Reguera Delgado 788260
    tcar_unsetModuleEnvironment "${SUBMODULE_NAME}"
Alain Reguera Delgado 788260
Alain Reguera Delgado 788260
}