|
|
878a2b |
#!/bin/bash
|
|
|
878a2b |
#
|
|
|
878a2b |
# cli_exportFunctions.sh -- This function exports funtionalities to
|
|
|
878a2b |
# `centos-art.sh' script execution evironment.
|
|
|
878a2b |
#
|
|
|
03486a |
# Copyright (C) 2009, 2010, 2011, 2012 The CentOS Project
|
|
|
878a2b |
#
|
|
|
878a2b |
# This program is free software; you can redistribute it and/or modify
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
#
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
# General Public License for more details.
|
|
|
878a2b |
#
|
|
|
878a2b |
|
|
|
878a2b |
# along with this program; if not, write to the Free Software
|
|
|
878a2b |
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
878a2b |
#
|
|
|
878a2b |
# ----------------------------------------------------------------------
|
|
|
878a2b |
# $Id$
|
|
|
878a2b |
# ----------------------------------------------------------------------
|
|
|
878a2b |
|
|
|
878a2b |
function cli_exportFunctions {
|
|
|
878a2b |
|
|
|
a3d8f0 |
|
|
|
a3d8f0 |
if [[ $# -lt 1 ]];then
|
|
|
a3d8f0 |
cli_printMessage "${FUNCNAME}: `gettext "At least one argument must be passed."`"
|
|
|
a3d8f0 |
fi
|
|
|
a3d8f0 |
|
|
|
a3d8f0 |
# Retrive export identifier for the function we want to export.
|
|
|
a3d8f0 |
local EXPORTID=$1
|
|
|
a3d8f0 |
|
|
|
a3d8f0 |
|
|
|
cd44d0 |
local LOCATION=${CLI_BASEDIR}/Functions/$(dirname ${EXPORTID})
|
|
|
878a2b |
|
|
|
a3d8f0 |
|
|
|
a3d8f0 |
local SUFFIX=$(basename "$EXPORTID")
|
|
|
878a2b |
|
|
|
a3d8f0 |
|
|
|
a3d8f0 |
|
|
|
a3d8f0 |
# function, use the function name value (CLI_FUNCNAME) as default
|
|
|
a3d8f0 |
|
|
|
878a2b |
if [[ $SUFFIX == '' ]];then
|
|
|
cd44d0 |
SUFFIX="${CLI_FUNCNAME}"
|
|
|
878a2b |
fi
|
|
|
878a2b |
|
|
|
cd44d0 |
|
|
|
cd44d0 |
|
|
|
cd44d0 |
SUFFIX=${SUFFIX}'[[:alpha:]_]*'
|
|
|
cd44d0 |
|
|
|
a3d8f0 |
|
|
|
878a2b |
|
|
|
a3d8f0 |
local PATTERN="^function[[:space:]]+${SUFFIX}[[:space:]]+{$"
|
|
|
878a2b |
|
|
|
a3d8f0 |
|
|
|
878a2b |
local FUNCFILE=''
|
|
|
790d2d |
local FUNCFILES=$(cli_getFilesList ${LOCATION} --pattern="${SUFFIX}\.sh" \
|
|
|
cd44d0 |
--maxdepth='1' --mindepth='1' --type='f')
|
|
|
878a2b |
|
|
|
a3d8f0 |
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
|
|
|
878a2b |
if [[ $FUNCFILES == '' ]];then
|
|
|
a3d8f0 |
cli_printMessage "${FUNCNAME}: `gettext "No function file was found."`" --as-error-line
|
|
|
878a2b |
fi
|
|
|
878a2b |
|
|
|
a3d8f0 |
|
|
|
878a2b |
for FUNCFILE in $FUNCFILES;do
|
|
|
878a2b |
|
|
|
a3d8f0 |
|
|
|
790d2d |
cli_checkFiles -x ${FUNCFILE}
|
|
|
878a2b |
|
|
|
a3d8f0 |
|
|
|
790d2d |
. ${FUNCFILE}
|
|
|
878a2b |
|
|
|
a3d8f0 |
|
|
|
878a2b |
|
|
|
878a2b |
export -f $(egrep "${PATTERN}" ${FUNCFILE} | gawk '{ print $2 }')
|
|
|
878a2b |
|
|
|
878a2b |
done
|
|
|
878a2b |
|
|
|
878a2b |
}
|