Blame Scripts/Bash/centos-art/Functions/cli_checkPathComponent.sh

64e627
#!/bin/bash
64e627
#
64e627
# cli_checkPathComponent.sh -- This function checks parts/components
64e627
# from repository paths. Generally, the path information is passed to
64e627
# the function's first positional argument and the part/component we
64e627
# want to check is passed to the function's second positional
64e627
# argument. If the second argument is not passed, then the first
64e627
# argument is assumed to be the part/component we want to check, and
64e627
# the action value (ACTIONVAL) variable is used instead as source path
64e627
# information.
64e627
#
64e627
# Copyright (C) 2009-2011 Alain Reguera Delgado
64e627
# 
64e627
# This program is free software; you can redistribute it and/or
64e627
# modify it under the terms of the GNU General Public License as
64e627
# published by the Free Software Foundation; either version 2 of the
64e627
# License, or (at your option) any later version.
64e627
# 
64e627
# This program is distributed in the hope that it will be useful, but
64e627
# WITHOUT ANY WARRANTY; without even the implied warranty of
64e627
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
64e627
# General Public License for more details.
64e627
#
64e627
# You should have received a copy of the GNU General Public License
64e627
# along with this program; if not, write to the Free Software
64e627
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
64e627
# USA.
64e627
# 
64e627
# ----------------------------------------------------------------------
7b46a4
# $Id$
64e627
# ----------------------------------------------------------------------
64e627
64e627
function cli_checkPathComponent {
64e627
64e627
    local -a PATTERNS
64e627
    local LOCATION=''
64e627
    local OPTION=''
64e627
    local MESSAGE=''
64e627
64e627
    # Define location which we retrive information from.
64e627
    if [[ "$#" -eq 1 ]];then
64e627
        LOCATION="$ACTIONVAL"
64e627
        OPTION="$1"
64e627
    elif [[ "$#" -eq 2 ]];then
64e627
        LOCATION="$1"
64e627
        OPTION="$2"
64e627
    else
64e627
       cli_printMessage "cli_checkPathComponent: `gettext "Invalid arguments."`" 'AsErrorLine'
64e627
       cli_printMessage "$(caller)" 'AsToKnowMoreLine' 
64e627
    fi
64e627
64e627
    # Define patterns.
64e627
    PATTERNS[0]="^.+/$(cli_getPathComponent "${LOCATION}" '--release-pattern')/.*$"
64e627
    PATTERNS[1]=$(cli_getPathComponent "${LOCATION}" '--release-architecture')
64e627
    PATTERNS[2]=$(cli_getPathComponent "${LOCATION}" '--release-theme')
64e627
64e627
    # Identify which part of the release we want to output.
64e627
    case "$OPTION" in
64e627
64e627
        '--release' )
64e627
            if [[ $LOCATION =~ ${PATTERN[0]} ]];then
0b4ba3
                MESSAGE="`eval_gettext "The release \\\`\\\$LOCATION' is not valid."`"
64e627
            fi
64e627
            ;;
64e627
64e627
        '--architecture' )
64e627
            if [[ $LOCATION =~ ${PATTERN[1]} ]];then
0b4ba3
                MESSAGE="`eval_gettext "The architecture \\\`\\\$LOCATION' is not valid."`"
64e627
            fi
64e627
            ;;
64e627
64e627
        '--theme' )
64e627
            if [[ $LOCATION =~ ${PATTERN[2]} ]];then
0b4ba3
                MESSAGE="`eval_gettext "The theme \\\`\\\$LOCATION' is not valid."`"
64e627
            fi
64e627
            ;;
64e627
8f5395
        '--default' | * )
8f5395
            if [[ $LOCATION == '' ]] \
8f5395
                || [[ $LOCATION =~ '(\.\.(/)?)' ]] \
8f5395
                || [[ ! $LOCATION =~ '^[A-Za-z0-9\.:/_-]+$' ]]; then 
b790be
                MESSAGE="`eval_gettext "The value \\\`\\\$LOCATION' is not valid."`"
64e627
            fi
64e627
            ;;
64e627
    esac
64e627
64e627
    # Output message.
64e627
    if [[ $MESSAGE != '' ]];then
64e627
        cli_printMessage "$MESSAGE" 'AsErrorLine'
64e627
        cli_printMessage "$(caller)" "AsToKnowMoreLine"
64e627
    fi
64e627
64e627
}