Blame tcar-scripts/tcar_checkWorkDirSource.sh

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