Blame Automation/centos-art.sh-mods/Prepare/prepare_updateDirectoryStructure.sh

Alain Reguera Delgado 8f60cb
#!/bin/bash
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# prepare_updateDirectoryStructure.sh -- This function standardizes
Alain Reguera Delgado 8f60cb
# the relation between source directory structures and target
Alain Reguera Delgado 8f60cb
# directory structures inside the repository. This function takes
Alain Reguera Delgado 8f60cb
# source and target paths as arguments, analyses them and builds the
Alain Reguera Delgado 8f60cb
# target directory structure based on source directory structure. This
Alain Reguera Delgado 8f60cb
# function must be executed before executing production functions like
Alain Reguera Delgado 8f60cb
# render.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# In order for this verification to work, all source directory
Alain Reguera Delgado 8f60cb
# structures provided must be organized using one directory level more
Alain Reguera Delgado 8f60cb
# than its related target directory. The purpose of this directory is
Alain Reguera Delgado 8f60cb
# content categorization. For example, consider the following path:
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
#   ---------------++++++++++++++++++++++++
Alain Reguera Delgado 8f60cb
#   ${SOURCE_PATH}/${CATEGORY}/${COMPONENT}
Alain Reguera Delgado 8f60cb
#   ---------------++++++++++++++++++++++++
Alain Reguera Delgado 8f60cb
#   ++++++++++++++++++++++++++++++++++------------
Alain Reguera Delgado 8f60cb
#   ${TARGET_PATH}/${NAME}/${VERSION}/${COMPONENT}
Alain Reguera Delgado 8f60cb
#   ++++++++++++++++++++++++++++++++++------------
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# So we end with the following path:
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
#   ${TARGET_PATH}/${CATEGORY}/${COMPONENT}
Alain Reguera Delgado 8f60cb
# 
Alain Reguera Delgado 8f60cb
# In this path, ${CATEGORY} makes reference to a categorization
Alain Reguera Delgado 8f60cb
# directory used to describe source components related to target
Alain Reguera Delgado 8f60cb
# components. However, in the target side, such ${CATEGORY} directory
Alain Reguera Delgado 8f60cb
# is not needed and should be removed from it in order to get the
Alain Reguera Delgado 8f60cb
# final target path, which is:  
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
#   ${TARGET_PATH}/${COMPONENT}
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# ${CATEGORY} is always a one-level directory, but ${COMPONENT} might
Alain Reguera Delgado 8f60cb
# have several levels deep.
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 8f60cb
# ----------------------------------------------------------------------
Alain Reguera Delgado 8f60cb
# $Id$
Alain Reguera Delgado 8f60cb
# ----------------------------------------------------------------------
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
function prepare_updateDirectoryStructure {
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 8f60cb
    local SOURCE_PATH=$(cli_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 8f60cb
    cli_checkFiles ${SOURCE_PATH} -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 8f60cb
    local TARGET_PATH=$(cli_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 8f60cb
    local SOURCE_DIRS=$(cli_getFilesList ${SOURCE_PATH} \
Alain Reguera Delgado 8f60cb
        --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 8f60cb
    for SOURCE_DIR in ${SOURCE_DIRS};do
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        local SOURCE_DIR_BASENAME=$(echo ${SOURCE_DIR} \
Alain Reguera Delgado 8f60cb
            | sed -r "s,${SOURCE_PATH}/,,")
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        local TARGET_DIR=${TARGET_PATH}/${SOURCE_DIR_BASENAME}
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        if [[ ${SOURCE_DIR} == ${SOURCE_DIR_BASENAME} ]];then
Alain Reguera Delgado 8f60cb
            continue
Alain Reguera Delgado 8f60cb
        fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Keep this for debugging ;)
Alain Reguera Delgado 8f60cb
        #echo '---'
Alain Reguera Delgado 8f60cb
        #echo $SOURCE_DIR_BASENAME;
Alain Reguera Delgado 8f60cb
        #echo $SOURCE_DIR;
Alain Reguera Delgado 8f60cb
        #echo $TARGET_DIR;
Alain Reguera Delgado 8f60cb
        #echo $TARGET_PATH;
Alain Reguera Delgado 8f60cb
        #echo '---'
Alain Reguera Delgado 8f60cb
        #continue
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        if [[ ! -d ${TARGET_DIR} ]];then
Alain Reguera Delgado 8f60cb
            mkdir -p ${TARGET_DIR}
Alain Reguera Delgado 8f60cb
        fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    done
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
}