Blame Scripts/Bash/Functions/Commons/cli_checkPathComponent.sh

878a2b
#!/bin/bash
878a2b
#
878a2b
# cli_checkPathComponent.sh -- This function checks parts/components
878a2b
# from repository paths.
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
# it under the terms of the GNU General Public License as published by
878a2b
# the Free Software Foundation; either version 2 of the License, or (at
878a2b
# your option) any later version.
878a2b
#
878a2b
# This program is distributed in the hope that it will be useful, but
878a2b
# WITHOUT ANY WARRANTY; without even the implied warranty of
878a2b
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
878a2b
# General Public License for more details.
878a2b
#
878a2b
# You should have received a copy of the GNU General Public License
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_checkPathComponent {
878a2b
878a2b
    # Define short options.
878a2b
    local ARGSS=''
878a2b
878a2b
    # Define long options.
d38270
    local ARGSL='release,architecture,motif,everything'
d38270
d38270
    # Initialize array variables used to process options.
d38270
    local -a CONDITION_PATTERN
d38270
    local -a CONDITION_MESSAGE
d38270
d38270
    # Initialize counter used to process array variables.
d38270
    local COUNTER=0
878a2b
878a2b
    # Initialize arguments with an empty value and set it as local
d38270
    # variable to this function scope. Doing this is very important to
d38270
    # avoid any clash with higher execution environments.
878a2b
    local ARGUMENTS=''
878a2b
d38270
    # Prepare ARGUMENTS for getopt.
878a2b
    cli_parseArgumentsReDef "$@"
878a2b
d38270
    # Redefine ARGUMENTS using getopt(1) command parser.
878a2b
    cli_parseArguments
878a2b
878a2b
    # Redefine positional parameters using ARGUMENTS variable.
878a2b
    eval set -- "$ARGUMENTS"
878a2b
878a2b
    # Look for options passed through positional parameters.
878a2b
    while true; do
878a2b
878a2b
        case "$1" in
878a2b
878a2b
            --release )
d38270
                CONDITION_PATTERN[((++${#CONDITION_PATTERN[*]}))]="^.+/$(cli_getPathComponent --release-pattern)/.*$"
d38270
                CONDITION_MESSAGE[((++${#CONDITION_MESSAGE[*]}))]="`gettext "contains an invalid release format."`"
d38270
                shift 1
878a2b
                ;;
878a2b
878a2b
            --architecture )
d38270
                CONDITION_PATTERN[((++${#CONDITION_PATTERN[*]}))]="$(cli_getPathComponent --architecture-pattern)"
d38270
                CONDITION_MESSAGE[((++${#CONDITION_MESSAGE[*]}))]="`gettext "contains an invalid architecture format."`" --as-error-line
d38270
                shift 1
878a2b
                ;;
878a2b
878a2b
            --motif )
d38270
                CONDITION_PATTERN[((++${#CONDITION_PATTERN[*]}))]="$(cli_getPathComponent --motif-pattern)"
d38270
                CONDITION_MESSAGE[((++${#CONDITION_MESSAGE[*]}))]="`gettext "contains an invalid theme format."`"
d38270
                shift 1
d38270
                ;;
d38270
d38270
            --everything )
d38270
                CONDITION_PATTERN[((++${#CONDITION_PATTERN[*]}))]="^[[:alnum:]/]+"
d38270
                CONDITION_MESSAGE[((++${#CONDITION_MESSAGE[*]}))]="`gettext "contains an invalid format."`"
d38270
                shift 1
878a2b
                ;;
878a2b
878a2b
            -- )
d38270
                shift 1
878a2b
                break
878a2b
                ;;
878a2b
878a2b
        esac
878a2b
    done
878a2b
d38270
    # Define list of files we want to apply verifications to, now that
d38270
    # all option-like arguments have been removed from positional
d38270
    # paramters list.
d38270
    local FILE=''
d38270
    local FILES="$@"
d38270
d38270
    for FILE in $FILES;do
d38270
d38270
        while [[ ${COUNTER} -lt ${#CONDITION_PATTERN[*]} ]];do
d38270
d38270
            if [[ ! ${FILE} =~ "${CONDITION_PATTERN[$COUNTER]}" ]];then
d38270
                cli_printMessage "${FILE} ${CONDITION_MESSAGE[$COUNTER]}" --as-error-line
d38270
            fi
d38270
d38270
            COUNTER=$(($COUNTER + 1))
d38270
d38270
        done
d38270
d38270
    done
d38270
878a2b
}