Blame tcar-scripts-prepare/Modules/Conf/conf.sh

Alain Reguera Delgado c554f1
#!/bin/bash
Alain Reguera Delgado c554f1
######################################################################
Alain Reguera Delgado c554f1
#
Alain Reguera Delgado c554f1
#   conf.sh -- This module prepares configuration files used by both
Alain Reguera Delgado c554f1
#   render and locale modules. 
Alain Reguera Delgado c554f1
#
Alain Reguera Delgado c554f1
#   To build the configuration file, this module creates a list of
Alain Reguera Delgado c554f1
#   files to process based on the arguments provided in the
Alain Reguera Delgado c554f1
#   command-line line. With this list, then, it creates the
Alain Reguera Delgado c554f1
#   configuration file using configuration templates for each file
Alain Reguera Delgado c554f1
#   extension supported inside the repository.
Alain Reguera Delgado c554f1
#
Alain Reguera Delgado c554f1
#   The configuration file this module creates doesn't include options
Alain Reguera Delgado c554f1
#   like brand which require information about the image you are about
Alain Reguera Delgado c554f1
#   to produce. The intention of this module is create the
Alain Reguera Delgado c554f1
#   configuration files you need to produce content right away in the
Alain Reguera Delgado c554f1
#   simplest way possible and then letting you improve it as needed.
Alain Reguera Delgado c554f1
#
Alain Reguera Delgado c554f1
#   The name and location of the final configuration file is that
Alain Reguera Delgado c554f1
#   passed as argument to prepare module in the command-line.
Alain Reguera Delgado c554f1
#
Alain Reguera Delgado c554f1
#   Written by:
Alain Reguera Delgado c554f1
#   * Alain Reguera Delgado <al@centos.org.cu>, 2013
Alain Reguera Delgado c554f1
#
Alain Reguera Delgado c554f1
# Copyright (C) 2009-2013 The CentOS Artwork SIG
Alain Reguera Delgado c554f1
#
Alain Reguera Delgado c554f1
# This program is free software; you can redistribute it and/or modify
Alain Reguera Delgado c554f1
# it under the terms of the GNU General Public License as published by
Alain Reguera Delgado c554f1
# the Free Software Foundation; either version 2 of the License, or (at
Alain Reguera Delgado c554f1
# your option) any later version.
Alain Reguera Delgado c554f1
#
Alain Reguera Delgado c554f1
# This program is distributed in the hope that it will be useful, but
Alain Reguera Delgado c554f1
# WITHOUT ANY WARRANTY; without even the implied warranty of
Alain Reguera Delgado c554f1
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Alain Reguera Delgado c554f1
# General Public License for more details.
Alain Reguera Delgado c554f1
#
Alain Reguera Delgado c554f1
# You should have received a copy of the GNU General Public License
Alain Reguera Delgado c554f1
# along with this program; if not, write to the Free Software
Alain Reguera Delgado c554f1
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Alain Reguera Delgado c554f1
#
Alain Reguera Delgado c554f1
######################################################################
Alain Reguera Delgado c554f1
Alain Reguera Delgado c554f1
function conf {
Alain Reguera Delgado c554f1
Alain Reguera Delgado c554f1
    # Verify that a configuration file was provided as argument.
Alain Reguera Delgado c554f1
    if [[ $# -eq 0 ]];then
Alain Reguera Delgado c554f1
        tcar_printMessage "`gettext "The configuration file wasn't provided."`" --as-error-line
Alain Reguera Delgado c554f1
    fi
Alain Reguera Delgado c554f1
Alain Reguera Delgado c554f1
    # Define configuration file.
Alain Reguera Delgado c554f1
    local CONF_FILE=$(tcar_checkRepoDirSource "${1}")
Alain Reguera Delgado c554f1
    tcar_checkFiles -m "\.conf$" ${CONF_FILE}
Alain Reguera Delgado c554f1
Alain Reguera Delgado c554f1
    # Define parent directory of configuration file.
Alain Reguera Delgado c554f1
    local CONF_DIR=$(dirname ${CONF_FILE})
Alain Reguera Delgado c554f1
    tcar_checkFiles -ed "${CONF_DIR}"
Alain Reguera Delgado c554f1
Alain Reguera Delgado c554f1
    # Build the list of files to process. This is all the source files
Alain Reguera Delgado c554f1
    # we want to produce th configuration file for.
Alain Reguera Delgado c554f1
    local SOURCE_FILES=$(tcar_getFilesList ${CONF_DIR} \
Alain Reguera Delgado c554f1
        --mindepth=1 --maxdepth=1 --type=f \
Alain Reguera Delgado c554f1
        --pattern='.+\.(svgz|svg|asciidoc)$')
Alain Reguera Delgado c554f1
Alain Reguera Delgado c554f1
    # Verify the list of files to process.
Alain Reguera Delgado c554f1
    tcar_checkFiles -ef ${SOURCE_FILES}
Alain Reguera Delgado c554f1
Alain Reguera Delgado c554f1
    # Print action message.
Alain Reguera Delgado c554f1
    tcar_printMessage "${CONF_FILE}" --as-creating-line
Alain Reguera Delgado c554f1
Alain Reguera Delgado c554f1
    # Process list of files.
Alain Reguera Delgado c554f1
    for SOURCE_FILE in ${SOURCE_FILES};do
Alain Reguera Delgado c554f1
Alain Reguera Delgado c554f1
        local CONF_FILE_NAME=$(tcar_getFileName "${SOURCE_FILE}")
Alain Reguera Delgado c554f1
        local CONF_FILE_EXTENSION=$(tcar_getFileExtension "${SOURCE_FILE}")
Alain Reguera Delgado c554f1
        local CONF_FILE_TEMPLATE=${TCAR_MODULE_DIR_CONFIGS}/${CONF_FILE_EXTENSION}.render.conf.tpl
Alain Reguera Delgado c554f1
Alain Reguera Delgado c554f1
        sed -r "s/=SECTION=/${CONF_FILE_NAME}/g" ${CONF_FILE_TEMPLATE} >> ${CONF_FILE}
Alain Reguera Delgado c554f1
Alain Reguera Delgado c554f1
    done
Alain Reguera Delgado c554f1
Alain Reguera Delgado c554f1
}