Blame Scripts/Modules/Tuneup/tuneup.sh

Alain Reguera Delgado b29c5b
#!/bin/bash
Alain Reguera Delgado b29c5b
######################################################################
Alain Reguera Delgado b29c5b
#
Alain Reguera Delgado cb2549
#   tcar - The CentOS Artwork Repository automation tool.
Alain Reguera Delgado cb2549
#   Copyright © 2014 The CentOS Artwork SIG
Alain Reguera Delgado b29c5b
#
Alain Reguera Delgado cb2549
#   This program is free software; you can redistribute it and/or
Alain Reguera Delgado cb2549
#   modify it under the terms of the GNU General Public License as
Alain Reguera Delgado cb2549
#   published by the Free Software Foundation; either version 2 of the
Alain Reguera Delgado cb2549
#   License, or (at your option) any later version.
Alain Reguera Delgado b29c5b
#
Alain Reguera Delgado cb2549
#   This program is distributed in the hope that it will be useful,
Alain Reguera Delgado cb2549
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
Alain Reguera Delgado cb2549
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Alain Reguera Delgado cb2549
#   General Public License for more details.
Alain Reguera Delgado b29c5b
#
Alain Reguera Delgado cb2549
#   You should have received a copy of the GNU General Public License
Alain Reguera Delgado cb2549
#   along with this program; if not, write to the Free Software
Alain Reguera Delgado cb2549
#   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Alain Reguera Delgado b29c5b
#
Alain Reguera Delgado cb2549
#   Alain Reguera Delgado <al@centos.org.cu>
Alain Reguera Delgado cb2549
#   39 Street No. 4426 Cienfuegos, Cuba.
Alain Reguera Delgado b29c5b
#
Alain Reguera Delgado b29c5b
######################################################################
Alain Reguera Delgado b29c5b
Alain Reguera Delgado cb2549
# Standardize source files maintenance.
Alain Reguera Delgado b29c5b
function tuneup {
Alain Reguera Delgado b29c5b
Alain Reguera Delgado b29c5b
    # Define file extensions tuneup module will look for processing.
Alain Reguera Delgado b29c5b
    local FILE_EXTENSION_REGEX='\.(svgz|svg|shtml|xhtml|html|sh)$'
Alain Reguera Delgado b29c5b
Alain Reguera Delgado b29c5b
    tuneup_getOptions
Alain Reguera Delgado b29c5b
Alain Reguera Delgado b29c5b
    for ARGUMENT in ${TCAR_MODULE_ARGUMENT};do
Alain Reguera Delgado b29c5b
Alain Reguera Delgado b29c5b
        # Sanitate non-option arguments to be sure they match the
Alain Reguera Delgado cb2549
        # directory conventions established by tcar.sh script
Alain Reguera Delgado b29c5b
        # against source directory locations in the working copy.
Alain Reguera Delgado 3a0a02
        local ARGUMENT=$(tcar_checkWorkDirSource ${ARGUMENT})
Alain Reguera Delgado b29c5b
Alain Reguera Delgado b29c5b
        # Build list of files to process.
Alain Reguera Delgado b29c5b
        if [[ -f ${ARGUMENT} ]];then
Alain Reguera Delgado b29c5b
            local FILES=${ARGUMENT}
Alain Reguera Delgado b29c5b
        elif [[ -d ${ARGUMENT} ]];then
Alain Reguera Delgado dd8f6b
            local FILES=$(tcar_getFilesList -p ".+${FILE_EXTENSION_REGEX}" -t 'f' ${ARGUMENT} \
Alain Reguera Delgado dd8f6b
                | egrep ${TCAR_FLAG_FILTER})
Alain Reguera Delgado b29c5b
        else
Alain Reguera Delgado b29c5b
            tcar_printMessage "`gettext "The argument provided isn't valid."`" --as-error-line
Alain Reguera Delgado b29c5b
        fi
Alain Reguera Delgado b29c5b
Alain Reguera Delgado b29c5b
        # Process list of files.
Alain Reguera Delgado b29c5b
        for FILE in ${FILES};do
Alain Reguera Delgado b29c5b
Alain Reguera Delgado b29c5b
            # Print action message.
Alain Reguera Delgado b29c5b
            tcar_printMessage "${FILE}" --as-tuningup-line
Alain Reguera Delgado b29c5b
Alain Reguera Delgado b29c5b
            # Retrieve module name to apply based on file extension .
Alain Reguera Delgado b29c5b
            local FILE_EXTENSION=$(echo ${FILE} \
Alain Reguera Delgado b29c5b
                | sed -r "s/.+${FILE_EXTENSION_REGEX}/\1/")
Alain Reguera Delgado b29c5b
Alain Reguera Delgado b29c5b
            # Set module aliases. 
Alain Reguera Delgado b29c5b
            if [[ ${FILE_EXTENSION} =~ '(shtml|html|htm)' ]];then
Alain Reguera Delgado b29c5b
                FILE_EXTENSION='xhtml'
Alain Reguera Delgado b29c5b
            fi
Alain Reguera Delgado b29c5b
Alain Reguera Delgado b29c5b
            # Initiate module's environment for processing file.
Alain Reguera Delgado b29c5b
            tcar_setModuleEnvironment -m "${FILE_EXTENSION}" -t "child" "${FILE}"
Alain Reguera Delgado b29c5b
Alain Reguera Delgado b29c5b
        done
Alain Reguera Delgado b29c5b
Alain Reguera Delgado b29c5b
    done
Alain Reguera Delgado b29c5b
Alain Reguera Delgado b29c5b
}