Blame tcar-scripts/tcar_checkRepoDirSource.sh

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