|
|
878a2b |
#!/bin/bash
|
|
|
878a2b |
#
|
|
|
878a2b |
# cli_getRepoTLDir.sh -- This function returns the repository top
|
|
|
878a2b |
# level absolute path. The repository top level absolute path can be
|
|
|
e78806 |
# either ${TCAR_WORKDIR}/trunk, ${TCAR_WORKDIR}/branches, or
|
|
|
e78806 |
# ${TCAR_WORKDIR}/tags.
|
|
|
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_getRepoTLDir {
|
|
|
878a2b |
|
|
|
878a2b |
# Define short options.
|
|
|
878a2b |
local ARGSS='r'
|
|
|
878a2b |
|
|
|
878a2b |
# Define long options.
|
|
|
878a2b |
local ARGSL='relative'
|
|
|
878a2b |
|
|
|
878a2b |
# Initialize arguments with an empty value and set it as local
|
|
|
878a2b |
# variable to this function scope.
|
|
|
878a2b |
local ARGUMENTS=''
|
|
|
878a2b |
|
|
|
878a2b |
# Initialize path pattern and replacement.
|
|
|
878a2b |
local PATTERN=''
|
|
|
878a2b |
local REPLACE=''
|
|
|
878a2b |
|
|
|
878a2b |
# Redefine ARGUMENTS variable using current positional parameters.
|
|
|
878a2b |
cli_parseArgumentsReDef "$@"
|
|
|
878a2b |
|
|
|
878a2b |
# Redefine ARGUMENTS variable using getopt output.
|
|
|
878a2b |
cli_parseArguments
|
|
|
878a2b |
|
|
|
878a2b |
# Redefine positional parameters using ARGUMENTS variable.
|
|
|
878a2b |
eval set -- "$ARGUMENTS"
|
|
|
878a2b |
|
|
|
878a2b |
# Define the location we want to apply verifications to.
|
|
|
878a2b |
local LOCATION=$(echo $@ | sed -r 's!^.*--[[:space:]](.+)$!\1!')
|
|
|
878a2b |
|
|
|
878a2b |
# Verify location passed as non-option argument. If no location is
|
|
|
878a2b |
# passed as non-option argument to this function, then set the
|
|
|
878a2b |
# trunk directory structure as default location.
|
|
|
878a2b |
if [[ $LOCATION =~ '--$' ]];then
|
|
|
e78806 |
LOCATION=${TCAR_WORKDIR}/trunk
|
|
|
878a2b |
fi
|
|
|
878a2b |
|
|
|
878a2b |
# Verify location where the working copy should be stored in the
|
|
|
878a2b |
# workstations. Whatever the location provided be, it should refer
|
|
|
878a2b |
# to one of the top level directories inside the working copy of
|
|
|
878a2b |
# CentOS Artwork Repository which, in turn, should be sotred in
|
|
|
878a2b |
# the `artwork' directory immediatly under your home directory.
|
|
|
e78806 |
if [[ ! $LOCATION =~ "^${TCAR_WORKDIR}/(trunk|branches|tags)" ]];then
|
|
|
878a2b |
cli_printMessage "`eval_gettext "The location \\\"\\\$LOCATION\\\" is not valid."`" --as-error-line
|
|
|
878a2b |
fi
|
|
|
878a2b |
|
|
|
878a2b |
# Look for options passed through positional parameters.
|
|
|
878a2b |
while true;do
|
|
|
878a2b |
|
|
|
878a2b |
case "$1" in
|
|
|
878a2b |
|
|
|
878a2b |
-r|--relative )
|
|
|
e78806 |
PATTERN="^${TCAR_WORKDIR}/(trunk|branches|tags)/.+$"
|
|
|
878a2b |
REPLACE='\1'
|
|
|
878a2b |
shift 2
|
|
|
878a2b |
break
|
|
|
878a2b |
;;
|
|
|
878a2b |
|
|
|
878a2b |
-- )
|
|
|
e78806 |
PATTERN="^(${TCAR_WORKDIR}/(trunk|branches|tags))/.+$"
|
|
|
878a2b |
REPLACE='\1'
|
|
|
878a2b |
shift 1
|
|
|
878a2b |
break
|
|
|
878a2b |
;;
|
|
|
878a2b |
esac
|
|
|
878a2b |
|
|
|
878a2b |
done
|
|
|
878a2b |
|
|
|
878a2b |
# Print out top level directory.
|
|
|
878a2b |
echo $LOCATION | sed -r "s!${PATTERN}!${REPLACE}!g"
|
|
|
878a2b |
|
|
|
878a2b |
}
|