Blame Functions/Shell/shell_updateCopyright.sh

c0ee12
#!/bin/bash
c0ee12
#
4fac24
# shell_updateTopComment.sh -- This function replaces top comment
4fac24
# section inside shell scripts (*.sh) with one of many pre-defined
4fac24
# templates available. Use this function to maintain shell scripts top
4fac24
# comments inside repository.
c0ee12
#
9f5f2e
# Copyright (C) 2009-2011 Alain Reguera Delgado
c0ee12
# 
7cd8e9
# This program is free software; you can redistribute it and/or
7cd8e9
# modify it under the terms of the GNU General Public License as
7cd8e9
# published by the Free Software Foundation; either version 2 of the
7cd8e9
# License, or (at your option) any later version.
c0ee12
# 
c0ee12
# This program is distributed in the hope that it will be useful, but
c0ee12
# WITHOUT ANY WARRANTY; without even the implied warranty of
c0ee12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
c0ee12
# General Public License for more details.
c0ee12
#
c0ee12
# You should have received a copy of the GNU General Public License
c0ee12
# along with this program; if not, write to the Free Software
c0ee12
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
c0ee12
# USA.
7cd8e9
# 
c0ee12
# ----------------------------------------------------------------------
c0ee12
# $Id$
c0ee12
# ----------------------------------------------------------------------
c0ee12
754a35
function shell_updateCopyright {
c0ee12
817c1d
    local FILE=''
754a35
    local COUNT=0
817c1d
    local FILES=''
817c1d
    local INSTANCE=''
817c1d
    local TEMPLATES=''
754a35
    local -a TITLE
754a35
    local -a VALUE
754a35
    local -a PATTERN
754a35
    local -a PATTERN_MSG
754a35
    local -a DEFAULT
754a35
    local -a MARKER
c0ee12
754a35
    # Define absolute path to template file.
7b46a4
    TEMPLATE="${CLI_BASEDIR}/Functions/Shell/Config/tpl_forCopyright.sed"
c0ee12
4fac24
    # Check template file existence.
b76c02
    cli_checkFiles $TEMPLATE 'f'
c0ee12
754a35
    # Define file name to template instance.
93705a
    INSTANCE=$(cli_getTemporalFile $TEMPLATE)
c0ee12
754a35
    # Define copyright information.
817c1d
    TITLE[0]="`gettext "Copyright holder"`"
817c1d
    TITLE[1]="`gettext "Copyright year"`"
c0ee12
754a35
    # Define translation marker. These values are used inside
754a35
    # template file.
817c1d
    MARKER[0]='=COPYRIGHT_HOLDER='
817c1d
    MARKER[1]='=COPYRIGHT_YEAR='
c0ee12
754a35
    # Define pattern. These values are used as regular
754a35
    # expression patterns for user's input further verification.
754a35
    PATTERN[0]='^([[:alnum:] _-.]+)?$'
754a35
    PATTERN[1]='^([[:digit:]]{4})?$'
c0ee12
754a35
    # Define pattern message. These values are used as output
754a35
    # message when user's input doesn't match the related pattern.
754a35
    PATTERN_MSG[0]="`gettext "Try using alphanumeric characters."`"
754a35
    PATTERN_MSG[1]="`gettext "Try using numeric characters."`"
c0ee12
754a35
    # Define default values.
817c1d
    DEFAULT[0]="The CentOS Project. `gettext "All rights reserved."`"
817c1d
    DEFAULT[1]=$(date +%Y)
754a35
754a35
    # Initialize values using user's input.
817c1d
    cli_printMessage "`gettext "Enter the information you want to apply:"`"
754a35
    while [[ $COUNT -ne ${#TITLE[*]} ]];do
754a35
754a35
        # Request value.
754a35
        cli_printMessage "${TITLE[$COUNT]}" 'AsRequestLine'
754a35
        read VALUE[$COUNT]
754a35
754a35
        # Sanitate values to exclude characters that could
754a35
        # introduce possible markup malformations to final SVG files.
754a35
        until [[ ${VALUE[$COUNT]} =~ ${PATTERN[$COUNT]} ]];do
754a35
            cli_printMessage "${PATTERN_MSG[$COUNT]}"
754a35
            cli_printMessage "${TITLE[$COUNT]}" 'AsRequestLine'
754a35
            read VALUE[$COUNT]
754a35
        done
754a35
754a35
        # Set default value to empty values. 
754a35
        if [[ ${VALUE[$COUNT]} == '' ]];then
754a35
            VALUE[$COUNT]=${DEFAULT[$COUNT]}
754a35
        fi
754a35
754a35
        # Increase counter.
754a35
        COUNT=$(($COUNT + 1))
754a35
754a35
    done
754a35
754a35
    # Create template instance.
754a35
    cp $TEMPLATE $INSTANCE
754a35
754a35
    # Check template instance. We cannot continue if template instance
754a35
    # couldn't be created.
754a35
    cli_checkFiles $INSTANCE 'f'
754a35
754a35
    # Reset counter.
754a35
    COUNT=0
754a35
754a35
    while [[ $COUNT -ne ${#TITLE[*]} ]];do
754a35
754a35
        # Apply translation marker replacement.
754a35
        sed -r -i "s!${MARKER[$COUNT]}!${VALUE[$COUNT]}!g" $INSTANCE
754a35
754a35
        # Increase counter.
754a35
        COUNT=$(($COUNT + 1))
754a35
754a35
    done
754a35
7f50e7
    # Define list of files to process
7f50e7
    FILES=$(cli_getFilesList "$ACTIONVAL" "${FLAG_FILTER}.*\.sh")
7f50e7
7f50e7
    # Set action preamble.
467208
    cli_printActionPreamble "${FILES}" '' ''
817c1d
a1abae
    # Process list of files.
754a35
    for FILE in $FILES;do
754a35
754a35
        # Output action message.
754a35
        cli_printMessage $FILE 'AsUpdatingLine'
754a35
 
754a35
        # Apply template instance to file.
754a35
        sed -r -i -f $INSTANCE $FILE
c0ee12
817c1d
    done
c0ee12
754a35
    # Remove template instance.
817c1d
    if [[ -f ${INSTANCE} ]];then
817c1d
        rm ${INSTANCE} 
817c1d
    fi
c0ee12
c0ee12
}