|
|
4c79b5 |
#!/bin/bash
|
|
|
4c79b5 |
#
|
|
|
37881a |
# cli_checkRepoDirSource.sh -- This function provides input validation
|
|
|
37881a |
# to repository entries considered as source locations.
|
|
|
4c79b5 |
#
|
|
|
c9be1c |
# Copyright (C) 2009-2011 Alain Reguera Delgado
|
|
|
4c79b5 |
#
|
|
|
7cd8e9 |
# This program is free software; you can redistribute it and/or
|
|
|
7cd8e9 |
# modify it under the terms of the GNU General Public License as
|
|
|
7cd8e9 |
# published by the Free Software Foundation; either version 2 of the
|
|
|
7cd8e9 |
# License, or (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 |
# ----------------------------------------------------------------------
|
|
|
418249 |
# $Id$
|
|
|
4c79b5 |
# ----------------------------------------------------------------------
|
|
|
4c79b5 |
|
|
|
37881a |
function cli_checkRepoDirSource {
|
|
|
55d653 |
|
|
|
37881a |
# Check source value before making an absolute path from it.
|
|
|
55d653 |
if [[ $ACTIONVAL == '' ]] \
|
|
|
55d653 |
|| [[ $ACTIONVAL =~ '(\.\.(/)?)' ]] \
|
|
|
55d653 |
|| [[ ! $ACTIONVAL =~ '^[A-Za-z0-9\.:/-]+$' ]];then
|
|
|
55d653 |
cli_printMessage "`eval_gettext "The value \\\`\\\$ACTIONVAL' is not valid."`" 'AsErrorLine'
|
|
|
1f1b3c |
cli_printMessage "$(caller)" "AsToKnowMoreLine"
|
|
|
4c79b5 |
fi
|
|
|
4c79b5 |
|
|
|
37881a |
# Redefine source value to build repository absolute path from
|
|
|
a58b61 |
# repository top level on. As we are removing
|
|
|
a58b61 |
# /home/centos/artwork/ from all centos-art.sh output (in order to
|
|
|
a58b61 |
# save horizontal output space), we need to be sure that all
|
|
|
a58b61 |
# strings begining with trunk/..., branches/..., and tags/... use
|
|
|
a58b61 |
# the correct absolute path. That is, you can refer trunk's
|
|
|
a58b61 |
# entries using both /home/centos/artwork/trunk/... or just
|
|
|
a58b61 |
# trunk/..., the /home/centos/artwork/ part is automatically added
|
|
|
a58b61 |
# here.
|
|
|
a58b61 |
if [[ $ACTIONVAL =~ '^(trunk|branches|tags)' ]];then
|
|
|
a58b61 |
ACTIONVAL=/home/centos/artwork/$ACTIONVAL
|
|
|
4c79b5 |
fi
|
|
|
4c79b5 |
|
|
|
37881a |
# Re-define source value to build repository absolute path from
|
|
|
a58b61 |
# repository relative paths. This let us to pass repository
|
|
|
37881a |
# relative paths as source value. Passing relative paths as
|
|
|
37881a |
# source value may save us some typing; specially if we are stood
|
|
|
37881a |
# a few levels up from the location we want to refer to as source
|
|
|
a58b61 |
# value. There is no need to pass the absolute path to it, just
|
|
|
a58b61 |
# refere it relatively.
|
|
|
a58b61 |
if [[ -d ${ACTIONVAL} ]];then
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# Add directory to the top of the directory stack.
|
|
|
a58b61 |
pushd "$ACTIONVAL" > /dev/null
|
|
|
4c79b5 |
|
|
|
a58b61 |
# Check directory existence inside the repository.
|
|
|
23c7a5 |
if [[ $(pwd) =~ '^/home/centos/artwork' ]];then
|
|
|
37881a |
# Re-define source value using absolute path.
|
|
|
a58b61 |
ACTIONVAL=$(pwd)
|
|
|
a58b61 |
else
|
|
|
55d653 |
cli_printMessage "`eval_gettext "The location \\\`\\\$ACTIONVAL' is not valid."`" 'AsErrorLine'
|
|
|
02e00f |
cli_printMessage "$(caller)" 'AsToKnowMoreLine'
|
|
|
a58b61 |
fi
|
|
|
a58b61 |
|
|
|
a58b61 |
# Remove directory from the directory stack.
|
|
|
a58b61 |
popd > /dev/null
|
|
|
a58b61 |
|
|
|
a58b61 |
elif [[ -f ${ACTIONVAL} ]];then
|
|
|
a58b61 |
|
|
|
a58b61 |
# Add directory to the top of the directory stack.
|
|
|
a58b61 |
pushd "$(dirname $ACTIONVAL)" > /dev/null
|
|
|
a58b61 |
|
|
|
a58b61 |
# Check directory existence inside the repository.
|
|
|
23c7a5 |
if [[ $(pwd) =~ '^/home/centos/artwork' ]];then
|
|
|
37881a |
# Re-define source value using absolute path.
|
|
|
a58b61 |
ACTIONVAL=$(pwd)/$(basename $ACTIONVAL)
|
|
|
a58b61 |
else
|
|
|
55d653 |
cli_printMessage "`eval_gettext "The location \\\`\\\$ACTIONVAL' is not valid."`" 'AsErrorLine'
|
|
|
02e00f |
cli_printMessage "$(caller)" 'AsToKnowMoreLine'
|
|
|
a58b61 |
fi
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# Remove directory from the directory stack.
|
|
|
4c79b5 |
popd > /dev/null
|
|
|
4c79b5 |
|
|
|
37881a |
else
|
|
|
37881a |
|
|
|
37881a |
# At this there is no existent working copy entry, nor a valid
|
|
|
37881a |
# url. The source value can only be considered as such if it
|
|
|
37881a |
# is an existent working copy or valid url. So, print a
|
|
|
37881a |
# message and stop script execution.
|
|
|
55d653 |
cli_printMessage "`eval_gettext "The location \\\`\\\$ACTIONVAL' is not valid."`" 'AsErrorLine'
|
|
|
37881a |
cli_printMessage "$(caller)" 'AsToKnowMoreLine'
|
|
|
37881a |
|
|
|
4c79b5 |
fi
|
|
|
4c79b5 |
|
|
|
4c79b5 |
}
|