|
|
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 |
#
|
|
|
3b0984 |
# Copyright (C) 2009, 2010, 2011 The CentOS Artwork SIG
|
|
|
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 |
|
|
|
eb238e |
local ARGSS='f,d'
|
|
|
b1bcf2 |
|
|
|
eb238e |
|
|
|
eb238e |
local ARGSL='basename,dirname'
|
|
|
b1bcf2 |
|
|
|
eb238e |
|
|
|
eb238e |
|
|
|
eb238e |
local ARGUMENTS=''
|
|
|
b1bcf2 |
|
|
|
eb238e |
|
|
|
793c4c |
cli_parseArgumentsReDef "$@"
|
|
|
eb238e |
|
|
|
eb238e |
|
|
|
793c4c |
cli_parseArguments
|
|
|
eb238e |
|
|
|
eb238e |
|
|
|
eb238e |
eval set -- "$ARGUMENTS"
|
|
|
b1bcf2 |
|
|
|
eb238e |
|
|
|
eb238e |
local NAME=$(echo $@ | sed -r 's!^.*--[[:space:]](.+)$!\1!')
|
|
|
b1bcf2 |
|
|
|
eb238e |
|
|
|
eb238e |
while true;do
|
|
|
b1bcf2 |
|
|
|
eb238e |
case "$1" in
|
|
|
b1bcf2 |
|
|
|
eb238e |
-f|
|
|
|
b1bcf2 |
|
|
|
eb238e |
|
|
|
eb238e |
|
|
|
eb238e |
|
|
|
eb238e |
NAME=$(basename $NAME)
|
|
|
b1bcf2 |
|
|
|
eb238e |
|
|
|
eb238e |
NAME=$(echo $NAME \
|
|
|
eb238e |
| tr -s ' ' '_' \
|
|
|
eb238e |
| tr '[:upper:]' '[:lower:]')
|
|
|
b1bcf2 |
|
|
|
eb238e |
shift 1
|
|
|
eb238e |
|
|
|
b1bcf2 |
|
|
|
eb238e |
-d|
|
|
|
b1bcf2 |
|
|
|
eb238e |
local DIR=''
|
|
|
eb238e |
local DIRS=''
|
|
|
eb238e |
local CLEANDIRS=''
|
|
|
eb238e |
local PREFIXDIR=''
|
|
|
b1bcf2 |
|
|
|
eb238e |
|
|
|
eb238e |
|
|
|
eb238e |
|
|
|
eb238e |
# combine them back to create a clean path string.
|
|
|
eb238e |
|
|
|
eb238e |
|
|
|
eb238e |
# part of it only. Of course, this is applied if
|
|
|
eb238e |
|
|
|
eb238e |
|
|
|
eb238e |
|
|
|
eb238e |
|
|
|
eb238e |
if [[ $NAME =~ '.+/.+' ]];then
|
|
|
eb238e |
|
|
|
eb238e |
|
|
|
eb238e |
|
|
|
eb238e |
|
|
|
eb238e |
|
|
|
eb238e |
|
|
|
eb238e |
|
|
|
eb238e |
|
|
|
eb238e |
PREFIXDIR=$(echo $NAME \
|
|
|
eb238e |
| sed -r "s,^(($(cli_getRepoTLDir)/)?(trunk|branches|tags)/).+$,\1,")
|
|
|
eb238e |
|
|
|
eb238e |
# ... and remove them from the path information we
|
|
|
eb238e |
|
|
|
eb238e |
DIRS=$(dirname "$NAME" \
|
|
|
eb238e |
| sed -r "s!^${PREFIXDIR}!!" \
|
|
|
eb238e |
| tr '/' ' ')
|
|
|
eb238e |
|
|
|
eb238e |
else
|
|
|
eb238e |
|
|
|
eb238e |
# At this point, there is not directory part in
|
|
|
eb238e |
|
|
|
eb238e |
|
|
|
eb238e |
DIRS=$NAME
|
|
|
eb238e |
|
|
|
eb238e |
fi
|
|
|
eb238e |
|
|
|
eb238e |
for DIR in $DIRS;do
|
|
|
eb238e |
|
|
|
eb238e |
|
|
|
eb238e |
if [[ $DIR =~ '^[a-z]' ]];then
|
|
|
eb238e |
DIR=$(echo ${DIR} \
|
|
|
eb238e |
| tr -s ' ' '_' \
|
|
|
eb238e |
| tr '[:upper:]' '[:lower:]' \
|
|
|
eb238e |
| sed -r 's/^([[:alpha:]])/\u\1/')
|
|
|
eb238e |
fi
|
|
|
eb238e |
|
|
|
eb238e |
|
|
|
eb238e |
CLEANDIRS="${CLEANDIRS}/$DIR"
|
|
|
eb238e |
|
|
|
eb238e |
done
|
|
|
eb238e |
|
|
|
eb238e |
|
|
|
eb238e |
NAME=$(echo ${CLEANDIRS} | sed -r "s!^/!!")
|
|
|
eb238e |
|
|
|
eb238e |
|
|
|
eb238e |
|
|
|
eb238e |
if [[ "$PREFIXDIR" != '' ]];then
|
|
|
eb238e |
NAME=${PREFIXDIR}${NAME}
|
|
|
eb238e |
fi
|
|
|
2ad5f6 |
|
|
|
eb238e |
shift 1
|
|
|
eb238e |
|
|
|
2ad5f6 |
|
|
|
eb238e |
|
|
|
eb238e |
shift 1
|
|
|
eb238e |
break
|
|
|
eb238e |
|
|
|
eb238e |
|
|
|
eb238e |
esac
|
|
|
2ad5f6 |
|
|
|
eb238e |
done
|
|
|
b1bcf2 |
|
|
|
eb238e |
|
|
|
b1bcf2 |
echo $NAME
|
|
|
4c79b5 |
|
|
|
4c79b5 |
}
|