From 0c6cdddb161f15bff180ba7fe2e94a00084bb865 Mon Sep 17 00:00:00 2001 From: Alain Reguera Delgado Date: May 06 2011 01:37:00 +0000 Subject: Update cli_checkPathComponent.sh. --- diff --git a/Scripts/Functions/cli_checkPathComponent.sh b/Scripts/Functions/cli_checkPathComponent.sh index 264e3ca..c4e7aab 100755 --- a/Scripts/Functions/cli_checkPathComponent.sh +++ b/Scripts/Functions/cli_checkPathComponent.sh @@ -1,13 +1,7 @@ #!/bin/bash # # cli_checkPathComponent.sh -- This function checks parts/components -# from repository paths. Generally, the path information is passed to -# the function's first positional argument and the part/component we -# want to check is passed to the function's second positional -# argument. If the second argument is not passed, then the first -# argument is assumed to be the part/component we want to check, and -# the action value (ACTIONVAL) variable is used instead as source path -# information. +# from repository paths. # # Copyright (C) 2009, 2010, 2011 The CentOS Project # @@ -31,60 +25,87 @@ function cli_checkPathComponent { - local -a PATTERNS - local LOCATION='' - local OPTION='' - local MESSAGE='' - - # Define location which we retrive information from. - if [[ "$#" -eq 1 ]];then - LOCATION="$ACTIONVAL" - OPTION="$1" - elif [[ "$#" -eq 2 ]];then - LOCATION="$1" - OPTION="$2" - else - cli_printMessage "`gettext "Invalid arguments."`" --as-error-line - fi + # Define short options. + local ARGSS='' + + # Define long options. + local ARGSL='release,architecture,theme' + + # Initialize arguments with an empty value and set it as local + # variable to this function scope. + local ARGUMENTS='' + + # Initialize file variable as local to avoid conflicts outside + # this function scope. In the file variable will set the file path + # we are going to verify. + local FILE='' + + # Redefine ARGUMENTS variable using current positional parameters. + cli_doParseArgumentsReDef "$@" + + # Redefine ARGUMENTS variable using getopt output. + cli_doParseArguments + + # Redefine positional parameters using ARGUMENTS variable. + eval set -- "$ARGUMENTS" + + # Define list of locations we want to apply verifications to. + local FILES=$(echo $@ | sed -r 's!^.*--[[:space:]](.+)$!\1!') - # Define patterns. - PATTERNS[0]="^.+/$(cli_getPathComponent "${LOCATION}" '--release-pattern')/.*$" - PATTERNS[1]=$(cli_getPathComponent "${LOCATION}" '--release-architecture') - PATTERNS[2]=$(cli_getPathComponent "${LOCATION}" '--release-theme') - - # Identify which part of the release we want to output. - case "$OPTION" in - - '--release' ) - if [[ $LOCATION =~ ${PATTERN[0]} ]];then - MESSAGE="`eval_gettext "The release \\\"\\\$LOCATION\\\" is not valid."`" - fi - ;; - - '--architecture' ) - if [[ $LOCATION =~ ${PATTERN[1]} ]];then - MESSAGE="`eval_gettext "The architecture \\\"\\\$LOCATION\\\" is not valid."`" - fi - ;; - - '--theme' ) - if [[ $LOCATION =~ ${PATTERN[2]} ]];then - MESSAGE="`eval_gettext "The theme \\\"\\\$LOCATION\\\" is not valid."`" - fi - ;; - - '--default' | * ) - if [[ $LOCATION == '' ]] \ - || [[ $LOCATION =~ '(\.\.(/)?)' ]] \ - || [[ ! $LOCATION =~ '^[A-Za-z0-9\.:/_-]+$' ]]; then - MESSAGE="`eval_gettext "The value \\\"\\\$LOCATION\\\" is not valid."`" - fi - ;; - esac - - # Output message. - if [[ $MESSAGE != '' ]];then - cli_printMessage "$MESSAGE" --as-error-line + # Verify list of locations, it is required that one location be + # present in the list and also be a valid file. + if [[ $FILES == '--' ]];then + cli_printMessage "You need to provide one file at least." --as-error-line fi + # Look for options passed through positional parameters. + while true; do + + case "$1" in + + --release ) + for FILE in $(echo $FILES);do + if [[ $FILE =~ "^.+/$(cli_getPathComponent "${FILE}" '--release-pattern')/.*$" ]];then + cli_printMessage "`eval_gettext "The release \\\"\\\$FILE\\\" is not valid."`" --as-error-line + fi + done + shift 2 + break + ;; + + --architecture ) + for FILE in $(echo $FILES);do + if [[ $FILE =~ $(cli_getPathComponent "${FILE}" '--release-architecture') ]];then + cli_printMessage "`eval_gettext "The architecture \\\"\\\$FILE\\\" is not valid."`" --as-error-line + fi + done + shift 2 + break + ;; + + --theme ) + for FILE in $(echo $FILES);do + if [[ $FILE =~ $(cli_getPathComponent "${FILE}" '--release-theme') ]];then + cli_printMessage "`eval_gettext "The theme \\\"\\\$FILE\\\" is not valid."`" --as-error-line + fi + done + shift 2 + break + ;; + + -- ) + for FILE in $(echo $FILES);do + if [[ $FILE == '' ]] \ + || [[ $FILE =~ '(\.\.(/)?)' ]] \ + || [[ ! $FILE =~ '^[A-Za-z0-9\.:/_-]+$' ]]; then + cli_printMessage "`eval_gettext "The value \\\"\\\$FILE\\\" is not valid."`" --as-error-line + fi + done + shift 2 + break + ;; + + esac + done + }