Blame tcar-scripts/tcar_setModuleArguments.sh

Alain Reguera Delgado 66223d
#!/bin/bash
Alain Reguera Delgado 66223d
######################################################################
Alain Reguera Delgado 66223d
#
Alain Reguera Delgado 66223d
#   tcar_setModuleArguments.sh -- This function uses getopt to process
Alain Reguera Delgado 66223d
#   arguments passed to tcar.sh script.
Alain Reguera Delgado 66223d
#
Alain Reguera Delgado 66223d
#   This function works with the following three variables:
Alain Reguera Delgado 66223d
#
Alain Reguera Delgado 66223d
#       ARGSS
Alain Reguera Delgado 66223d
#           Stores getopt short arguments definition.
Alain Reguera Delgado 66223d
#
Alain Reguera Delgado 66223d
#       ARGSL
Alain Reguera Delgado 66223d
#           Stores getopt long arguments definition.  
Alain Reguera Delgado 66223d
#
Alain Reguera Delgado 66223d
#       TCAR_MODULE_ARGUMENT
Alain Reguera Delgado 66223d
#           Stores arguments passed to functions or command-line
Alain Reguera Delgado 66223d
#           interface depending the context it is defined.
Alain Reguera Delgado 66223d
#
Alain Reguera Delgado 66223d
#   These three variables are not defined in this function but the
Alain Reguera Delgado 66223d
#   function environment you want to provide option parsing for,
Alain Reguera Delgado 66223d
#   through getopt command. Using local definition for these three
Alain Reguera Delgado 66223d
#   variables let you to nest option parsing inside different
Alain Reguera Delgado 66223d
#   function-environment levels.
Alain Reguera Delgado 66223d
#
Alain Reguera Delgado 66223d
#   Written by:
Alain Reguera Delgado 66223d
#   * Alain Reguera Delgado <al@centos.org.cu>, 2009-2013
Alain Reguera Delgado 66223d
#
Alain Reguera Delgado 66223d
# Copyright (C) 2009-2013 The CentOS Artwork SIG
Alain Reguera Delgado 66223d
#
Alain Reguera Delgado 66223d
# This program is free software; you can redistribute it and/or modify
Alain Reguera Delgado 66223d
# it under the terms of the GNU General Public License as published by
Alain Reguera Delgado 66223d
# the Free Software Foundation; either version 2 of the License, or (at
Alain Reguera Delgado 66223d
# your option) any later version.
Alain Reguera Delgado 66223d
#
Alain Reguera Delgado 66223d
# This program is distributed in the hope that it will be useful, but
Alain Reguera Delgado 66223d
# WITHOUT ANY WARRANTY; without even the implied warranty of
Alain Reguera Delgado 66223d
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Alain Reguera Delgado 66223d
# General Public License for more details.
Alain Reguera Delgado 66223d
#
Alain Reguera Delgado 66223d
# You should have received a copy of the GNU General Public License
Alain Reguera Delgado 66223d
# along with this program; if not, write to the Free Software
Alain Reguera Delgado 66223d
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Alain Reguera Delgado 66223d
#
Alain Reguera Delgado 66223d
######################################################################
Alain Reguera Delgado 66223d
Alain Reguera Delgado 66223d
function tcar_setModuleArguments {
Alain Reguera Delgado 66223d
Alain Reguera Delgado 66223d
    # Verify non-option arguments passed to command-line. If there
Alain Reguera Delgado 66223d
    # isn't any or dot is provided, redefine the TCAR_MODULE_ARGUMENT
Alain Reguera Delgado 66223d
    # variable to use the current location the tcar.sh script
Alain Reguera Delgado 66223d
    # was called from.
Alain Reguera Delgado 2bb25b
    if [[ -z "${TCAR_MODULE_ARGUMENT}" ]];then
Alain Reguera Delgado 66223d
        TCAR_MODULE_ARGUMENT=${PWD}
Alain Reguera Delgado 66223d
    fi
Alain Reguera Delgado 66223d
Alain Reguera Delgado 66223d
    # Verify presence of either short or long options in the
Alain Reguera Delgado 66223d
    # environment. If they are present apply option validation through
Alain Reguera Delgado 66223d
    # getopt.
Alain Reguera Delgado 66223d
    if [[ ! -z ${ARGSS} ]] || [[ ! -z ${ARGSL} ]];then
Alain Reguera Delgado 66223d
Alain Reguera Delgado 66223d
        # Redefine positional parameters using TCAR_MODULE_ARGUMENT variable.
Alain Reguera Delgado 66223d
        eval set -- "${TCAR_MODULE_ARGUMENT}"
Alain Reguera Delgado 66223d
Alain Reguera Delgado 66223d
        # Process positional parameters using getopt's option validation.
Alain Reguera Delgado 66223d
        TCAR_MODULE_ARGUMENT=$(getopt -o "${ARGSS}" -l "${ARGSL}" \
Alain Reguera Delgado bbb179
            -n "${TCAR_SCRIPT_PACKAGE} (${TCAR_MODULE_NAME})" -- "${@}")
Alain Reguera Delgado 66223d
Alain Reguera Delgado 66223d
        # Verify getopt's exit status and finish the script execution
Alain Reguera Delgado 66223d
        # with an error message, if it failed.
Alain Reguera Delgado 66223d
        if [[ $? -ne 0 ]];then
Alain Reguera Delgado 66223d
            tcar_printMessage "`gettext "The argument verification failed."`" --as-error-line
Alain Reguera Delgado 66223d
        fi
Alain Reguera Delgado 66223d
Alain Reguera Delgado 66223d
    fi
Alain Reguera Delgado 66223d
Alain Reguera Delgado 66223d
}