Blame Automation/Modules/Prepare/Scripts/prepare_setDirStructure.sh

Alain Reguera Delgado 8f60cb
#!/bin/bash
Alain Reguera Delgado d26212
######################################################################
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado db88f2
#   prepare_setDirStructure.sh -- This function standardizes the
Alain Reguera Delgado db88f2
#   relation between source and target directory structures inside the
Alain Reguera Delgado db88f2
#   repository.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado db88f2
#   This function takes two arguments. The first is the source
Alain Reguera Delgado db88f2
#   directory and the second is the target directory where you wan to
Alain Reguera Delgado db88f2
#   reproduce the source directory structure.  In order for this to
Alain Reguera Delgado db88f2
#   work, all source directory structures provided to this function
Alain Reguera Delgado db88f2
#   must have one level of directories more than its related target
Alain Reguera Delgado db88f2
#   directory.  The purpose of this level is content categorization.
Alain Reguera Delgado db88f2
#   For example, consider the following path:
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado db88f2
#       ----------++++++++++++++++++++++++
Alain Reguera Delgado db88f2
#       ${SOURCE}/${CATEGORY}/${COMPONENT}
Alain Reguera Delgado db88f2
#       ----------++++++++++++++++++++++++
Alain Reguera Delgado db88f2
#       +++++++++++++++++++++++++++++------------
Alain Reguera Delgado db88f2
#       ${TARGET}/${NAME}/${VERSION}/${COMPONENT}
Alain Reguera Delgado db88f2
#       +++++++++++++++++++++++++++++------------
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado d26212
#   So we end with the following path:
Alain Reguera Delgado d26212
#
Alain Reguera Delgado db88f2
#       ${TARGET}/${CATEGORY}/${COMPONENT}
Alain Reguera Delgado 8f60cb
# 
Alain Reguera Delgado d26212
#   In this path, ${CATEGORY} makes reference to a categorization
Alain Reguera Delgado d26212
#   directory used to describe source components related to target
Alain Reguera Delgado d26212
#   components. However, in the target side, such ${CATEGORY}
Alain Reguera Delgado d26212
#   directory is not needed and should be removed from it in order to
Alain Reguera Delgado d26212
#   get the final target path, which is:  
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado db88f2
#       ${TARGET}/${COMPONENT}
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado d26212
#   ${CATEGORY} is always a one-level directory, but ${COMPONENT}
Alain Reguera Delgado db88f2
#   might have several levels deep inside.
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 d26212
######################################################################
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado d26212
function prepare_setDirStructure {
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define absolute path to design models' directory structure. This
Alain Reguera Delgado 8f60cb
    # directory contains the directory structure you want to verify
Alain Reguera Delgado 8f60cb
    # inside target path.
Alain Reguera Delgado db88f2
    local SOURCE_DIRECTORY=$(tcar_checkRepoDirSource "${1}")
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Verify existence source path, just to be sure it was passed and
Alain Reguera Delgado 8f60cb
    # it is a valid directory.
Alain Reguera Delgado db88f2
    tcar_checkFiles ${SOURCE_DIR} -d
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define absolute path to directory inside the repository where
Alain Reguera Delgado 8f60cb
    # you want to replicate the source path directory structure.
Alain Reguera Delgado db88f2
    local TARGET_DIRECTORY=$(tcar_checkRepoDirSource "${2}")
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # NOTE: It is possible that target path doesn't exist. So verify
Alain Reguera Delgado 8f60cb
    # the relation between target and source path. If there is a
Alain Reguera Delgado 8f60cb
    # source path for the target, create an empty directory as target,
Alain Reguera Delgado 8f60cb
    # using the related source directory as reference.
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define list of directories inside source path.
Alain Reguera Delgado db88f2
    local DIRECTORIES=$(tcar_getFilesList ${SOURCE_DIRECTORY} \
Alain Reguera Delgado db88f2
        --pattern='.+/[[:alpha:]]+$' --type='d')
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Iterate through directories inside source path and verify
Alain Reguera Delgado 8f60cb
    # whether or not they exist in the target path. If they don't
Alain Reguera Delgado 8f60cb
    # exist create them.
Alain Reguera Delgado db88f2
    for DIRECTORY in ${DIRECTORIES};do
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado db88f2
        local DIRECTORY_BASENAME=$(echo ${DIRECTORY} \
Alain Reguera Delgado db88f2
            | sed -r "s,${SOURCE_DIRECTORY}/,,")
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado db88f2
        if [[ ${DIRECTORY} == ${DIRECTORY_BASENAME} ]];then
Alain Reguera Delgado 8f60cb
            continue
Alain Reguera Delgado 8f60cb
        fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado db88f2
        local DIRECTORY_TARGET=${TARGET_DIRECTORY}/${DIRECTORY_BASENAME}
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado db88f2
        if [[ ! -d ${DIRECTORY_TARGET} ]];then
Alain Reguera Delgado db88f2
            mkdir -p ${DIRECTORY_TARGET}
Alain Reguera Delgado 8f60cb
        fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    done
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
}