Blame Scripts/Functions/cli_getRepoTLDir.sh

7a5604
#!/bin/bash
7a5604
#
f128ea
# cli_getRepoTLDir.sh -- This function returns the repository top
726fe2
# level absolute path. The repository top level absolute path can be
726fe2
# either ${HOME}/artwork/trunk, ${HOME}/artwork/branches, or
726fe2
# ${HOME}/artwork/tags.
7a5604
#
2d3646
# Copyright (C) 2009, 2010, 2011 The CentOS Project
fa95b1
#
fa95b1
# This program is free software; you can redistribute it and/or modify
fa95b1
# it under the terms of the GNU General Public License as published by
dcd347
# the Free Software Foundation; either version 2 of the License, or (at
dcd347
# your option) any later version.
fa95b1
#
74a058
# This program is distributed in the hope that it will be useful, but
74a058
# WITHOUT ANY WARRANTY; without even the implied warranty of
7a5604
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
7a5604
# General Public License for more details.
7a5604
#
7a5604
# You should have received a copy of the GNU General Public License
7a5604
# along with this program; if not, write to the Free Software
dcd347
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
7ac5a5
#
7a5604
# ----------------------------------------------------------------------
7a5604
# $Id$
7a5604
# ----------------------------------------------------------------------
7a5604
f128ea
function cli_getRepoTLDir {
7a5604
726fe2
    # Define short options.
726fe2
    local ARGSS='r'
726fe2
726fe2
    # Define long options.
726fe2
    local ARGSL='relative'
726fe2
726fe2
    # Initialize arguments with an empty value and set it as local
726fe2
    # variable to this function scope.
726fe2
    local ARGUMENTS=''
726fe2
726fe2
    # Initialize path pattern and replacement.
a129e4
    local PATTERN=''
a129e4
    local REPLACE=''
726fe2
726fe2
    # Redefine ARGUMENTS variable using current positional parameters. 
726fe2
    cli_doParseArgumentsReDef "$@"
726fe2
726fe2
    # Redefine ARGUMENTS variable using getopt output.
726fe2
    cli_doParseArguments
726fe2
726fe2
    # Redefine positional parameters using ARGUMENTS variable.
726fe2
    eval set -- "$ARGUMENTS"
726fe2
726fe2
    # Define the location we want to apply verifications to.
726fe2
    local LOCATION=$(echo $@ | sed -r 's!^.*--[[:space:]](.+)$!\1!')
726fe2
726fe2
    # Verify location passed as non-option argument. If no location is
726fe2
    # passed as non-option argument to this function, then use action
726fe2
    # value as default location.
726fe2
    if [[ $LOCATION == '--' ]];then
726fe2
        LOCATION=$ACTIONVAL
a129e4
    fi
a129e4
726fe2
    # Verify location where the working copy should be stored in the
726fe2
    # workstations. Whatever the location provided be, it should refer
726fe2
    # to one of the top level directories inside the working copy of
726fe2
    # CentOS Artwork Repository which, in turn, should be sotred in
726fe2
    # the `artwork' directory immediatly under your home directory.
726fe2
    if [[ ! $LOCATION =~ "^${HOME}/artwork/(trunk|branches|tags)/.+$" ]];then
726fe2
        cli_printMessage "`eval_gettext "The location \\\"\\\$LOCATION\\\" is not valid."`" --as-error-line
726fe2
    fi
726fe2
726fe2
    # Look for options passed through positional parameters.
726fe2
    while true;do
726fe2
726fe2
        case "$1" in
726fe2
    
a129e4
            -r|--relative )
7b46a4
                PATTERN="^${HOME}/artwork/(trunk|branches|tags)/.+$"
a129e4
                REPLACE='\1'
726fe2
                shift 2
726fe2
                break
a129e4
                ;;
726fe2
726fe2
            -- )
7b46a4
                PATTERN="^(${HOME}/artwork/(trunk|branches|tags))/.+$"
a129e4
                REPLACE='\1'
726fe2
                shift 1
726fe2
                break
a129e4
                ;;
a129e4
        esac
a129e4
726fe2
    done
726fe2
726fe2
    # Print out top level directory.
a129e4
    echo $LOCATION | sed -r "s!${PATTERN}!${REPLACE}!g"
7a5604
7a5604
}