Blame tcar-scripts/tcar_checkRepoDirSource.sh

Alain Reguera Delgado 66223d
#!/bin/bash
Alain Reguera Delgado 66223d
######################################################################
Alain Reguera Delgado 66223d
#
Alain Reguera Delgado 66223d
#   tcar_checkRepoDirSource.sh -- This function standardizes the path
Alain Reguera Delgado 66223d
#   construction of directories inside the working copy, using
Alain Reguera Delgado 66223d
#   absolute paths. This function transforms relative paths passed as
Alain Reguera Delgado 66223d
#   non-option arguments to tcar.sh script command-line into
Alain Reguera Delgado 66223d
#   absolute paths inside the working copy, based on whether you are
Alain Reguera Delgado 66223d
#   using Subversion or Git as version control system. Further
Alain Reguera Delgado 66223d
#   verifications, (e.g., whether they really exist as directories
Alain Reguera Delgado 66223d
#   inside the working copy or not) should be realized outside this
Alain Reguera Delgado 66223d
#   function.
Alain Reguera Delgado 66223d
#
Alain Reguera Delgado 66223d
#   Use this function whenever you want to be sure non-option
Alain Reguera Delgado 66223d
#   arguments passed to tcar.sh script command-line do always
Alain Reguera Delgado 66223d
#   point to directories inside the working copy.  Transforming
Alain Reguera Delgado 66223d
#   relative paths into absolute paths, before processing them, is
Alain Reguera Delgado 66223d
#   very useful when you need to execute the tcar.sh script as
Alain Reguera Delgado 66223d
#   command (e.g., `tcar') anywhere on your workstation.
Alain Reguera Delgado 66223d
#
Alain Reguera Delgado 66223d
#   Written by:
Alain Reguera Delgado 66223d
#   * Alain Reguera Delgado <al@centos.org.cu>, 2009-2013
Alain Reguera Delgado 66223d
#
Alain Reguera Delgado 66223d
# Copyright (C) 2009-2013 The CentOS Artwork SIG
Alain Reguera Delgado 66223d
#
Alain Reguera Delgado 66223d
# This program is free software; you can redistribute it and/or modify
Alain Reguera Delgado 66223d
# it under the terms of the GNU General Public License as published by
Alain Reguera Delgado 66223d
# the Free Software Foundation; either version 2 of the License, or (at
Alain Reguera Delgado 66223d
# your option) any later version.
Alain Reguera Delgado 66223d
#
Alain Reguera Delgado 66223d
# This program is distributed in the hope that it will be useful, but
Alain Reguera Delgado 66223d
# WITHOUT ANY WARRANTY; without even the implied warranty of
Alain Reguera Delgado 66223d
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Alain Reguera Delgado 66223d
# General Public License for more details.
Alain Reguera Delgado 66223d
#
Alain Reguera Delgado 66223d
# You should have received a copy of the GNU General Public License
Alain Reguera Delgado 66223d
# along with this program; if not, write to the Free Software
Alain Reguera Delgado 66223d
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Alain Reguera Delgado 66223d
#
Alain Reguera Delgado 66223d
######################################################################
Alain Reguera Delgado 66223d
Alain Reguera Delgado 66223d
function tcar_checkRepoDirSource {
Alain Reguera Delgado 66223d
Alain Reguera Delgado 66223d
    local LOCATION=${1}
Alain Reguera Delgado 66223d
Alain Reguera Delgado 66223d
    # Remove any dot from arguments passed to tcar.sh script.
Alain Reguera Delgado 66223d
    # This way it is possible to use a single dot to reflect the
Alain Reguera Delgado 66223d
    # current location from which tcar.sh was executed. Notice
Alain Reguera Delgado 66223d
    # that using a dot as argument is optional (e.g.: when you pass no
Alain Reguera Delgado 66223d
    # argument to tcar command-line, the current location is
Alain Reguera Delgado 66223d
    # used as default location). However, it might be useful to use a
Alain Reguera Delgado 66223d
    # dot as argument when you want to include the current location in
Alain Reguera Delgado 66223d
    # a list of arguments to process. Don't forget that dot slash can
Alain Reguera Delgado 66223d
    # be used to refer locations relatively.
Alain Reguera Delgado 66223d
    LOCATION=$(echo "${LOCATION}" | sed -r "s,^\.(/([[:alnum:]_/.-]+)?)?$,$(pwd)\1,g")
Alain Reguera Delgado 66223d
Alain Reguera Delgado 66223d
    # Remove the path to repository's base directory from location in
Alain Reguera Delgado 66223d
    # order to avoid path duplications here.
Alain Reguera Delgado 66223d
    LOCATION=$(echo "${LOCATION}" | sed "s,${TCAR_BASEDIR}/,,g")
Alain Reguera Delgado 66223d
Alain Reguera Delgado 66223d
    # When we use Git as version control system, there isn't a need of
Alain Reguera Delgado 66223d
    # using the `trunk', `branches', `tags' convention we were using
Alain Reguera Delgado 66223d
    # for Subversion.  The working copy begins directly with the
Alain Reguera Delgado 66223d
    # content of our repository (e.g., Documentation, Scripts,
Alain Reguera Delgado 66223d
    # Identity and Locales).
Alain Reguera Delgado 66223d
    #
Alain Reguera Delgado 66223d
    # When we use Subversion as version control system, we follow the
Alain Reguera Delgado 66223d
    # `trunk', `branches', `tags' convention to organize files inside
Alain Reguera Delgado 66223d
    # the repository and need to redefine the source path in order to
Alain Reguera Delgado 66223d
    # build the repository absolute path from the repository top level
Alain Reguera Delgado 66223d
    # on.  As convention, when you prepare your working copy through
Alain Reguera Delgado 66223d
    # tcar.sh script, the absolute path to the `trunk/'
Alain Reguera Delgado 66223d
    # directory is used as working copy. This is, path arguments
Alain Reguera Delgado 66223d
    # provided to tcar.sh script will be interpreted from trunk/
Alain Reguera Delgado 66223d
    # directory level on. For example, the following command should
Alain Reguera Delgado 66223d
    # work correctly in both Subversion and Git repositories:
Alain Reguera Delgado 66223d
    #
Alain Reguera Delgado 66223d
    #   tcar render Documentation/Manuals/Docbook/Tcar-ug
Alain Reguera Delgado 66223d
    #
Alain Reguera Delgado 66223d
    # There isn't a need of verifying the paths built here.  This is
Alain Reguera Delgado 66223d
    # something we do later, using the tcar_checkFiles function. We
Alain Reguera Delgado 66223d
    # don't do the file verification here to avoid malformed error
Alain Reguera Delgado 66223d
    # messages when we reassign variable values using this function as
Alain Reguera Delgado 66223d
    # reference (e.g., in order to prevent error messages from being
Alain Reguera Delgado 66223d
    # stored inside variables.).
Alain Reguera Delgado 66223d
    LOCATION=${TCAR_BASEDIR}/${LOCATION}
Alain Reguera Delgado 66223d
Alain Reguera Delgado 66223d
    # Remove trailing slashes passed as argument. The single slash
Alain Reguera Delgado 66223d
    # form is used to refer the repository's root directory. The
Alain Reguera Delgado 66223d
    # single slash form passed as argument of tcar.sh script is
Alain Reguera Delgado 66223d
    # useful to execute commands over the
Alain Reguera Delgado 66223d
    # entire repository tree.
Alain Reguera Delgado 66223d
    echo "${LOCATION}" | sed -r -e 's,/+,/,g' -e 's,/+$,,g'
Alain Reguera Delgado 66223d
Alain Reguera Delgado 66223d
}