Blame Scripts/Bash/Functions/cli_getFunctions.sh

4c79b5
#!/bin/bash
4c79b5
#
79b380
# cli_getFunctions.sh -- This function loads funtionalities supported by
4c79b5
# centos-art.sh script.
4c79b5
#
7cd8e9
# Copyright (C) 2009, 2010 Alain Reguera Delgado
4c79b5
# 
7cd8e9
# This program is free software; you can redistribute it and/or
7cd8e9
# modify it under the terms of the GNU General Public License as
7cd8e9
# published by the Free Software Foundation; either version 2 of the
7cd8e9
# License, or (at your option) any later version.
4c79b5
# 
4c79b5
# This program is distributed in the hope that it will be useful, but
4c79b5
# 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
4c79b5
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
4c79b5
# USA.
4c79b5
# 
4c79b5
# ----------------------------------------------------------------------
418249
# $Id$
4c79b5
# ----------------------------------------------------------------------
4c79b5
79b380
function cli_getFunctions {
4c79b5
4c79b5
    # Define variables as local to avoid conflicts outside.
94d85d
    local FUNCNAMDIR=''
94d85d
    local FUNCNAMFILES=''
94d85d
    local FUNCNAMSCRIPT=''
94d85d
    local FUNCNAMCALL=''
a23bb7
    local REPOFUNDIR=''
a23bb7
a23bb7
    # Define path to directory where actions are stored inside the
a23bb7
    # repository.
a23bb7
    REPOFUNDIR=/home/centos/artwork/trunk/Scripts/Bash/Functions
4c79b5
4c79b5
    # Define action directory. 
94d85d
    FUNCNAMDIR=$(cli_getRepoName $FUNCNAM 'd')
4c79b5
4c79b5
    # Define action file name.
94d85d
    FUNCNAMSCRIPT=${REPOFUNDIR}/${FUNCNAMDIR}/${FUNCNAM}.sh
4c79b5
4c79b5
    # Check action existence.
94d85d
    if [[ ! -f $FUNCNAMSCRIPT ]];then
4c79b5
        cli_printMessage "`gettext "The action provided is not valid."`"
1f1b3c
        cli_printMessage "$(caller)" "AsToKnowMoreLine"
4c79b5
    fi
4c79b5
4c79b5
    # Build action-specifc script file list.
94d85d
    FUNCNAMFILES=$(ls ${REPOFUNDIR}/${FUNCNAMDIR}/${FUNCNAM}*.sh)
4c79b5
94d85d
    for FILE in $FUNCNAMFILES;do
4c79b5
4c79b5
        if [[ -x ${FILE} ]];then
4c79b5
4c79b5
            # Initialize action-specific functions.
4c79b5
            . $FILE
4c79b5
4c79b5
            # Export action-specific functions to current shell script
4c79b5
            # environment.
94d85d
            FUNCNAMCALL=$(grep '^function ' $FILE | cut -d' ' -f2)
94d85d
            export -f $FUNCNAMCALL
4c79b5
4c79b5
        else
4c79b5
4c79b5
            cli_printMessage "`eval_gettext "The \\\$FILE hasn't execution rights."`"
1f1b3c
            cli_printMessage "$(caller)" "AsToKnowMoreLine"
4c79b5
4c79b5
        fi
4c79b5
4c79b5
    done
4c79b5
4c79b5
    # Execute action passed to centos-art.sh script.
94d85d
    eval $FUNCNAM
4c79b5
4c79b5
}