Blame Scripts/Bash/Functions/Shell/shell_updateTopComment.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
#
c0ee12
#   Usage:
4fac24
#
4fac24
#   centos-art shell --update-topcomment=path/to/dir --filter=filename
c0ee12
#
c0ee12
# In the above usage example `path/to/dir' represents the parent
4fac24
# directory where shell scripts, you want to update top comment, are.
4fac24
# The `--filter=filename' argument is optional and if provided just
4fac24
# the file specificed is affected. Otherwise all files ending in `.sh'
4fac24
# are massively modified.
c0ee12
#
c0ee12
# Copyright (C) 2009-2010 Alain Reguera Delgado
c0ee12
# 
c0ee12
# This program is free software; you can redistribute it and/or modify
c0ee12
# it under the terms of the GNU General Public License as published by
c0ee12
# the Free Software Foundation; either version 2 of the License, or
c0ee12
# (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.
c0ee12
#
c0ee12
# ----------------------------------------------------------------------
c0ee12
# $Id$
c0ee12
# ----------------------------------------------------------------------
c0ee12
4fac24
function shell_updateTopComment {
c0ee12
c0ee12
    local TEMPLATES=''
4fac24
    local TEMPLATE=''
c0ee12
    local INSTANCE=''
4fac24
    local YEAR=''
c0ee12
4fac24
    # Define absolute path to template files.
4fac24
    TEMPLATES=~/artwork/trunk/Scripts/Bash/Functions/Shell/Tpl
c0ee12
4fac24
    # Define template file we want to apply. More than one template
4fac24
    # file may exist, so let the user choose which one to use.
4fac24
    cli_printMessage "`gettext "Select the template you want to apply"`:"
c0ee12
    select TEMPLATE in $(ls $TEMPLATES);do
c0ee12
       TEMPLATE=$TEMPLATES/$TEMPLATE
c0ee12
       break
c0ee12
    done
c0ee12
4fac24
    # Check template file existence.
b76c02
    cli_checkFiles $TEMPLATE 'f'
c0ee12
4fac24
    # Define template instance name.
c0ee12
    INSTANCE=${TMPFILE}-$(basename $TEMPLATE)
c0ee12
4fac24
    # Define the last year to use in the copyright note. As last year
4fac24
    # we understand the last year in which the files were modified, or
4fac24
    # what is the same, the present year in which this automation
4fac24
    # script was applied on.
4fac24
    YEAR=$(date +%Y)
c0ee12
c0ee12
    for FILE in $FILES;do
c0ee12
4fac24
        # Create template instance.
4fac24
        sed -r -e "s!=YEAR=!$YEAR!" \
c0ee12
            $TEMPLATE > $INSTANCE
c0ee12
4fac24
        # Apply template instance to file.
c0ee12
        sed -i -f $INSTANCE $FILE
c0ee12
4fac24
        # Remove template instance.
b76c02
        cli_checkFiles $INSTANCE 'f'
b76c02
        rm $INSTANCE
c0ee12
c0ee12
    done \
c0ee12
        | awk -f /home/centos/artwork/trunk/Scripts/Bash/Styles/output_forTwoColumns.awk
c0ee12
4fac24
    # Check repository changes and ask user to commit them up to
c0ee12
    # central repository.
c0ee12
    cli_commitRepoChanges
c0ee12
c0ee12
}