Blame Automation/Modules/Tuneup/tuneup.sh

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