Blame Scripts/Bash/Functions/cli_getActions.sh

4c79b5
#!/bin/bash
4c79b5
#
4c79b5
# cli_getActions.sh -- This function loads funtionalities supported by
4c79b5
# centos-art.sh script.
4c79b5
#
4c79b5
# Copyright (C) 2009-2010 Alain Reguera Delgado
4c79b5
# 
4c79b5
# This program is free software; you can redistribute it and/or modify
4c79b5
# it under the terms of the GNU General Public License as published by
4c79b5
# the Free Software Foundation; either version 2 of the License, or
4c79b5
# (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
# ----------------------------------------------------------------------
4c79b5
# $Id: cli_getActions.sh 98 2010-09-19 16:01:53Z al $
4c79b5
# ----------------------------------------------------------------------
4c79b5
4c79b5
function cli_getActions {
4c79b5
4c79b5
    # Define variables as local to avoid conflicts outside.
4c79b5
    local ACTIONDIR=''
4c79b5
    local ACTIONFILES=''
4c79b5
    local ACTIONSCRIPT=''
4c79b5
    local ACTIONFUN=''
4c79b5
4c79b5
    # Define action directory. 
4c79b5
    ACTIONDIR=$(cli_getRepoName 'd' $ACTION)
4c79b5
4c79b5
    # Define action file name.
4c79b5
    ACTIONSCRIPT=${REPO_PATHS[8]}/${ACTIONDIR}/${ACTION}.sh
4c79b5
4c79b5
    # Check action existence.
4c79b5
    if [[ ! -f $ACTIONSCRIPT ]];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.
4c79b5
    ACTIONFILES=$(ls ${REPO_PATHS[8]}/${ACTIONDIR}/${ACTION}*.sh)
4c79b5
4c79b5
    for FILE in $ACTIONFILES;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.
4c79b5
            ACTIONFUN=$(grep '^function ' $FILE | cut -d' ' -f2)
4c79b5
            export -f $ACTIONFUN
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.
4c79b5
    eval $ACTION
4c79b5
4c79b5
}