Blame Scripts/Bash/Functions/Prepare/prepare_updateDirectoryStructure.sh

Alain Reguera Delgado 64aead
#!/bin/bash
Alain Reguera Delgado 64aead
#
Alain Reguera Delgado 64aead
# prepare_updateDirectoryStructure.sh -- This function standardizes
Alain Reguera Delgado 64aead
# the relation between source directory structures and target
Alain Reguera Delgado 64aead
# directory structures inside the repository. This function takes
Alain Reguera Delgado 64aead
# source and target paths as arguments, analyses them and builds the
Alain Reguera Delgado 64aead
# target directory structure based on source directory structure. This
Alain Reguera Delgado 64aead
# function must be executed before executing production functions like
Alain Reguera Delgado 64aead
# render.
Alain Reguera Delgado 64aead
#
Alain Reguera Delgado 64aead
# In order for this verification to work, all source directory
Alain Reguera Delgado 64aead
# structures provided must be organized using one directory level more
Alain Reguera Delgado 64aead
# than its related target directory. The purpose of this directory is
Alain Reguera Delgado 64aead
# content categorization. For example, consider the following path:
Alain Reguera Delgado 64aead
#
Alain Reguera Delgado 64aead
#   ---------------++++++++++++++++++++++++
Alain Reguera Delgado 64aead
#   ${SOURCE_PATH}/${CATEGORY}/${COMPONENT}
Alain Reguera Delgado 64aead
#   ---------------++++++++++++++++++++++++
Alain Reguera Delgado 64aead
#   ++++++++++++++++++++++++++++++++++------------
Alain Reguera Delgado 64aead
#   ${TARGET_PATH}/${NAME}/${VERSION}/${COMPONENT}
Alain Reguera Delgado 64aead
#   ++++++++++++++++++++++++++++++++++------------
Alain Reguera Delgado 64aead
#
Alain Reguera Delgado 64aead
# So we end with the following path:
Alain Reguera Delgado 64aead
#
Alain Reguera Delgado 64aead
#   ${TARGET_PATH}/${CATEGORY}/${COMPONENT}
Alain Reguera Delgado 64aead
# 
Alain Reguera Delgado 64aead
# In this path, ${CATEGORY} makes reference to a categorization
Alain Reguera Delgado 64aead
# directory used to describe source components related to target
Alain Reguera Delgado 64aead
# components. However, in the target side, such ${CATEGORY} directory
Alain Reguera Delgado 64aead
# is not needed and should be removed from it in order to get the
Alain Reguera Delgado 64aead
# final target path, which is:  
Alain Reguera Delgado 64aead
#
Alain Reguera Delgado 64aead
#   ${TARGET_PATH}/${COMPONENT}
Alain Reguera Delgado 64aead
#
Alain Reguera Delgado 64aead
# ${CATEGORY} is always a one-level directory, but ${COMPONENT} might
Alain Reguera Delgado 64aead
# have several levels deep.
Alain Reguera Delgado 64aead
#
Alain Reguera Delgado 64aead
# Copyright (C) 2009-2013 The CentOS Project
Alain Reguera Delgado 64aead
#
Alain Reguera Delgado 64aead
# This program is free software; you can redistribute it and/or modify
Alain Reguera Delgado 64aead
# it under the terms of the GNU General Public License as published by
Alain Reguera Delgado 64aead
# the Free Software Foundation; either version 2 of the License, or (at
Alain Reguera Delgado 64aead
# your option) any later version.
Alain Reguera Delgado 64aead
#
Alain Reguera Delgado 64aead
# This program is distributed in the hope that it will be useful, but
Alain Reguera Delgado 64aead
# WITHOUT ANY WARRANTY; without even the implied warranty of
Alain Reguera Delgado 64aead
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Alain Reguera Delgado 64aead
# General Public License for more details.
Alain Reguera Delgado 64aead
#
Alain Reguera Delgado 64aead
# You should have received a copy of the GNU General Public License
Alain Reguera Delgado 64aead
# along with this program; if not, write to the Free Software
Alain Reguera Delgado 64aead
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Alain Reguera Delgado 64aead
#
Alain Reguera Delgado 64aead
# ----------------------------------------------------------------------
Alain Reguera Delgado 64aead
# $Id$
Alain Reguera Delgado 64aead
# ----------------------------------------------------------------------
Alain Reguera Delgado 64aead
Alain Reguera Delgado 64aead
function prepare_updateDirectoryStructure {
Alain Reguera Delgado 64aead
Alain Reguera Delgado 64aead
    # Define absolute path to design models' directory structure. This
Alain Reguera Delgado 64aead
    # directory contains the directory structure you want to verify
Alain Reguera Delgado 64aead
    # inside target path.
Alain Reguera Delgado 64aead
    local SOURCE_PATH=$(cli_checkRepoDirSource "${1}")
Alain Reguera Delgado 64aead
Alain Reguera Delgado 64aead
    # Verify existence source path, just to be sure it was passed and
Alain Reguera Delgado 64aead
    # it is a valid directory.
Alain Reguera Delgado 64aead
    cli_checkFiles ${SOURCE_PATH} -d
Alain Reguera Delgado 64aead
Alain Reguera Delgado 64aead
    # Define absolute path to directory inside the repository where
Alain Reguera Delgado 64aead
    # you want to replicate the source path directory structure.
Alain Reguera Delgado 64aead
    local TARGET_PATH=$(cli_checkRepoDirSource "${2}")
Alain Reguera Delgado 64aead
Alain Reguera Delgado 64aead
    # NOTE: It is possible that target path doesn't exist. So verify
Alain Reguera Delgado 64aead
    # the relation between target and source path. If there is a
Alain Reguera Delgado 64aead
    # source path for the target, create an empty directory as target,
Alain Reguera Delgado 64aead
    # using the related source directory as reference.
Alain Reguera Delgado 64aead
Alain Reguera Delgado 64aead
    # Define list of directories inside source path.
Alain Reguera Delgado 64aead
    local SOURCE_DIRS=$(cli_getFilesList ${SOURCE_PATH} \
Alain Reguera Delgado 64aead
        --pattern='.+/[[:alpha:]]+$' --type=d)
Alain Reguera Delgado 64aead
Alain Reguera Delgado 64aead
    # Iterate through directories inside source path and verify
Alain Reguera Delgado 64aead
    # whether or not they exist in the target path. If they don't
Alain Reguera Delgado 64aead
    # exist create them.
Alain Reguera Delgado 64aead
    for SOURCE_DIR in ${SOURCE_DIRS};do
Alain Reguera Delgado 64aead
Alain Reguera Delgado 64aead
        local SOURCE_DIR_BASENAME=$(echo ${SOURCE_DIR} \
Alain Reguera Delgado 64aead
            | sed -r "s,${SOURCE_PATH}/,,")
Alain Reguera Delgado 64aead
Alain Reguera Delgado 64aead
        local TARGET_DIR=${TARGET_PATH}/${SOURCE_DIR_BASENAME}
Alain Reguera Delgado 64aead
Alain Reguera Delgado 64aead
        if [[ ${SOURCE_DIR} == ${SOURCE_DIR_BASENAME} ]];then
Alain Reguera Delgado 64aead
            continue
Alain Reguera Delgado 64aead
        fi
Alain Reguera Delgado 64aead
Alain Reguera Delgado 64aead
        # Keep this for debugging ;)
Alain Reguera Delgado 64aead
        #echo '---'
Alain Reguera Delgado 64aead
        #echo $SOURCE_DIR_BASENAME;
Alain Reguera Delgado 64aead
        #echo $SOURCE_DIR;
Alain Reguera Delgado 64aead
        #echo $TARGET_DIR;
Alain Reguera Delgado 64aead
        #echo $TARGET_PATH;
Alain Reguera Delgado 64aead
        #echo '---'
Alain Reguera Delgado 64aead
        #continue
Alain Reguera Delgado 64aead
Alain Reguera Delgado 64aead
        if [[ ! -d ${TARGET_DIR} ]];then
Alain Reguera Delgado 64aead
            mkdir -p ${TARGET_DIR}
Alain Reguera Delgado 64aead
        fi
Alain Reguera Delgado 64aead
Alain Reguera Delgado 64aead
    done
Alain Reguera Delgado 64aead
Alain Reguera Delgado 64aead
}