Blame Scripts/Modules/Locale/Modules/Files/Modules/Update/Modules/Conf/conf.sh

Alain Reguera Delgado f23b0d
#!/bin/bash
Alain Reguera Delgado f23b0d
######################################################################
Alain Reguera Delgado f23b0d
#
Alain Reguera Delgado c0ca71
#   tcar - The CentOS Artwork Repository automation tool.
Alain Reguera Delgado c0ca71
#   Copyright © 2014 The CentOS Artwork SIG
Alain Reguera Delgado f23b0d
#
Alain Reguera Delgado c0ca71
#   This program is free software; you can redistribute it and/or
Alain Reguera Delgado c0ca71
#   modify it under the terms of the GNU General Public License as
Alain Reguera Delgado c0ca71
#   published by the Free Software Foundation; either version 2 of the
Alain Reguera Delgado c0ca71
#   License, or (at your option) any later version.
Alain Reguera Delgado f23b0d
#
Alain Reguera Delgado c0ca71
#   This program is distributed in the hope that it will be useful,
Alain Reguera Delgado c0ca71
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
Alain Reguera Delgado c0ca71
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Alain Reguera Delgado c0ca71
#   General Public License for more details.
Alain Reguera Delgado f23b0d
#
Alain Reguera Delgado c0ca71
#   You should have received a copy of the GNU General Public License
Alain Reguera Delgado c0ca71
#   along with this program; if not, write to the Free Software
Alain Reguera Delgado c0ca71
#   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Alain Reguera Delgado f23b0d
#
Alain Reguera Delgado c0ca71
#   Alain Reguera Delgado <al@centos.org.cu>
Alain Reguera Delgado c0ca71
#   39 Street No. 4426 Cienfuegos, Cuba.
Alain Reguera Delgado f23b0d
#
Alain Reguera Delgado f23b0d
######################################################################
Alain Reguera Delgado f23b0d
Alain Reguera Delgado c0ca71
# Process configuration files provided as argument in the command-line
Alain Reguera Delgado c0ca71
# to locale command. Basically, it redefines values previously set in
Alain Reguera Delgado c0ca71
# the files-related function using the configuration file provided in
Alain Reguera Delgado c0ca71
# the command-line.
Alain Reguera Delgado f23b0d
function conf {
Alain Reguera Delgado f23b0d
Alain Reguera Delgado f23b0d
    local CONFIGURATION=${RENDER_FROM}
Alain Reguera Delgado f23b0d
Alain Reguera Delgado f23b0d
    # Use arrays to store section names. This make possible to make
Alain Reguera Delgado f23b0d
    # use of post-rendition and last-rendition concepts. Otherwise it
Alain Reguera Delgado f23b0d
    # would be difficult to predict information about sections inside
Alain Reguera Delgado f23b0d
    # deeper environments.
Alain Reguera Delgado f23b0d
    local -a SECTIONS
Alain Reguera Delgado f23b0d
    for SECTION in $(tcar_getConfigSectionNames "${CONFIGURATION}" \
Alain Reguera Delgado f23b0d
        | egrep ${TCAR_FLAG_FILTER});do
Alain Reguera Delgado f23b0d
        SECTIONS[++${#SECTIONS[*]}]="${SECTION}"
Alain Reguera Delgado f23b0d
    done
Alain Reguera Delgado f23b0d
Alain Reguera Delgado f23b0d
    # Verify the configuration file has one section entry at least.
Alain Reguera Delgado f23b0d
    if [[ ${#SECTIONS[*]} -eq 0 ]];then
Alain Reguera Delgado f23b0d
        tcar_printMessage "`eval_gettext "No section definition was found in \\\$CONFIGURATION."`" --as-error-line
Alain Reguera Delgado f23b0d
    fi
Alain Reguera Delgado f23b0d
Alain Reguera Delgado f23b0d
    local COUNTER=0
Alain Reguera Delgado f23b0d
Alain Reguera Delgado f23b0d
    while [[ ${COUNTER} -lt ${#SECTIONS[*]} ]];do
Alain Reguera Delgado f23b0d
Alain Reguera Delgado f23b0d
        local SECTION=${SECTIONS[${COUNTER}]}
Alain Reguera Delgado f23b0d
Alain Reguera Delgado f23b0d
        local RENDER_TYPE=$(tcar_getConfigValue "${CONFIGURATION}" "${SECTION}" "render-type")
Alain Reguera Delgado f23b0d
        if [[ -z ${RENDER_TYPE} ]];then
Alain Reguera Delgado f23b0d
            tcar_printMessage "${CONFIGURATION} `gettext "hasn't render-type set in."`" --as-error-line
Alain Reguera Delgado f23b0d
        fi
Alain Reguera Delgado f23b0d
Alain Reguera Delgado f23b0d
        local RENDER_FROM=$(tcar_getConfigValue "${CONFIGURATION}" "${SECTION}" "render-from")
Alain Reguera Delgado f23b0d
        if [[ -z ${RENDER_FROM} ]];then
Alain Reguera Delgado f23b0d
            tcar_printMessage "${CONFIGURATION} `gettext "hasn't render-from set in."`" --as-error-line
Alain Reguera Delgado f23b0d
        fi
Alain Reguera Delgado f23b0d
        if [[ ! ${RENDER_FROM} =~ "^/" ]];then
Alain Reguera Delgado f23b0d
            RENDER_FROM=$(dirname ${CONFIGURATION})/${RENDER_FROM}
Alain Reguera Delgado f23b0d
        fi
Alain Reguera Delgado f23b0d
Alain Reguera Delgado f23b0d
        local RENDER_FLOW=$(tcar_getConfigValue "${CONFIGURATION}" "${SECTION}" "render-flow")
Alain Reguera Delgado f23b0d
        if [[ -z ${RENDER_FLOW} ]];then
Alain Reguera Delgado f23b0d
            tcar_printMessage "${CONFIGURATION} `gettext "hasn't render-flow set in."`" --as-error-line
Alain Reguera Delgado f23b0d
        fi
Alain Reguera Delgado f23b0d
Alain Reguera Delgado f23b0d
        local LOCALE_FROM=$(tcar_getConfigValue "${CONFIGURATION}" "${SECTION}" "locale-from")
Alain Reguera Delgado f23b0d
        if [[ -z ${LOCALE_FROM} ]];then
Alain Reguera Delgado f23b0d
            tcar_printMessage "${CONFIGURATION} `gettext "hasn't locale-from set in."`" --as-error-line
Alain Reguera Delgado f23b0d
        fi
Alain Reguera Delgado f23b0d
        if [[ ! ${LOCALE_FROM} =~ "^/" ]];then
Alain Reguera Delgado f23b0d
            LOCALE_FROM=$(dirname ${CONFIGURATION})/${LOCALE_FROM}
Alain Reguera Delgado f23b0d
        fi
Alain Reguera Delgado f23b0d
Alain Reguera Delgado f23b0d
        # Re-define package name written in POT and PO files. This is
Alain Reguera Delgado f23b0d
        # the name of the initialization file you provided as argument
Alain Reguera Delgado f23b0d
        # to the command line to provide localization for.
Alain Reguera Delgado f23b0d
        local PACKAGE_NAME=$(basename ${RENDER_FROM})
Alain Reguera Delgado f23b0d
Alain Reguera Delgado f23b0d
        # Re-define absolute path to portable and machine objects.
Alain Reguera Delgado f23b0d
        local POT_FILE=$(tcar_getTemporalFile "${PACKAGE_NAME}.pot")
Alain Reguera Delgado f23b0d
        local PO_FILE=${LOCALE_FROM}
Alain Reguera Delgado f23b0d
        local MO_FILE=$(dirname ${RENDER_FROM})/Locales/${TCAR_SCRIPT_LANG_LC}/LC_MESSAGES/${PACKAGE_NAME}.mo
Alain Reguera Delgado f23b0d
Alain Reguera Delgado f23b0d
        # Execute type-specific module for processing files.
Alain Reguera Delgado f23b0d
        tcar_setModuleEnvironment -m "${RENDER_TYPE}" -t "sibling"
Alain Reguera Delgado f23b0d
Alain Reguera Delgado f23b0d
        # Increment section's counter.
Alain Reguera Delgado f23b0d
        COUNTER=$(( ${COUNTER} + 1 ))
Alain Reguera Delgado f23b0d
Alain Reguera Delgado f23b0d
    done
Alain Reguera Delgado f23b0d
Alain Reguera Delgado f23b0d
    # Reset array variables and their counters to avoid undesired
Alain Reguera Delgado f23b0d
    # concatenations between configuration files.
Alain Reguera Delgado f23b0d
    unset COUNTER
Alain Reguera Delgado f23b0d
    unset SECTIONS
Alain Reguera Delgado f23b0d
Alain Reguera Delgado f23b0d
}