Blame Scripts/Bash/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
#
f62945
# 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
c0ee12
    local TEMPLATES=''
c0ee12
    local INSTANCE=''
754a35
    local COUNT=0
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.
754a35
    TEMPLATE="/home/centos/artwork/trunk/Scripts/Bash/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.
754a35
    TITLE[0]="`gettext "Your full name"`"
754a35
    TITLE[1]="`gettext "Year which you started working in"`"
754a35
    TITLE[2]="`gettext "Year which you stopped working in"`"
c0ee12
754a35
    # Define translation marker. These values are used inside
754a35
    # template file.
754a35
    MARKER[0]='=FULLNAME='
754a35
    MARKER[1]='=YEAR1='
754a35
    MARKER[2]='=YEAR2='
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})?$'
754a35
    PATTERN[2]=${PATTERN[1]}
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."`"
754a35
    PATTERN_MSG[2]=${PATTERN_MSG[1]}
c0ee12
754a35
    # Define default values.
754a35
    DEFAULT[0]="The CentOS Project"
754a35
    DEFAULT[1]='2003'
754a35
    DEFAULT[2]=$(date +%Y)
754a35
754a35
    # Initialize values using user's input.
754a35
    cli_printMessage "`gettext "Enter copyright 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
a1abae
    # Define list of files to process.
a1abae
    cli_getFilesList
a1abae
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
c0ee12
    done \
c0ee12
        | awk -f /home/centos/artwork/trunk/Scripts/Bash/Styles/output_forTwoColumns.awk
c0ee12
754a35
    # Remove template instance.
754a35
    cli_checkFiles "${INSTANCE}" 'f'
754a35
    rm $INSTANCE
754a35
754a35
    # Check repository changes and ask you to commit them up to
c0ee12
    # central repository.
c0ee12
    cli_commitRepoChanges
c0ee12
c0ee12
}