Blame Automation/Modules/Locale/Modules/Directory/directory_getConfiguration.sh

Alain Reguera Delgado 52ee2e
#!/bin/bash
Alain Reguera Delgado 5f643d
######################################################################
Alain Reguera Delgado 5f643d
#
Alain Reguera Delgado 06ab0f
#   directory_getConfiguration.sh -- This function retrieves options
Alain Reguera Delgado 06ab0f
#   from configuration files and process them accordingly.
Alain Reguera Delgado 5f643d
#
Alain Reguera Delgado 5f643d
#   Written by:
Alain Reguera Delgado 5f643d
#   * Alain Reguera Delgado <al@centos.org.cu>, 2009-2013
Alain Reguera Delgado 5f643d
#
Alain Reguera Delgado bb076b
# Copyright (C) 2009-2013 The CentOS Artwork SIG
Alain Reguera Delgado 5f643d
#
Alain Reguera Delgado 5f643d
# This program is free software; you can redistribute it and/or modify
Alain Reguera Delgado 5f643d
# it under the terms of the GNU General Public License as published by
Alain Reguera Delgado bb076b
# the Free Software Foundation; either version 2 of the License, or (at
Alain Reguera Delgado bb076b
# your option) any later version.
Alain Reguera Delgado 5f643d
#
Alain Reguera Delgado 5f643d
# This program is distributed in the hope that it will be useful, but
Alain Reguera Delgado 5f643d
# WITHOUT ANY WARRANTY; without even the implied warranty of
Alain Reguera Delgado 5f643d
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Alain Reguera Delgado 5f643d
# General Public License for more details.
Alain Reguera Delgado 5f643d
#
Alain Reguera Delgado 5f643d
# You should have received a copy of the GNU General Public License
Alain Reguera Delgado 5f643d
# along with this program; if not, write to the Free Software
Alain Reguera Delgado 5f643d
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Alain Reguera Delgado 5f643d
#
Alain Reguera Delgado 5f643d
######################################################################
Alain Reguera Delgado 52ee2e
Alain Reguera Delgado bd3978
function directory_getConfiguration {
Alain Reguera Delgado 52ee2e
Alain Reguera Delgado 06ab0f
    local CONFIGURATION="${1}"
Alain Reguera Delgado 52ee2e
    local SECTION=''
Alain Reguera Delgado 52ee2e
    local -a SECTIONS
Alain Reguera Delgado 52ee2e
Alain Reguera Delgado 52ee2e
    # Define motif-specific environment variables, based on
Alain Reguera Delgado 52ee2e
    # configuration file path. These variables might save
Alain Reguera Delgado 52ee2e
    # configuration file writers from typing motif-specific
Alain Reguera Delgado 52ee2e
    # information when they produce motif-specific content. These
Alain Reguera Delgado 52ee2e
    # variables will be empty if the configuration file isn't inside
Alain Reguera Delgado 52ee2e
    # a motif-specific directory structure.
Alain Reguera Delgado 06ab0f
    local MOTIF=$(tcar_getPathComponent ${CONFIGURATION} --motif)
Alain Reguera Delgado 06ab0f
    local MOTIF_NAME=$(tcar_getPathComponent ${CONFIGURATION} --motif-name)
Alain Reguera Delgado 06ab0f
    local MOTIF_VERSION=$(tcar_getPathComponent ${CONFIGURATION} --motif-version)
Alain Reguera Delgado 52ee2e
Alain Reguera Delgado 52ee2e
    # Use arrays to store section names. This make possible to make
Alain Reguera Delgado 52ee2e
    # use of post-rendition and last-rendition concepts. Otherwise it
Alain Reguera Delgado 52ee2e
    # would be difficult to predict information about sections inside
Alain Reguera Delgado 52ee2e
    # deeper environments.
Alain Reguera Delgado 52ee2e
    for SECTION in $(tcar_getConfigSectionNames "${CONFIGURATION}" \
Alain Reguera Delgado 52ee2e
        | egrep ${TCAR_FLAG_FILTER});do
Alain Reguera Delgado 06ab0f
        SECTIONS[++${#SECTIONS[*]}]="${SECTION}"
Alain Reguera Delgado 52ee2e
    done
Alain Reguera Delgado 52ee2e
Alain Reguera Delgado 52ee2e
    local COUNTER=0
Alain Reguera Delgado 52ee2e
Alain Reguera Delgado 52ee2e
    while [[ ${COUNTER} -lt ${#SECTIONS[*]} ]];do
Alain Reguera Delgado 52ee2e
Alain Reguera Delgado 52ee2e
        # Initialize array variables locally.
Alain Reguera Delgado 52ee2e
        local -a TRANSLATIONS
Alain Reguera Delgado 52ee2e
        local -a SOURCES
Alain Reguera Delgado 06ab0f
        local SOURCE=''
Alain Reguera Delgado 06ab0f
Alain Reguera Delgado 52ee2e
        local SECTION=${SECTIONS[${COUNTER}]}
Alain Reguera Delgado 52ee2e
Alain Reguera Delgado 52ee2e
        local RENDER_FROM=$(tcar_getConfigValue "${CONFIGURATION}" "${SECTION}" "render-from")
Alain Reguera Delgado 52ee2e
        for SOURCE in ${RENDER_FROM};do
Alain Reguera Delgado 52ee2e
            if [[ ${SOURCE} =~ "^/" ]];then
Alain Reguera Delgado 06ab0f
                SOURCES[++${#SOURCES[*]}]=${SOURCE}
Alain Reguera Delgado 52ee2e
            else
Alain Reguera Delgado 06ab0f
                SOURCES[++${#SOURCES[*]}]=$(dirname ${CONFIGURATION})/${SOURCE}
Alain Reguera Delgado 52ee2e
            fi
Alain Reguera Delgado 52ee2e
        done
Alain Reguera Delgado 786ac0
        
Alain Reguera Delgado 6a1e04
        local RENDER_TYPE=$(tcar_getConfigValue "${CONFIGURATION}" "${SECTION}" "render-type")
Alain Reguera Delgado 52ee2e
        if [[ -z ${RENDER_TYPE} ]];then
Alain Reguera Delgado 52ee2e
           RENDER_TYPE=$(echo ${SOURCES[0]} | sed -r 's/.+\.([[:alpha:]]+)$/\1/') 
Alain Reguera Delgado 52ee2e
        fi
Alain Reguera Delgado 52ee2e
Alain Reguera Delgado 52ee2e
        local LOCALE_FROM=$(tcar_getConfigValue "${CONFIGURATION}" "${SECTION}" "locale-from")
Alain Reguera Delgado 52ee2e
        for TRANSLATION in ${LOCALE_FROM};do
Alain Reguera Delgado 52ee2e
            if [[ ${TRANSLATION} =~ "^/" ]];then
Alain Reguera Delgado 06ab0f
                TRANSLATIONS[++${#TRANSLATIONS[*]}]=${TRANSLATION}
Alain Reguera Delgado 52ee2e
            else
Alain Reguera Delgado 06ab0f
                TRANSLATIONS[++${#TRANSLATIONS[*]}]=$(dirname ${CONFIGURATION})/${TRANSLATION}
Alain Reguera Delgado 52ee2e
            fi
Alain Reguera Delgado 52ee2e
        done
Alain Reguera Delgado 52ee2e
Alain Reguera Delgado 06ab0f
        local RENDER_FLOW=$(tcar_getConfigValue "${CONFIGURATION}" "${SECTION}" "render-flow")
Alain Reguera Delgado 6a1e04
        if [[ -z ${RENDER_FLOW} ]];then
Alain Reguera Delgado 6a1e04
            RENDER_FLOW='article'
Alain Reguera Delgado 6a1e04
        fi
Alain Reguera Delgado 6a1e04
Alain Reguera Delgado 06ab0f
        local PO_FILE=${TRANSLATIONS[0]}
Alain Reguera Delgado 786ac0
Alain Reguera Delgado 163b4d
        # Define package name. This is the name of the initialization
Alain Reguera Delgado 163b4d
        # file you provided as argument to the command line to provide
Alain Reguera Delgado 163b4d
        # localization for.
Alain Reguera Delgado 163b4d
        local PACKAGE_NAME=$(basename ${RENDER_FROM})
Alain Reguera Delgado 163b4d
Alain Reguera Delgado 163b4d
        # Define package version. The script version is used here.
Alain Reguera Delgado 163b4d
        # Modules doesn't have a version by now. They share the same
Alain Reguera Delgado 163b4d
        # version of the centos-art.sh script.
Alain Reguera Delgado 163b4d
        local PACKAGE_VERSION=${TCAR_SCRIPT_VERSION}
Alain Reguera Delgado 163b4d
Alain Reguera Delgado bd3978
        # Initialize locale's actions module.
Alain Reguera Delgado 06ab0f
        tcar_setModuleEnvironment -m "actions" -t "sib-module"
Alain Reguera Delgado 52ee2e
Alain Reguera Delgado 52ee2e
        # Increment section's counter.
Alain Reguera Delgado 52ee2e
        COUNTER=$(( ${COUNTER} + 1 ))
Alain Reguera Delgado 52ee2e
Alain Reguera Delgado 06ab0f
        # Reset array variables to prevent section-specific
Alain Reguera Delgado 06ab0f
        # information from being concatenated to other sections.
Alain Reguera Delgado 52ee2e
        unset SOURCES
Alain Reguera Delgado 06ab0f
        unset TRANSLATIONS
Alain Reguera Delgado 52ee2e
Alain Reguera Delgado 52ee2e
    done
Alain Reguera Delgado 52ee2e
Alain Reguera Delgado 52ee2e
    # Reset array variables and their counters to avoid undesired
Alain Reguera Delgado 52ee2e
    # concatenations between configuration files.
Alain Reguera Delgado 52ee2e
    unset COUNTER
Alain Reguera Delgado 52ee2e
    unset SECTIONS
Alain Reguera Delgado 52ee2e
Alain Reguera Delgado 52ee2e
}