Blame Scripts/Bash/Functions/cli_checkOptionValue.sh

4c79b5
#!/bin/bash
4c79b5
#
4c79b5
# cli_checkOptionValue.sh -- This function provides input validation
4c79b5
# for the option value (OPTIONVAL) variable.
4c79b5
#
4c79b5
# Copyright (C) 2009-2010 Alain Reguera Delgado
4c79b5
# 
4c79b5
# This program is free software; you can redistribute it and/or modify
4c79b5
# it under the terms of the GNU General Public License as published by
4c79b5
# the Free Software Foundation; either version 2 of the License, or
4c79b5
# (at your option) any later version.
4c79b5
# 
4c79b5
# This program is distributed in the hope that it will be useful, but
4c79b5
# WITHOUT ANY WARRANTY; without even the implied warranty of
4c79b5
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
4c79b5
# General Public License for more details.
4c79b5
#
4c79b5
# You should have received a copy of the GNU General Public License
4c79b5
# along with this program; if not, write to the Free Software
4c79b5
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
4c79b5
# USA.
4c79b5
# 
4c79b5
# ----------------------------------------------------------------------
4c79b5
# $Id: cli_checkOptionValue.sh 98 2010-09-19 16:01:53Z al $
4c79b5
# ----------------------------------------------------------------------
4c79b5
4c79b5
function cli_checkOptionValue {
4c79b5
4c79b5
    # Check option value before making an absolute path from it. 
4c79b5
    if [[ $OPTIONVAL =~ '(\.\.(/)?)' ]];then
4c79b5
        cli_printMessage "`gettext "The path provided can't be processed."`"
1f1b3c
        cli_printMessage "$(caller)" "AsToKnowMoreLine"
4c79b5
    fi
4c79b5
    if [[ ! $OPTIONVAL =~ '^[A-Za-z0-9\./-]+$' ]];then
4c79b5
        cli_printMessage "`gettext "The path provided can't be processed."`"
1f1b3c
        cli_printMessage "$(caller)" "AsToKnowMoreLine"
4c79b5
    fi
4c79b5
4c79b5
    # Re-define option value to match the correct absolute path. As we
4c79b5
    # are removing /home/centos/artwork/ from all centos-art.sh output
4c79b5
    # (in order to save space), we need to be sure that all strings
4c79b5
    # begining with trunk/..., branches/..., and tags/... use the
4c79b5
    # correct absolute path. That is, you can refer trunk's entries
4c79b5
    # using both /home/centos/artwork/trunk/... or just trunk/..., the
4c79b5
    # /home/centos/artwork/ part is automatically added here. 
4c79b5
    if [[ $OPTIONVAL =~ '^(trunk|branches|tags)' ]];then
4c79b5
        OPTIONVAL=/home/centos/artwork/$OPTIONVAL
4c79b5
    fi
4c79b5
4c79b5
    # Build absolute path from option value. It is required for the
4c79b5
    # option value to point a valid directory. Otherwise leave a
4c79b5
    # message and quit script execution.
4c79b5
    if [[ -d $OPTIONVAL ]];then
4c79b5
4c79b5
        # Add directory to the top of the directory stack.
4c79b5
        pushd "$OPTIONVAL" > /dev/null
4c79b5
4c79b5
        # Re-define option value using absolute path.
4c79b5
        OPTIONVAL=$(pwd)
4c79b5
4c79b5
        # Remove directory from the directory stack.
4c79b5
        popd > /dev/null
4c79b5
4c79b5
    else
4c79b5
        cli_printMessage "`gettext "The path provided is not a valid directory."`"
1f1b3c
        cli_printMessage "$(caller)" "AsToKnowMoreLine"
4c79b5
    fi
4c79b5
4c79b5
}