From 1b4ebe1121e72e2182c4a434b5f8a48cd7fd590a Mon Sep 17 00:00:00 2001 From: Alain Reguera Delgado Date: Dec 13 2013 16:36:38 +0000 Subject: Change tcar_getFilesList option parsing, from getopt to getopts. - Previously, tcar_getFilesList function was using getopt to parse options. However, the required implementation set at tcar_setModuleArguments function was removed in order to prevent unexpected commands from being passed through option values. In order to keep internal option parsing for tcar_getFilesList, but suppress the use of tcar_setModuleArguments, this update changes tcar_getFilesList interface to use getopts instead of getopt. --- diff --git a/tcar-scripts/tcar_getFilesList.sh b/tcar-scripts/tcar_getFilesList.sh index 3f43952..1a1fad9 100755 --- a/tcar-scripts/tcar_getFilesList.sh +++ b/tcar-scripts/tcar_getFilesList.sh @@ -29,66 +29,39 @@ function tcar_getFilesList { - # Define short options. - local ARGSS='' - - # Define long options. - local ARGSL='pattern:,mindepth:,maxdepth:,type:,uid:' - # Initialize pattern used to reduce the find output. local PATTERN="${TCAR_FLAG_FILTER}" # Initialize options used with find command. local OPTIONS='' - # Initialize arguments with an empty value and set it as local - # variable to this function scope. Doing this is very important to - # avoid any clash with higher execution environments. - local TCAR_MODULE_ARGUMENT='' - - # Process all arguments currently available in this function - # environment. If either ARGSS or ARGSL local variables have been - # defined, argument processing goes through getopt for validation. - tcar_setModuleArguments "${@}" - - # Redefine positional parameters using TCAR_MODULE_ARGUMENT variable. - eval set -- "${TCAR_MODULE_ARGUMENT}" + OPTIND=1 + while getopts "p:,a:,i:,t:,u:" OPTION "${@}"; do - while true;do - case "${1}" in - - --pattern ) - PATTERN="${2}" - shift 2 + case "${OPTION}" in + p ) + PATTERN="${OPTARG}" ;; - - --maxdepth ) - OPTIONS="${OPTIONS} -maxdepth ${2}" - shift 2 + a ) + OPTIONS="${OPTIONS} -maxdepth ${OPTARG}" ;; - - --mindepth ) - OPTIONS="${OPTIONS} -mindepth ${2}" - shift 2 + i ) + OPTIONS="${OPTIONS} -mindepth ${OPTARG}" ;; - - --type ) - OPTIONS="${OPTIONS} -type ${2}" - shift 2 - ;; - - --uid ) - OPTIONS="${OPTIONS} -uid ${2}" - shift 2 + t ) + OPTIONS="${OPTIONS} -type ${OPTARG}" ;; - - -- ) - shift 1 - break + u ) + OPTIONS="${OPTIONS} -uid ${OPTARG}" ;; esac + done + # Clean up positional parameters to reflect the fact that options + # have been processed already. + shift $(( ${OPTIND} - 1 )) + # At this point all options arguments have been processed and # removed from positional parameters. Only non-option arguments # remain so we use them as source location for find command to diff --git a/tcar-scripts/tcar_setModuleEnvironmentScripts.sh b/tcar-scripts/tcar_setModuleEnvironmentScripts.sh index 728ac63..bd9df2f 100755 --- a/tcar-scripts/tcar_setModuleEnvironmentScripts.sh +++ b/tcar-scripts/tcar_setModuleEnvironmentScripts.sh @@ -37,8 +37,9 @@ function tcar_setModuleEnvironmentScripts { local TCAR_MODULE_SCRIPTS="${TCAR_MODULE_INIT_FILE}" if [[ -d ${TCAR_MODULE_DIR} ]];then TCAR_MODULE_SCRIPTS="${TCAR_MODULE_SCRIPTS} - $(tcar_getFilesList ${TCAR_MODULE_DIR} \ - --pattern="${TCAR_MODULE_DIR}/${TCAR_MODULE_NAME}_[[:alnum:]]+\.sh$" --type='f')" + $(tcar_getFilesList \ + -p "${TCAR_MODULE_DIR}/${TCAR_MODULE_NAME}_[[:alnum:]]+\.sh$" \ + -t 'f' ${TCAR_MODULE_DIR})" fi # Verify the list of files. If no function file exists for the