Blame Scripts/Functions/cli_exportFunctions.sh

4c79b5
#!/bin/bash
4c79b5
#
2bbbd5
# cli_exportFunctions.sh -- This function exports funtionalities to
2bbbd5
# `centos-art.sh' script execution evironment.
4c79b5
#
3b0984
# Copyright (C) 2009, 2010, 2011 The CentOS Artwork SIG
fa95b1
#
fa95b1
# This program is free software; you can redistribute it and/or modify
fa95b1
# it under the terms of the GNU General Public License as published by
dcd347
# the Free Software Foundation; either version 2 of the License, or (at
dcd347
# your option) any later version.
fa95b1
#
74a058
# This program is distributed in the hope that it will be useful, but
74a058
# WITHOUT ANY WARRANTY; without even the implied warranty of
4c79b5
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
4c79b5
# General Public License for more details.
4c79b5
#
4c79b5
# You should have received a copy of the GNU General Public License
4c79b5
# along with this program; if not, write to the Free Software
dcd347
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
7ac5a5
#
4c79b5
# ----------------------------------------------------------------------
418249
# $Id$
4c79b5
# ----------------------------------------------------------------------
4c79b5
d117ae
function cli_exportFunctions {
4c79b5
4ef408
    # Define source location where function files are placed in.
4ef408
    local LOCATION=$1
4c79b5
d64001
    # Define suffix used to retrive function files.
d64001
    local SUFFIX=$2
d64001
d64001
    # Verify suffix value used to retrive function files. Assuming no
d64001
    # suffix value is passed as second argument to this function, use
d64001
    # the function name value (FUNCNAM) as default value.
d64001
    if [[ $SUFFIX == '' ]];then
d64001
        SUFFIX=$FUNCNAM
d64001
    fi
d64001
4ef408
    # Define pattern used to retrive function names from function
4ef408
    # files.
d64001
    local PATTERN="^function[[:space:]]+${SUFFIX}[[:alnum:]_]*[[:space:]]+{$"
4c79b5
4ef408
    # Define list of files.
2bbbd5
    local FUNCFILE=''
d64001
    local FUNCFILES=$(cli_getFilesList ${LOCATION} --pattern="${SUFFIX}.*\.sh" --maxdepth="1")
4c79b5
a6c236
    # Verify list of files. If no function file exists for the
a6c236
    # location specified stop the script execution. Otherwise the
a6c236
    # script will surely try to execute a function that haven't been
a6c236
    # exported yet and report an error about it.
a6c236
    if [[ $FUNCFILES == '' ]];then
a6c236
        cli_printMessage "`gettext "No function file was found for this action."`" --as-error-line
a6c236
    fi
a6c236
4ef408
    # Process list of files.
2bbbd5
    for FUNCFILE in $FUNCFILES;do
4c79b5
4ef408
        # Verify file execution rights.
2bbbd5
        cli_checkFiles $FUNCFILE --execution
4c79b5
4ef408
        # Initialize file.
2bbbd5
        . $FUNCFILE
4c79b5
4ef408
        # Export function names inside the file to current shell
4ef408
        # script environment.
007550
        export -f $(egrep "${PATTERN}" ${FUNCFILE} | gawk '{ print $2 }')
4c79b5
4c79b5
    done
4c79b5
4c79b5
}