From be7de369aa34932a22fe8efd1a64725f4e3ae1ab Mon Sep 17 00:00:00 2001 From: Alain Reguera Delgado Date: Mar 30 2011 03:08:43 +0000 Subject: Move `shell' functionality into `tuneup' functionality. --- diff --git a/Scripts/Functions/Shell/Config/tpl_forCopyright.sed b/Scripts/Functions/Shell/Config/tpl_forCopyright.sed deleted file mode 100644 index e8e5e2c..0000000 --- a/Scripts/Functions/Shell/Config/tpl_forCopyright.sed +++ /dev/null @@ -1,38 +0,0 @@ -# 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$ -# --------------------------------------------------- -/^# +Copyright .*$/a\ -# Copyright (C) =COPYRIGHT_YEAR== =COPYRIGHT_HOLDER=\ -# \ -# 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/Functions/Shell/shell.sh b/Scripts/Functions/Shell/shell.sh deleted file mode 100755 index f7d573d..0000000 --- a/Scripts/Functions/Shell/shell.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash -# -# shell.sh -- This function provides very basic string manipulations -# to help you maintain Bash scripts inside repository. -# -# Copyright (C) 2009-2011 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 { - - # Define command-line interface. - shell_getActions - -} diff --git a/Scripts/Functions/Shell/shell_getActions.sh b/Scripts/Functions/Shell/shell_getActions.sh deleted file mode 100755 index 44d75d9..0000000 --- a/Scripts/Functions/Shell/shell_getActions.sh +++ /dev/null @@ -1,86 +0,0 @@ -#!/bin/bash -# -# shell_getActions.sh -- This function interpretes arguments passed to -# `shell' functionality and calls actions accordingly. -# -# Copyright (C) 2009-2011 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 { - - # Define short options we want to support. - local ARGSS="" - - # Define long options we want to support. - local ARGSL="update-copyright:" - - # Parse arguments using getopt(1) command parser. - cli_doParseArguments - - # Reset positional parameters using output from (getopt) argument - # parser. - eval set -- "$ARGUMENTS" - - # Look for options passed through command-line. - while true; do - - case "$1" in - - --update-copyright ) - - # Define action value. - ACTIONVAL="$2" - - # Define action name using action value as reference. - ACTIONNAM="${FUNCNAM}_updateCopyright" - - # Rotate positional parameters. - shift 2 - ;; - - * ) - # Break options loop. - break - esac - done - - # Check action value. Be sure the action value matches the - # convenctions defined for source locations inside the working - # copy. - cli_checkRepoDirSource - - # Syncronize changes between the working copy and the central - # repository to bring down changes. - cli_syncroRepoChanges - - # Execute action name. - if [[ $ACTIONNAM =~ "^${FUNCNAM}_[A-Za-z]+$" ]];then - eval $ACTIONNAM - else - cli_printMessage "`gettext "A valid action is required."`" 'AsErrorLine' - cli_printMessage "${FUNCDIRNAM}" 'AsToKnowMoreLine' - fi - - # Syncronize changes between the working copy and the central - # repository to commit up changes. - cli_commitRepoChanges - -} diff --git a/Scripts/Functions/Shell/shell_updateCopyright.sh b/Scripts/Functions/Shell/shell_updateCopyright.sh deleted file mode 100755 index 42bbae1..0000000 --- a/Scripts/Functions/Shell/shell_updateCopyright.sh +++ /dev/null @@ -1,143 +0,0 @@ -#!/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. -# -# Copyright (C) 2009-2011 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_updateCopyright { - - local FILE='' - local COUNT=0 - local FILES='' - local INSTANCE='' - local TEMPLATES='' - local -a TITLE - local -a VALUE - local -a PATTERN - local -a PATTERN_MSG - local -a DEFAULT - local -a MARKER - - # Define absolute path to template file. - TEMPLATE="${CLI_BASEDIR}/Functions/Shell/Config/tpl_forCopyright.sed" - - # Check template file existence. - cli_checkFiles $TEMPLATE 'f' - - # Define file name to template instance. - INSTANCE=$(cli_getTemporalFile $TEMPLATE) - - # Define copyright information. - TITLE[0]="`gettext "Copyright holder"`" - TITLE[1]="`gettext "Copyright year"`" - - # Define translation marker. These values are used inside - # template file. - MARKER[0]='=COPYRIGHT_HOLDER=' - MARKER[1]='=COPYRIGHT_YEAR=' - - # Define pattern. These values are used as regular - # expression patterns for user's input further verification. - PATTERN[0]='^([[:alnum:] _-.]+)?$' - PATTERN[1]='^([[:digit:]]{4})?$' - - # Define pattern message. These values are used as output - # message when user's input doesn't match the related pattern. - PATTERN_MSG[0]="`gettext "Try using alphanumeric characters."`" - PATTERN_MSG[1]="`gettext "Try using numeric characters."`" - - # Define default values. - DEFAULT[0]="The CentOS Project. `gettext "All rights reserved."`" - DEFAULT[1]=$(date +%Y) - - # Initialize values using user's input. - cli_printMessage "`gettext "Enter the information you want to apply:"`" - while [[ $COUNT -ne ${#TITLE[*]} ]];do - - # Request value. - cli_printMessage "${TITLE[$COUNT]}" 'AsRequestLine' - read VALUE[$COUNT] - - # Sanitate values to exclude characters that could - # introduce possible markup malformations to final SVG files. - until [[ ${VALUE[$COUNT]} =~ ${PATTERN[$COUNT]} ]];do - cli_printMessage "${PATTERN_MSG[$COUNT]}" - cli_printMessage "${TITLE[$COUNT]}" 'AsRequestLine' - read VALUE[$COUNT] - done - - # Set default value to empty values. - if [[ ${VALUE[$COUNT]} == '' ]];then - VALUE[$COUNT]=${DEFAULT[$COUNT]} - fi - - # Increase counter. - COUNT=$(($COUNT + 1)) - - done - - # Create template instance. - cp $TEMPLATE $INSTANCE - - # Check template instance. We cannot continue if template instance - # couldn't be created. - cli_checkFiles $INSTANCE 'f' - - # Reset counter. - COUNT=0 - - while [[ $COUNT -ne ${#TITLE[*]} ]];do - - # Apply translation marker replacement. - sed -r -i "s!${MARKER[$COUNT]}!${VALUE[$COUNT]}!g" $INSTANCE - - # Increase counter. - COUNT=$(($COUNT + 1)) - - done - - # Define list of files to process - FILES=$(cli_getFilesList "$ACTIONVAL" "${FLAG_FILTER}.*\.sh") - - # Set action preamble. - cli_printActionPreamble "${FILES}" '' '' - - # Process list of files. - for FILE in $FILES;do - - # Output action message. - cli_printMessage $FILE 'AsUpdatingLine' - - # Apply template instance to file. - sed -r -i -f $INSTANCE $FILE - - done - - # Remove template instance. - if [[ -f ${INSTANCE} ]];then - rm ${INSTANCE} - fi - -} diff --git a/Scripts/Functions/Tuneup/Config/shell_topcomment.sed b/Scripts/Functions/Tuneup/Config/shell_topcomment.sed new file mode 100644 index 0000000..fde98c6 --- /dev/null +++ b/Scripts/Functions/Tuneup/Config/shell_topcomment.sed @@ -0,0 +1,55 @@ +#!/bin/sed +# +# shell_topcomment.sed -- This file standardizes the top comment +# inside centos-art.sh scripts. +# +# Copyright (C) 2009-2011 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$ +# ---------------------------------------------------------------------- +/^# +Copyright .*$/a\ +# Copyright (C) 2009-=COPYRIGHT_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 copyright notice, just to be sure the one above be +# used always. +/^# +Copyright .*$/,/^# -{70}$/{ +d +} + +# Remove more than one space after comments. +s/^# +/# / + +# Define script first line. +1c\ +#!/bin/bash diff --git a/Scripts/Functions/Tuneup/tuneup_doBaseActions.sh b/Scripts/Functions/Tuneup/tuneup_doBaseActions.sh index 0e8a9da..89ed183 100755 --- a/Scripts/Functions/Tuneup/tuneup_doBaseActions.sh +++ b/Scripts/Functions/Tuneup/tuneup_doBaseActions.sh @@ -41,6 +41,9 @@ function tuneup_doBaseActions { # Verify list of files. cli_printActionPreamble "$FILES" '' '' + # Print separator line. + cli_printMessage '-' 'AsSeparatorLine' + # Process list of files and perform maintainance tasks # accordingly. for FILE in $FILES;do diff --git a/Scripts/Functions/Tuneup/tuneup_doShell.sh b/Scripts/Functions/Tuneup/tuneup_doShell.sh new file mode 100755 index 0000000..f700985 --- /dev/null +++ b/Scripts/Functions/Tuneup/tuneup_doShell.sh @@ -0,0 +1,33 @@ +#!/bin/bash +# +# tuneup_doShell.sh -- This function performs maintainance tasks for +# Shell script files. +# +# Copyright (C) 2009-2011 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 tuneup_doShell { + + # Rebuild top comment inside shell scripts, mainly to update + # copyright information. + tuneup_doShellTopComment + +} diff --git a/Scripts/Functions/Tuneup/tuneup_doShellTopComment.sh b/Scripts/Functions/Tuneup/tuneup_doShellTopComment.sh new file mode 100755 index 0000000..a00b0d6 --- /dev/null +++ b/Scripts/Functions/Tuneup/tuneup_doShellTopComment.sh @@ -0,0 +1,57 @@ +#!/bin/bash +# +# tuneup_doShellTopComment.sh -- This function tunnes up the top +# comment section inside shell scripts (*.sh) using a predefined +# template. +# +# Copyright (C) 2009-2011 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 tuneup_doShellTopComment { + + # Define absolute path to template file. + local TEMPLATE="${FUNCCONFIG}/shell_topcomment.sed" + + # Check template file existence. + cli_checkFiles $TEMPLATE 'f' + + # Define file name to template instance. + local INSTANCE=$(cli_getTemporalFile $TEMPLATE) + + # Create template instance. + cp $TEMPLATE $INSTANCE + + # Check template instance. We cannot continue if template instance + # couldn't be created. + cli_checkFiles $INSTANCE 'f' + + # Expand translation markers in template instance. + cli_replaceTMarkers $INSTANCE + + # Apply template instance to file. + sed -r -i -f $INSTANCE $FILE + + # Remove template instance. + if [[ -f ${INSTANCE} ]];then + rm ${INSTANCE} + fi + +}