|
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 |
615395 |
# Written by:
|
|
Alain Reguera Delgado |
615395 |
# * Alain Reguera Delgado <al@centos.org.cu>, 2009-2013
|
|
Alain Reguera Delgado |
8f60cb |
#
|
|
Alain Reguera Delgado |
8f60cb |
# Copyright (C) 2009-2013 The CentOS Project
|
|
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 |
788260 |
local MODULE_DIR="${1}"
|
|
Alain Reguera Delgado |
788260 |
local MODULE_NAME="${2}"
|
|
Alain Reguera Delgado |
788260 |
local MODULE_INIT_FILE="${3}"
|
|
Alain Reguera Delgado |
788260 |
|
|
Alain Reguera Delgado |
8f60cb |
# Define the pattern used to retrieve function names from function
|
|
Alain Reguera Delgado |
8f60cb |
# files.
|
|
Alain Reguera Delgado |
2ae54a |
local FUNCTION_PATTERN="^function[[:space:]]+${MODULE_NAME}(_[[:alnum:]]+)?[[:space:]]+{[[:space:]]*$"
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
# Define the list of files.
|
|
Alain Reguera Delgado |
2e37b0 |
local MODULE_SCRIPTS="${MODULE_INIT_FILE}"
|
|
Alain Reguera Delgado |
2e37b0 |
if [[ -d ${MODULE_DIR} ]];then
|
|
Alain Reguera Delgado |
2e37b0 |
MODULE_SCRIPTS="${MODULE_SCRIPTS}
|
|
Alain Reguera Delgado |
2e37b0 |
$(tcar_getFilesList ${MODULE_DIR} \
|
|
Alain Reguera Delgado |
786ac0 |
--pattern="${MODULE_DIR}/${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 |
}
|