Blame Automation/Scripts/tcar_checkRepoDirSource.sh

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