Blame Manuals/Repository/trunk/Scripts/Bash/Functions/Shell.texi

ad1d7b
@subsection Goals
ad1d7b
ad1d7b
This section exists to organize files related to @code{shell}
ad1d7b
functionality of @file{centos-art.sh} script.
ad1d7b
ad1d7b
@subsection Description
ad1d7b
ad1d7b
The @code{shell} functionality of @file{centos-art.sh} script helps
ad1d7b
you to maintain bash scripts inside repository. For example, suppose
ad1d7b
you've created many functionalities for @file{centos-art.sh} script,
ad1d7b
and you want to use a common copyright and license note for
ad1d7b
consistency in all your script files. If you have a bunch of files,
ad1d7b
doing this one by one wouldn't be a big deal. In contrast, if the
ad1d7b
amount of files grows, updating the copyright and license note for all
ad1d7b
of them would be a task rather tedious. The @code{shell} functionality
ad1d7b
exists to solve maintainance tasks just as the one previously
ad1d7b
mentioned.
ad1d7b
ad1d7b
When you use @code{shell} functionality to update copyright inside
ad1d7b
script files, it is required that your script files contain (at least)
ad1d7b
the following top commentary structure:
ad1d7b
ad1d7b
@float Figure,fig:trunk/Scripts/Bash/Functions/Shell:1
ad1d7b
@verbatim
ad1d7b
 1| #!/bin/bash
ad1d7b
 2| #
ad1d7b
 3| # doSomething.sh -- The function description goes here.
ad1d7b
 4| # 
ad1d7b
 5| # Copyright
ad1d7b
 6| #
ad1d7b
 7| # ...
ad1d7b
 8| #
ad1d7b
 9| # ----------------------------------------------------------------------
