diff --git a/Scripts/Bash/Functions/Shell/Tpl/centos-artwork-sig.sed b/Scripts/Bash/Functions/Shell/Tpl/centos-artwork-sig.sed deleted file mode 100644 index 2fb15ab..0000000 --- a/Scripts/Bash/Functions/Shell/Tpl/centos-artwork-sig.sed +++ /dev/null @@ -1,68 +0,0 @@ -# This file is the metadata information used by CentOS Artwork SIG on -# its scalable vector graphics (SVG) files. This files is used with -# the regular expression '.*\.svg$' only. -# --------------------------------------------------- -# $Id: svg-metadata-centos.sed 5964 2010-06-16 06:51:37Z al $ -# --------------------------------------------------- -/\ - \ - \ - image/svg+xml\ - \ - \ - =TITLE=\ - =DATE=\ - \ - \ - =CREATOR=\ - \ - \ - \ - \ - =RIGHTS=\ - \ - \ - \ - \ - =PUBLISHER=\ - \ - \ - \ - \ - \ - en\ - \ - \ -=KEYWORDS=\ - \ - \ - =COVERAGE=\ - \ - \ - \ - Alain Reguera Delgado\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - diff --git a/Scripts/Bash/Functions/Shell/Tpl/gpl-copyright-al.sed b/Scripts/Bash/Functions/Shell/Tpl/gpl-copyright-al.sed new file mode 100644 index 0000000..b18b358 --- /dev/null +++ b/Scripts/Bash/Functions/Shell/Tpl/gpl-copyright-al.sed @@ -0,0 +1,38 @@ +# This file standardizes the look and feel of top comments used by +# scripts inside CentOS Artwork Repository. It contains the copyright +# note and the license under which the script is released. This files +# is used with the regular expression '.*\.sh$' only. +# --------------------------------------------------- +# $Id: svg-metadata-centos.sed 5962 2010-06-16 05:44:51Z al $ +# --------------------------------------------------- +/^# +Copyright .*$/a\ +# Copyright (C) 2009-=YEAR= Alain Reguera Delgado\ +# \ +# This program is free software; you can redistribute it and/or\ +# modify it under the terms of the GNU General Public License as\ +# published by the Free Software Foundation; either version 2 of the\ +# License, or (at your option) any later version.\ +# \ +# This program is distributed in the hope that it will be useful, but\ +# WITHOUT ANY WARRANTY; without even the implied warranty of\ +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\ +# General Public License for more details.\ +#\ +# You should have received a copy of the GNU General Public License\ +# along with this program; if not, write to the Free Software\ +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\ +# USA.\ +# \ +#------------------------------------------------------------ + +# Remove previous comments. +/^# +Copyright .*$/,/^#-+$/{ +d +} + +# Remove more than one space after comments. +s/^# +/# / + +# Define first line +1c\ +#!/bin/bash diff --git a/Scripts/Bash/Functions/Shell/shell.sh b/Scripts/Bash/Functions/Shell/shell.sh new file mode 100755 index 0000000..1338c09 --- /dev/null +++ b/Scripts/Bash/Functions/Shell/shell.sh @@ -0,0 +1,41 @@ +#!/bin/bash +# +# shell.sh -- This function provides very basic string manipulations +# to help you maintain Bash scripts inside repository. +# +# Copyright (C) 2009-2010 Alain Reguera Delgado +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +# USA. +# +# ---------------------------------------------------------------------- +# $Id$ +# ---------------------------------------------------------------------- + +function shell { + + local FILES='' + + # Define list of files to process using option value as reference. + if [[ -d $OPTIONVAL ]];then + FILES=$(find $OPTIONVAL -regextype posix-egrep -type f -regex '.*/*.shell$') + elif [[ -f $OPTIONVAL ]];then + FILES=$OPTIONVAL + fi + + # Define command line interface. + shell_getActions + +} diff --git a/Scripts/Bash/Functions/Shell/shell_getActions.sh b/Scripts/Bash/Functions/Shell/shell_getActions.sh new file mode 100755 index 0000000..4d8b3cd --- /dev/null +++ b/Scripts/Bash/Functions/Shell/shell_getActions.sh @@ -0,0 +1,45 @@ +#!/bin/bash +# +# shell_getActions.sh -- This function initializes very simple string +# manipulations to Bash scripts (*.sh), using the option value of +# centos-art.sh script as reference. +# +# Copyright (C) 2009-2010 Alain Reguera Delgado +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +# USA. +# +# ---------------------------------------------------------------------- +# $Id$ +# ---------------------------------------------------------------------- + +function shell_getActions { + + # Evaluate option name and define which actions does centos-art.sh + # script supports. + case $OPTIONNAM in + + '--update-topcomment' ) + # Update top comment inside shell scripts using templates. + shell_updateMetadata + ;; + + * ) + cli_printMessage "`eval_gettext "The option provided is not valid."`" + ;; + + esac + +} diff --git a/Scripts/Bash/Functions/Shell/shell_updateComments.sh b/Scripts/Bash/Functions/Shell/shell_updateComments.sh new file mode 100755 index 0000000..1b0fdf3 --- /dev/null +++ b/Scripts/Bash/Functions/Shell/shell_updateComments.sh @@ -0,0 +1,95 @@ +#!/bin/bash +# +# shell_updateTopComment.sh -- This function replaces top comment +# section inside shell scripts (*.sh) with one of many pre-defined +# templates available. Use this function to maintain shell scripts top +# comments inside repository. +# +# Usage: +# +# centos-art shell --update-topcomment=path/to/dir --filter=filename +# +# In the above usage example `path/to/dir' represents the parent +# directory where shell scripts, you want to update top comment, are. +# The `--filter=filename' argument is optional and if provided just +# the file specificed is affected. Otherwise all files ending in `.sh' +# are massively modified. +# +# Copyright (C) 2009-2010 Alain Reguera Delgado +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +# USA. +# +# ---------------------------------------------------------------------- +# $Id$ +# ---------------------------------------------------------------------- + +function shell_updateTopComment { + + local TEMPLATES='' + local TEMPLATE='' + local INSTANCE='' + local YEAR='' + + # Define absolute path to template files. + TEMPLATES=~/artwork/trunk/Scripts/Bash/Functions/Shell/Tpl + + # Define template file we want to apply. More than one template + # file may exist, so let the user choose which one to use. + cli_printMessage "`gettext "Select the template you want to apply"`:" + select TEMPLATE in $(ls $TEMPLATES);do + TEMPLATE=$TEMPLATES/$TEMPLATE + break + done + + # Check template file existence. + cli_checkFiles $TEMPLATE 'f' '' '--quiet' + if [[ $? -ne 0 ]];then + cli_printMessage "`gettext "The template file you provided doesn't exist."`" + cli_printMessage "$(caller)" 'AsToKnowMoreLine' + fi + + # Define template instance name. + INSTANCE=${TMPFILE}-$(basename $TEMPLATE) + + # Define the last year to use in the copyright note. As last year + # we understand the last year in which the files were modified, or + # what is the same, the present year in which this automation + # script was applied on. + YEAR=$(date +%Y) + + for FILE in $FILES;do + + # Create template instance. + sed -r -e "s!=YEAR=!$YEAR!" \ + $TEMPLATE > $INSTANCE + + # Apply template instance to file. + sed -i -f $INSTANCE $FILE + + # Remove template instance. + cli_checkFiles $INSTANCE 'f' '' '--quiet' + if [[ $? -eq 0 ]];then + rm $INSTANCE + fi + + done \ + | awk -f /home/centos/artwork/trunk/Scripts/Bash/Styles/output_forTwoColumns.awk + + # Check repository changes and ask user to commit them up to + # central repository. + cli_commitRepoChanges + +} diff --git a/Scripts/Bash/Functions/Shell/svg.sh b/Scripts/Bash/Functions/Shell/svg.sh deleted file mode 100755 index 24a6acb..0000000 --- a/Scripts/Bash/Functions/Shell/svg.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/bash -# -# svg.sh -- This function provides very basic SVG manipulations to -# help maintain svg files inside the repository. -# -# Copyright (C) 2009-2010 Alain Reguera Delgado -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 -# USA. -# -# ---------------------------------------------------------------------- -# $Id$ -# ---------------------------------------------------------------------- - -function svg { - - local FILES='' - - # Define list of scalable vector graphic files to process using - # option value as reference. - if [[ -d $OPTIONVAL ]];then - FILES=$(find $OPTIONVAL -regextype posix-egrep -type f -regex '.*/*.svg$') - elif [[ -f $OPTIONVAL ]];then - FILES=$OPTIONVAL - fi - - # Define command line interface for svg-based actions. - svg_getActions - -} diff --git a/Scripts/Bash/Functions/Shell/svg_getActions.sh b/Scripts/Bash/Functions/Shell/svg_getActions.sh deleted file mode 100755 index 6670793..0000000 --- a/Scripts/Bash/Functions/Shell/svg_getActions.sh +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/bash -# -# svg_getActions.sh -- This function initializes SVG string -# manipulation functionalities, using the option value of -# centos-art.sh script as reference. -# -# Copyright (C) 2009-2010 Alain Reguera Delgado -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 -# USA. -# -# ---------------------------------------------------------------------- -# $Id$ -# ---------------------------------------------------------------------- - -function svg_getActions { - - # Evaluate option name and define which actions does centos-art.sh - # script supports. - case $OPTIONNAM in - - '--update-metadata' ) - # Update metadata inside svg files using metadata - # templates. - svg_updateMetadata - ;; - - * ) - cli_printMessage "`eval_gettext "The option provided is not valid."`" - ;; - - esac - -} diff --git a/Scripts/Bash/Functions/Shell/svg_updateMetadata.sh b/Scripts/Bash/Functions/Shell/svg_updateMetadata.sh deleted file mode 100755 index 7d5e8a2..0000000 --- a/Scripts/Bash/Functions/Shell/svg_updateMetadata.sh +++ /dev/null @@ -1,137 +0,0 @@ -#!/bin/bash -# -# svg_updateMetadata.sh -- This function replaces metadata section -# inside scalable vector graphic (SVG) files with one of pre-defined -# metadata templates available. Use this function to maintain metadata -# information inside repository. -# -# Usage: -# centos-art svg --update-metadata=path/to/dir --filter=filename -# -# In the above usage example `path/to/dir' represents the parent -# directory where scalable vector graphics you want to update metadata -# information are. The `--filter=filename' is optional and if provided -# just the file specificed is affected. Otherwise all files ending in -# `.svg' are massively modified. -# -# Copyright (C) 2009-2010 Alain Reguera Delgado -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 -# USA. -# -# ---------------------------------------------------------------------- -# $Id$ -# ---------------------------------------------------------------------- - -function svg_updateMetadata { - - local TITLE='' - local DATE='' - local CREATOR='' - local RIGHTS='' - local PUBLISHER='' - local COVERAGE='' - local TEMPLATES='' - local KEYWORDS='' - local INSTANCE='' - - # Define absolute path to metadata templates parent directory. - # This is the place where we store metadata template files. - TEMPLATES=~/artwork/trunk/Scripts/Bash/Functions/Svg/Tpl - - # Define metadata template file we want to apply. More than one - # metadata template file may exist, so let choosing which one to - # use. - cli_printMessage "`gettext "Select the metadata template you want to apply:"`" - select TEMPLATE in $(ls $TEMPLATES);do - TEMPLATE=$TEMPLATES/$TEMPLATE - break - done - - # Check metadata template file existence. - cli_checkFiles $TEMPLATE 'f' '' '--quiet' - if [[ $? -ne 0 ]];then - cli_printMessage "`gettext "The template file you provided doesn't exist."`" - cli_printMessage "$(caller)" 'AsToKnowMoreLine' - fi - - # Define metadata template instance. - INSTANCE=${TMPFILE}-$(basename $TEMPLATE) - - # Define svg document date. - DATE=$(date +%Y-%m-%d) - - # Define svg document creator. - CREATOR='CentOS Artwork SIG' - - # Define svg document rights. - RIGHTS=$CREATOR - - # Define svg document publisher. - PUBLISHER='The CentOS Project' - - # Define svg document coverage. - COVERAGE=$PUBLISHER - - for FILE in $FILES;do - - # Define svg document title. - TITLE=$(basename $FILE) - - # Define svg document keywords. - KEYWORDS=$(echo $FILE | cut -d/ -f6- | tr '/' '\n') - - # Redifine keywords using SVG standard format. Note that this - # information is inserted inside metadata template file. The - # metadata template file is a replacement set of sed commands - # so we need to escape the new line of each line using one - # backslash (\). As we are doing this inside bash, it is - # required to escape the backslash with another backslash so - # it passes literally. - KEYWORDS=$(\ - for KEY in $KEYWORDS;do - echo " $KEY\\" - done) - - # Create metadata template instance. - sed -r \ - -e "s!=TITLE=!$TITLE!" \ - -e "s!=DATE=!$DATE!" \ - -e "s!=CREATOR=!$CREATOR!" \ - -e "s!=RIGHTS=!$RIGHTS!" \ - -e "s!=PUBLISHER=!$PUBLISHER!" \ - -e "s!=COVERAGE=!$COVERAGE!" \ - -e "/=KEYWORDS=/c\\${KEYWORDS}" \ - $TEMPLATE > $INSTANCE - sed -i -r -e 's/>$/>\\/g' $INSTANCE - - # Apply metadata template instance to scalable vector graphic - # file. - sed -i -f $INSTANCE $FILE - - # Remove metadata template instance. - cli_checkFiles $INSTANCE 'f' '' '--quiet' - if [[ $? -eq 0 ]];then - rm $INSTANCE - fi - - done \ - | awk -f /home/centos/artwork/trunk/Scripts/Bash/Styles/output_forTwoColumns.awk - - # Check repository changes and ask you to commit them up to - # central repository. - cli_commitRepoChanges - -}