Blame tcar-scripts-render/modules/Files/files.sh

Alain Reguera Delgado 2c7b25
#!/bin/bash
Alain Reguera Delgado 2c7b25
######################################################################
Alain Reguera Delgado 2c7b25
#
Alain Reguera Delgado 2c7b25
#   files.sh -- This module initializes processing of configuration
Alain Reguera Delgado 2c7b25
#   files when the argument passed in the command-line points to a
Alain Reguera Delgado 2c7b25
#   regular file or symbolic link.
Alain Reguera Delgado 2c7b25
#
Alain Reguera Delgado 2c7b25
#   Written by:
Alain Reguera Delgado 2c7b25
#   * Alain Reguera Delgado <al@centos.org.cu>, 2009-2013
Alain Reguera Delgado 2c7b25
#
Alain Reguera Delgado 2c7b25
# Copyright (C) 2009-2013 The CentOS Artwork SIG
Alain Reguera Delgado 2c7b25
#
Alain Reguera Delgado 2c7b25
# This program is free software; you can redistribute it and/or modify
Alain Reguera Delgado 2c7b25
# it under the terms of the GNU General Public License as published by
Alain Reguera Delgado 2c7b25
# the Free Software Foundation; either version 2 of the License, or (at
Alain Reguera Delgado 2c7b25
# your option) any later version.
Alain Reguera Delgado 2c7b25
#
Alain Reguera Delgado 2c7b25
# This program is distributed in the hope that it will be useful, but
Alain Reguera Delgado 2c7b25
# WITHOUT ANY WARRANTY; without even the implied warranty of
Alain Reguera Delgado 2c7b25
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Alain Reguera Delgado 2c7b25
# General Public License for more details.
Alain Reguera Delgado 2c7b25
#
Alain Reguera Delgado 2c7b25
# You should have received a copy of the GNU General Public License
Alain Reguera Delgado 2c7b25
# along with this program; if not, write to the Free Software
Alain Reguera Delgado 2c7b25
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Alain Reguera Delgado 2c7b25
#
Alain Reguera Delgado 2c7b25
######################################################################
Alain Reguera Delgado 2c7b25
Alain Reguera Delgado 2c7b25
function files {
Alain Reguera Delgado 2c7b25
Alain Reguera Delgado 2c7b25
    local CONFIGURATION=$(tcar_checkRepoDirSource "${1}")
Alain Reguera Delgado 2c7b25
Alain Reguera Delgado 2c7b25
    local -a SECTIONS
Alain Reguera Delgado 2c7b25
    local SECTION=''
Alain Reguera Delgado 2c7b25
Alain Reguera Delgado 2c7b25
    # Define motif-specific environment variables, based on
Alain Reguera Delgado 2c7b25
    # configuration file path. These variables might save
Alain Reguera Delgado 2c7b25
    # configuration file writers from typing motif-specific
Alain Reguera Delgado 2c7b25
    # information when they produce motif-specific content. These
Alain Reguera Delgado 2c7b25
    # variables will be empty if the configuration file isn't inside
Alain Reguera Delgado 2c7b25
    # a motif-specific directory structure.
Alain Reguera Delgado 2c7b25
    local MOTIF=$(tcar_getPathComponent ${CONFIGURATION} --motif)
Alain Reguera Delgado 2c7b25
    local MOTIF_NAME=$(tcar_getPathComponent ${CONFIGURATION} --motif-name)
Alain Reguera Delgado 2c7b25
    local MOTIF_VERSION=$(tcar_getPathComponent ${CONFIGURATION} --motif-version)
Alain Reguera Delgado 2c7b25
Alain Reguera Delgado 2c7b25
    # Use arrays to store section names. This make possible to make
Alain Reguera Delgado 2c7b25
    # use of post-rendition and last-rendition concepts. Otherwise it
Alain Reguera Delgado 2c7b25
    # would be difficult to predict information about sections inside
Alain Reguera Delgado 2c7b25
    # deeper environments.
Alain Reguera Delgado 2c7b25
    for SECTION in $(tcar_getConfigSectionNames "${CONFIGURATION}" \
Alain Reguera Delgado 2c7b25
        | egrep ${TCAR_FLAG_FILTER});do
Alain Reguera Delgado 2c7b25
        SECTIONS[++${#SECTIONS[*]}]="${SECTION}"
Alain Reguera Delgado 2c7b25
    done
Alain Reguera Delgado 2c7b25
Alain Reguera Delgado 2c7b25
    # Verify the configuration file has one section entry at least.
Alain Reguera Delgado 2c7b25
    if [[ ${#SECTIONS[*]} -eq 0 ]];then
Alain Reguera Delgado 2c7b25
        tcar_printMessage "`eval_gettext "No section definition was found in \\\$CONFIGURATION."`" --as-error-line
Alain Reguera Delgado 2c7b25
    fi
Alain Reguera Delgado 2c7b25
Alain Reguera Delgado 2c7b25
    local COUNTER=0
Alain Reguera Delgado 2c7b25
Alain Reguera Delgado 2c7b25
    while [[ ${COUNTER} -lt ${#SECTIONS[*]} ]];do
Alain Reguera Delgado 2c7b25
Alain Reguera Delgado 2c7b25
        # Initialize array variables locally.
Alain Reguera Delgado 2c7b25
        local -a TRANSLATIONS
Alain Reguera Delgado 2c7b25
        local -a SOURCES
Alain Reguera Delgado 2c7b25
  
Alain Reguera Delgado 2c7b25
        SECTION=${SECTIONS[${COUNTER}]}
Alain Reguera Delgado 2c7b25
Alain Reguera Delgado 2c7b25
        if [[ ${SECTION} =~ "^/" ]];then
Alain Reguera Delgado 2c7b25
            RENDER_TARGET=${SECTION}
Alain Reguera Delgado 2c7b25
        else
Alain Reguera Delgado 2c7b25
            RENDER_TARGET=$(dirname ${CONFIGURATION})/Final/${TCAR_SCRIPT_LANG_LC}/${SECTION}
Alain Reguera Delgado 2c7b25
        fi
Alain Reguera Delgado 2c7b25
Alain Reguera Delgado 2c7b25
        RENDER_TYPE=$(tcar_getConfigValue "${CONFIGURATION}" "${SECTION}" "render-type")
Alain Reguera Delgado 2c7b25
        if [[ -z ${RENDER_TYPE} ]];then
Alain Reguera Delgado 2c7b25
            tcar_printMessage "${CONFIGURATION} `gettext "hasn't render-type set in."`" --as-error-line
Alain Reguera Delgado 2c7b25
        fi
Alain Reguera Delgado 2c7b25
Alain Reguera Delgado 2c7b25
        RENDER_FROM=$(tcar_getConfigValue "${CONFIGURATION}" "${SECTION}" "render-from")
Alain Reguera Delgado 2c7b25
        if [[ -z ${RENDER_TYPE} ]];then
Alain Reguera Delgado 2c7b25
            tcar_printMessage "${CONFIGURATION} `gettext "hasn't render-from set in."`" --as-error-line
Alain Reguera Delgado 2c7b25
        fi
Alain Reguera Delgado 2c7b25
Alain Reguera Delgado 2c7b25
        for SOURCE in ${RENDER_FROM};do
Alain Reguera Delgado 2c7b25
            if [[ ${SOURCE} =~ "^/" ]];then
Alain Reguera Delgado 2c7b25
                SOURCES[++${#SOURCES[*]}]=${SOURCE}
Alain Reguera Delgado 2c7b25
            else
Alain Reguera Delgado 2c7b25
                SOURCES[++${#SOURCES[*]}]=$(dirname ${CONFIGURATION})/${SOURCE}
Alain Reguera Delgado 2c7b25
            fi
Alain Reguera Delgado 2c7b25
        done
Alain Reguera Delgado 2c7b25
Alain Reguera Delgado 2c7b25
        if [[ -z ${RENDER_TYPE} ]];then
Alain Reguera Delgado 2c7b25
           RENDER_TYPE=$(echo ${SOURCES[0]} | sed -r 's/.+\.([[:alpha:]]+)$/\1/') 
Alain Reguera Delgado 2c7b25
        fi
Alain Reguera Delgado 2c7b25
Alain Reguera Delgado 2c7b25
        LOCALE_FROM=$(tcar_getConfigValue "${CONFIGURATION}" "${SECTION}" "locale-from")
Alain Reguera Delgado 2c7b25
        if [[ -z ${LOCALE_FROM} ]] || [[ ${LOCALE_FROM} == 'no-locale' ]] ;then
Alain Reguera Delgado 2c7b25
            RENDER_FLAG_NO_LOCALE='true'
Alain Reguera Delgado 2c7b25
            RENDER_TARGET=$(echo ${RENDER_TARGET} | sed "s,${TCAR_SCRIPT_LANG_LC}/,,")
Alain Reguera Delgado 2c7b25
        else
Alain Reguera Delgado 2c7b25
            for TRANSLATION in ${LOCALE_FROM};do
Alain Reguera Delgado 2c7b25
                if [[ ${TRANSLATION} =~ "^/" ]];then
Alain Reguera Delgado 2c7b25
                    TRANSLATIONS[++${#TRANSLATIONS[*]}]=${TRANSLATION}
Alain Reguera Delgado 2c7b25
                else
Alain Reguera Delgado 2c7b25
                    TRANSLATIONS[++${#TRANSLATIONS[*]}]=$(dirname ${CONFIGURATION})/${TRANSLATION}
Alain Reguera Delgado 2c7b25
                fi
Alain Reguera Delgado 2c7b25
            done
Alain Reguera Delgado 2c7b25
        fi
Alain Reguera Delgado 2c7b25
Alain Reguera Delgado 2c7b25
        # Execute module for processing type-specific files.
Alain Reguera Delgado 2c7b25
        tcar_setModuleEnvironment -m "${RENDER_TYPE}" -t "child"
Alain Reguera Delgado 2c7b25
Alain Reguera Delgado 2c7b25
        # Increment section's counter.
Alain Reguera Delgado 2c7b25
        COUNTER=$(( ${COUNTER} + 1 ))
Alain Reguera Delgado 2c7b25
Alain Reguera Delgado 2c7b25
        # Reset array variable to avoid undesired concatenations
Alain Reguera Delgado 2c7b25
        # between sections blocks.
Alain Reguera Delgado 2c7b25
        unset TRANSLATIONS
Alain Reguera Delgado 2c7b25
        unset SOURCES
Alain Reguera Delgado 2c7b25
Alain Reguera Delgado 2c7b25
    done
Alain Reguera Delgado 2c7b25
Alain Reguera Delgado 2c7b25
    # Reset array variables and their counters to avoid undesired
Alain Reguera Delgado 2c7b25
    # concatenations between configuration files.
Alain Reguera Delgado 2c7b25
    unset COUNTER
Alain Reguera Delgado 2c7b25
    unset SECTIONS
Alain Reguera Delgado 2c7b25
Alain Reguera Delgado 2c7b25
    # Tuneup final files.
Alain Reguera Delgado 2c7b25
    tcar_setModuleEnvironment -m 'tuneup' -t 'parent' -g $(dirname ${RENDER_TARGET})
Alain Reguera Delgado 2c7b25
Alain Reguera Delgado 2c7b25
}