ad1d7b
10| # $Id$
ad1d7b
11| # ----------------------------------------------------------------------
ad1d7b
12|
ad1d7b
13| function doSomething {
ad1d7b
14|     
ad1d7b
15| }
ad1d7b
@end verbatim
ad1d7b
@caption{The functions script base comment structure}
ad1d7b
@end float
ad1d7b
ad1d7b
Relevant lines in the above structure are lines from 5 to 9.
ad1d7b
Everything else in the file is left immutable.
ad1d7b
ad1d7b
When you are updating copyright through @code{shell}
ad1d7b
functionality,  the @file{centos-art.sh} script replaces everything
ad1d7b
in-between line 5 ---the first one matching @samp{^# Copyright .+$}
ad1d7b
string--- and line 9---the first long dash separator matching @samp{^#
ad1d7b
-+$}--- with the content of copyright template instance.
ad1d7b
ad1d7b
@quotation
ad1d7b
@strong{Caution} Be sure to add the long dash separator that matches
ad1d7b
@samp{^# -+$} regular expression @emph{before} the function
ad1d7b
definition. Otherwise, if the @samp{Copyright} line is present but no
ad1d7b
long dash separator exists, @file{centos-art.sh} will remove anything
ad1d7b
in-between the @samp{Copyright} line and the end of file. This way you
ad1d7b
may lost your function definitions entirely.
ad1d7b
@end quotation
ad1d7b
ad1d7b
The copyright template instance is created from one copyright template
ad1d7b
stored in the @file{Config/tpl_forCopyright.sed} file.  The template
ad1d7b
instance is created once, and later removed when no longer needed. At
ad1d7b
this moment, when template instance is created, the
ad1d7b
@file{centos-art.sh} script takes advantage of automation in order to
ad1d7b
set copyright full name and date dynamically.
ad1d7b
ad1d7b
When you use @code{shell} functionality to update copyright, the first
ad1d7b
thing @file{shell} functionality does is requesting copyright
ad1d7b
information to user, and later, if values were left empty (i.e., no
ad1d7b
value was typed before pressing @key{RET} key), the @file{shell}
ad1d7b
functionality uses its own default values.
ad1d7b
ad1d7b
When @code{shell} functionality uses its own default values, the final
ad1d7b
copyright note looks like the following:
ad1d7b
ad1d7b
@float Figure,fig:trunk/Scripts/Bash/Functions/Shell:2
ad1d7b
@verbatim
ad1d7b
 1| #!/bin/bash
ad1d7b
 2| #
ad1d7b
 3| # doSomthing.sh -- The function description goes here.
ad1d7b
 4| #
ad1d7b
 5| # Copyright (C) 2003, 2010 The CentOS Project
ad1d7b
 6| # 
ad1d7b
 7| # This program is free software; you can redistribute it and/or modify
ad1d7b
 8| # it under the terms of the GNU General Public License as published by
ad1d7b
 9| # the Free Software Foundation; either version 2 of the License, or
ad1d7b
10| # (at your option) any later version.
ad1d7b
11| # 
ad1d7b
12| # This program is distributed in the hope that it will be useful, but
ad1d7b
13| # WITHOUT ANY WARRANTY; without even the implied warranty of
ad1d7b
14| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
ad1d7b
15| # General Public License for more details.
ad1d7b
16| #
ad1d7b
17| # You should have received a copy of the GNU General Public License
ad1d7b
18| # along with this program; if not, write to the Free Software
ad1d7b
19| # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
ad1d7b
20| # USA.
ad1d7b
21| #
ad1d7b
22| # ----------------------------------------------------------------------
ad1d7b
23| # $Id$
ad1d7b
24| # ----------------------------------------------------------------------
ad1d7b
25|
ad1d7b
26| function doSomething {
ad1d7b
27|
ad1d7b
28| }
ad1d7b
@end verbatim
ad1d7b
@caption{The function script comment example}
ad1d7b
@end float
ad1d7b
ad1d7b
Relevant lines in the above structure are lines from 5 to 22.  Pay
ad1d7b
attention how the copyright line was built, and how the license was
ad1d7b
added into the top comment where previously was just three dots.
ad1d7b
Everything else in the file was left immutable. 
ad1d7b
ad1d7b
To change copyright information (i.e., full name or year information),
ad1d7b
run the @code{shell} functionality over the root directory containing
ad1d7b
the script files you want to update copyright in and enter the
ad1d7b
appropriate information when it be requested. You can run the
ad1d7b
@code{shell} functionality as many times as you need to.
ad1d7b
ad1d7b
To change copyright license (i.e., the text in-between lines 7 and
ad1d7b
20), you need to edit the @file{Config/tpl_forCopyright.sed} file, set
ad1d7b
the appropriate information, and run the @code{shell} functionality
ad1d7b
once again for changes to take effect over the files you specify.
ad1d7b
ad1d7b
@quotation
ad1d7b
@strong{Important} The @file{centos-art.sh} script is released as: 
ad1d7b
ad1d7b
@verbatim
ad1d7b
GNU GENERAL PUBLIC LICENSE
ad1d7b
Version 2, June 1991
ad1d7b
ad1d7b
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
ad1d7b
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
ad1d7b
@end verbatim
ad1d7b
ad1d7b
Do not change the license information under which @file{centos-art.sh}
ad1d7b
script is released. Instead, if you think a different license must be
ad1d7b
used, please share your reasons at @email{centos-devel@@centos-art.sh,
ad1d7b
CentOS Developers mailing list}.
ad1d7b
@end quotation
ad1d7b
ad1d7b
@subsection Usage
ad1d7b
ad1d7b
@table @command
ad1d7b
@item centos-art sh --update-copyright='path/to/dir'
ad1d7b
@itemx centos-art sh --update-copyright='path/to/dir' --filter='regex'
ad1d7b
Use these commands to update copyright information in @samp{.sh} files
ad1d7b
under @samp{path/to/dir} directory. 
ad1d7b
@end table
ad1d7b
ad1d7b
When you provide @option{--filter='regex'} argument, the list of files
ad1d7b
to process is reduced as specified in @samp{regex} regular expression.
ad1d7b
Inside @file{centos-art.sh} script, the @samp{regex} regular
ad1d7b
expression is used in combination with @command{find} command to look
ad1d7b
for files matching the regular expression path pattern.
ad1d7b
ad1d7b
@quotation
ad1d7b
@strong{Warning} In order for @samp{regex} regular expression to match
ad1d7b
a file, the @samp{regex} regular expresion must match the whole file
ad1d7b
path not just the file name. 
ad1d7b
@end quotation
ad1d7b
ad1d7b
For example, if you want to match all @file{render.conf.sh} files
ad1d7b
inside @file{path/to/dir}, use the @code{.+/render.conf} regular
ad1d7b
expression.  Later, @file{centos-art.sh} script uses this value inside
ad1d7b
@code{^$REGEX\.sh$} expression in order to build the final regular
ad1d7b
expression (i.e., @code{^.+/render.conf\.sh$}) that is evaluated
ad1d7b
against available file paths inside the list of files to process.
ad1d7b
ad1d7b
Exceptionally, when you provide @option{--filter='regex'} in the way
ad1d7b
that @samp{regex}, appended to @samp{path/to/dir/} (i.e.
ad1d7b
@samp{path/to/dir/regex}), matches a regular file; the
ad1d7b
@file{centos-art.sh} script uses the file matching as only file in the
ad1d7b
list of files to process. 
ad1d7b
ad1d7b
@subsection See also
ad1d7b
ad1d7b
@menu
ad1d7b
* trunk Scripts Bash::
ad1d7b
* trunk Scripts Bash Functions::
ad1d7b
@end menu