Blame Automation/Scripts/tcar_setModuleEnvironment.sh

Alain Reguera Delgado 69f807
#!/bin/bash
Alain Reguera Delgado 69f807
######################################################################
Alain Reguera Delgado 69f807
#
Alain Reguera Delgado 9c1e5e
#   tcar_setModuleEnvironment.sh -- This function initiates module
Alain Reguera Delgado 9c1e5e
#   environments inside the centos-art.sh script.
Alain Reguera Delgado 69f807
#
Alain Reguera Delgado 69f807
#   Written by: 
Alain Reguera Delgado 69f807
#   * Alain Reguera Delgado <al@centos.org.cu>, 2009-2013
Alain Reguera Delgado 69f807
#     Key fingerprint = D67D 0F82 4CBD 90BC 6421  DF28 7CCE 757C 17CA 3951
Alain Reguera Delgado 69f807
#
Alain Reguera Delgado 69f807
# Copyright (C) 2013 The CentOS Project
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 eb3010
        tcar_printMessage "`gettext "The module provided isn't valid."`" --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 2ae54a
    local MODULE_DIR_MANUALS=${MODULE_DIR}/Manuals
Alain Reguera Delgado 2ae54a
    local MODULE_DIR_SCRIPTS=${MODULE_DIR}/Scripts
Alain Reguera Delgado 2ae54a
    local MODULE_DIR_LOCALES=${MODULE_DIR}/Locales
Alain Reguera Delgado 2ae54a
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 eb3010
    tcar_checkFiles -x ${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 f446c2
    # Verify number of arguments passed to centos-art.sh script. By
Alain Reguera Delgado f446c2
    # default, to all modules, when no option is provided the version
Alain Reguera Delgado f446c2
    # information is printed.
Alain Reguera Delgado f446c2
    if [[ $# -lt 1 ]];then
Alain Reguera Delgado eb3010
        tcar_printVersion
Alain Reguera Delgado f446c2
    fi
Alain Reguera Delgado f446c2
Alain Reguera Delgado 9bd420
    # Redefine module-specific configuration values.
Alain Reguera Delgado 9bd420
    if [[ -f ${MODULE_DIR}/${MODULE_NAME}.conf.sh ]];then
Alain Reguera Delgado 9bd420
        . ${MODULE_DIR}/${MODULE_NAME}.conf.sh
Alain Reguera Delgado 9bd420
    fi
Alain Reguera Delgado 9bd420
Alain Reguera Delgado 9bd420
    # Redefine module-specific internationalization configuration variables.
Alain Reguera Delgado 5824c8
    declare -x TEXTDOMAIN=${MODULE_NAME}
Alain Reguera Delgado 5824c8
    declare -x TEXTDOMAINDIR=${MODULE_DIR}/Locales
Alain Reguera Delgado 5824c8
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 2ae54a
    tcar_setModuleEnvironmentScripts
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 69f807
}