Blame Automation/Scripts/tcar_setModuleEnvironmentScripts.sh

Alain Reguera Delgado 8f60cb
#!/bin/bash
Alain Reguera Delgado 615395
######################################################################
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 9c1e5e
#   tcar_setModuleEnvironmentScripts.sh -- This function standardizes
Alain Reguera Delgado 9c1e5e
#   the way specific functionalities are exported to centos-art.sh
Alain Reguera Delgado 9c1e5e
#   script environment.
Alain Reguera Delgado 615395
#
Alain Reguera Delgado 0e5ba0
#   Written by:
Alain Reguera Delgado 615395
#   * Alain Reguera Delgado <al@centos.org.cu>, 2009-2013
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 0e5ba0
# Copyright (C) 2009-2013 The CentOS Artwork SIG
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# This program is free software; you can redistribute it and/or modify
Alain Reguera Delgado 8f60cb
# it under the terms of the GNU General Public License as published by
Alain Reguera Delgado 8f60cb
# the Free Software Foundation; either version 2 of the License, or (at
Alain Reguera Delgado 8f60cb
# your option) any later version.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# This program is distributed in the hope that it will be useful, but
Alain Reguera Delgado 8f60cb
# WITHOUT ANY WARRANTY; without even the implied warranty of
Alain Reguera Delgado 8f60cb
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Alain Reguera Delgado 8f60cb
# General Public License for more details.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# You should have received a copy of the GNU General Public License
Alain Reguera Delgado 8f60cb
# along with this program; if not, write to the Free Software
Alain Reguera Delgado 8f60cb
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 615395
######################################################################
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 9c1e5e
function tcar_setModuleEnvironmentScripts {
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 0fdaad
    # Define gettext-specific variables locally, to provide
Alain Reguera Delgado 0fdaad
    # per-function localization.
Alain Reguera Delgado 0fdaad
    local TEXTDOMAIN="${FUNCNAME}.sh"
Alain Reguera Delgado 0fdaad
    local TEXTDOMAINDIR="${TCAR_SCRIPT_BASEDIR}/Scripts/Locales"
Alain Reguera Delgado 0fdaad
Alain Reguera Delgado 8f60cb
    # Define the pattern used to retrieve function names from function
Alain Reguera Delgado 8f60cb
    # files.
Alain Reguera Delgado 06ab0f
    local FUNCTION_PATTERN="^function[[:space:]]+${TCAR_MODULE_NAME}(_[[:alnum:]]+)?[[:space:]]+{[[:space:]]*$"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define the list of files.
Alain Reguera Delgado 06ab0f
    local MODULE_SCRIPTS="${TCAR_MODULE_INIT_FILE}"
Alain Reguera Delgado 06ab0f
    if [[ -d ${TCAR_MODULE_DIR} ]];then
Alain Reguera Delgado 2e37b0
        MODULE_SCRIPTS="${MODULE_SCRIPTS} 
Alain Reguera Delgado 06ab0f
            $(tcar_getFilesList ${TCAR_MODULE_DIR} \
Alain Reguera Delgado 06ab0f
            --pattern="${TCAR_MODULE_DIR}/${TCAR_MODULE_NAME}_[[:alnum:]]+\.sh$" --type='f')"
Alain Reguera Delgado 2e37b0
    fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Verify the list of files. If no function file exists for the
Alain Reguera Delgado 8f60cb
    # location specified stop the script execution. Otherwise the
Alain Reguera Delgado 8f60cb
    # script will surely try to execute a function that haven't been
Alain Reguera Delgado 8f60cb
    # exported yet and report an error about it.
Alain Reguera Delgado ddf7d2
    if [[ -z ${MODULE_SCRIPTS} ]];then
Alain Reguera Delgado eb3010
        tcar_printMessage "${FUNCNAME}: `gettext "No function file was found."`" --as-error-line
Alain Reguera Delgado 8f60cb
    fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Process the list of files.
Alain Reguera Delgado ddf7d2
    for MODULE_SCRIPT in ${MODULE_SCRIPTS};do
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Verify the execution rights for function file.
Alain Reguera Delgado 786ac0
        tcar_checkFiles -ex ${MODULE_SCRIPT}
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Verify that function files have not been already exported.
Alain Reguera Delgado 8f60cb
        # If they have been already exported don't export them again.
Alain Reguera Delgado 8f60cb
        # Instead, continue with the next function file in the list.
Alain Reguera Delgado ddf7d2
        declare -F | gawk '{ print $3 }' | egrep "^${MODULE_SCRIPT}$" > /dev/null
Alain Reguera Delgado 8f60cb
        if [[ $? -eq 0 ]];then
Alain Reguera Delgado 8f60cb
            continue
Alain Reguera Delgado 8f60cb
        fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Initialize the function file.
Alain Reguera Delgado ddf7d2
        . ${MODULE_SCRIPT}
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Export the function names inside the file to current shell
Alain Reguera Delgado 8f60cb
        # script environment.
Alain Reguera Delgado ddf7d2
        export -f $(egrep "${FUNCTION_PATTERN}" ${MODULE_SCRIPT} | gawk '{ print $2 }')
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    done
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
}