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

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