|
|
4c79b5 |
#!/bin/bash
|
|
|
4c79b5 |
#
|
|
|
eb238e |
# cli_getRepoName.sh -- This function standardize file and directories
|
|
|
eb238e |
|
|
|
eb238e |
# Repository. As convenction, regular files are written in lower case
|
|
|
4c79b5 |
|
|
|
eb238e |
# in upper case. Use this function to sanitate the name of regular
|
|
|
b1bcf2 |
|
|
|
4c79b5 |
#
|
|
|
2fe9b7 |
# Copyright (C) 2009, 2010, 2011 The CentOS Project
|
|
|
fa95b1 |
#
|
|
|
fa95b1 |
# This program is free software; you can redistribute it and/or modify
|
|
|
fa95b1 |
|
|
|
dcd347 |
|
|
|
dcd347 |
|
|
|
fa95b1 |
#
|
|
|
74a058 |
|
|
|
74a058 |
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# General Public License for more details.
|
|
|
4c79b5 |
#
|
|
|
4c79b5 |
|
|
|
4c79b5 |
# along with this program; if not, write to the Free Software
|
|
|
dcd347 |
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
7ac5a5 |
#
|
|
|
4c79b5 |
# ----------------------------------------------------------------------
|
|
|
418249 |
# $Id$
|
|
|
4c79b5 |
# ----------------------------------------------------------------------
|
|
|
4c79b5 |
|
|
|
4c79b5 |
function cli_getRepoName {
|
|
|
4c79b5 |
|
|
|
eb238e |
|
|
|
550c05 |
local NAME="$1"
|
|
|
b1bcf2 |
|
|
|
550c05 |
|
|
|
550c05 |
|
|
|
550c05 |
|
|
|
550c05 |
|
|
|
550c05 |
if [[ $NAME =~ '^-' ]];then
|
|
|
550c05 |
return
|
|
|
550c05 |
fi
|
|
|
b1bcf2 |
|
|
|
550c05 |
|
|
|
550c05 |
case "$2" in
|
|
|
b1bcf2 |
|
|
|
550c05 |
-f|
|
|
|
b1bcf2 |
|
|
|
550c05 |
|
|
|
550c05 |
|
|
|
550c05 |
|
|
|
550c05 |
NAME=$(basename $NAME)
|
|
|
b1bcf2 |
|
|
|
550c05 |
|
|
|
550c05 |
NAME=$(echo $NAME \
|
|
|
550c05 |
| tr -s ' ' '_' \
|
|
|
550c05 |
| tr '[:upper:]' '[:lower:]')
|
|
|
550c05 |
|
|
|
b1bcf2 |
|
|
|
550c05 |
-d|
|
|
|
b1bcf2 |
|
|
|
550c05 |
local DIR=''
|
|
|
550c05 |
local DIRS=''
|
|
|
550c05 |
local CLEANDIRS=''
|
|
|
550c05 |
local PREFIXDIR=''
|
|
|
b1bcf2 |
|
|
|
550c05 |
|
|
|
550c05 |
|
|
|
550c05 |
|
|
|
550c05 |
# back to create a clean path string.
|
|
|
eb238e |
|
|
|
550c05 |
|
|
|
550c05 |
|
|
|
550c05 |
|
|
|
550c05 |
|
|
|
550c05 |
|
|
|
550c05 |
if [[ $NAME =~ '.+/.+' ]];then
|
|
|
550c05 |
|
|
|
550c05 |
|
|
|
550c05 |
|
|
|
550c05 |
|
|
|
550c05 |
|
|
|
550c05 |
|
|
|
550c05 |
|
|
|
550c05 |
|
|
|
550c05 |
PREFIXDIR=$(echo $NAME \
|
|
|
550c05 |
| sed -r "s,^(($(cli_getRepoTLDir)/)?(trunk|branches|tags)/).+$,\1,")
|
|
|
550c05 |
|
|
|
550c05 |
# ... and remove them from the path information we do
|
|
|
550c05 |
|
|
|
550c05 |
DIRS=$(dirname "$NAME" \
|
|
|
550c05 |
| sed -r "s!^${PREFIXDIR}!!" \
|
|
|
550c05 |
| tr '/' ' ')
|
|
|
550c05 |
|
|
|
550c05 |
else
|
|
|
eb238e |
|
|
|
550c05 |
|
|
|
550c05 |
|
|
|
550c05 |
|
|
|
550c05 |
DIRS=$NAME
|
|
|
eb238e |
|
|
|
550c05 |
fi
|
|
|
eb238e |
|
|
|
550c05 |
for DIR in $DIRS;do
|
|
|
eb238e |
|
|
|
550c05 |
|
|
|
550c05 |
if [[ $DIR =~ '^[a-z]' ]];then
|
|
|
550c05 |
DIR=$(echo ${DIR} \
|
|
|
550c05 |
| tr -s ' ' '_' \
|
|
|
550c05 |
| tr '[:upper:]' '[:lower:]' \
|
|
|
550c05 |
| sed -r 's/^([[:alpha:]])/\u\1/')
|
|
|
550c05 |
fi
|
|
|
eb238e |
|
|
|
550c05 |
|
|
|
550c05 |
CLEANDIRS="${CLEANDIRS}/$DIR"
|
|
|
eb238e |
|
|
|
550c05 |
done
|
|
|
2ad5f6 |
|
|
|
550c05 |
|
|
|
550c05 |
NAME=$(echo ${CLEANDIRS} | sed -r "s!^/!!")
|
|
|
2ad5f6 |
|
|
|
550c05 |
|
|
|
550c05 |
|
|
|
550c05 |
if [[ "$PREFIXDIR" != '' ]];then
|
|
|
550c05 |
NAME=${PREFIXDIR}${NAME}
|
|
|
550c05 |
fi
|
|
|
550c05 |
|
|
|
2ad5f6 |
|
|
|
550c05 |
esac
|
|
|
b1bcf2 |
|
|
|
eb238e |
|
|
|
b1bcf2 |
echo $NAME
|
|
|
4c79b5 |
|
|
|
4c79b5 |
}
|