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

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