Blame Automation/Manuals/Understanding_Modules/understanding_modules.asciidoc

Alain Reguera Delgado 393983
Understanding Modules
Alain Reguera Delgado 393983
=====================
Alain Reguera Delgado 393983
Alain Reguera Delgado <al@centos.org.cu>
Alain Reguera Delgado a76055
v0.1, Oct 2013
Alain Reguera Delgado 393983
Alain Reguera Delgado a76055
Overview
Alain Reguera Delgado a76055
--------
Alain Reguera Delgado 393983
Alain Reguera Delgado a76055
From version 0.5, the *centos-art.sh* script introduces the idea of
Alain Reguera Delgado a76055
modules to its base design. Modules are a collection of functions
Alain Reguera Delgado a76055
written in Bash that can call one another to create individual
Alain Reguera Delgado a76055
execution environments. They may be nested to achieve high levels of
Alain Reguera Delgado 393983
maintainability and extensibility. This make possible for modules
Alain Reguera Delgado 393983
writers to divide complicated tasks into smaller tasks that can be
Alain Reguera Delgado 393983
easier to debug, maintain and share with other modules efficiently
Alain Reguera Delgado 393983
(e.g., instead of loading modules all at once, they are only loaded at
Alain Reguera Delgado 393983
demand and unset once they conclude their execution).
Alain Reguera Delgado 393983
Alain Reguera Delgado 393983
This article describes the modular design of *centos-art.sh* script.
Alain Reguera Delgado a76055
It is a good place for you to start if you are planning to contribute
Alain Reguera Delgado a76055
new module environments to *centos-art.sh* script or want to know more
Alain Reguera Delgado a76055
about how it works. The next section delves into what a module
Alain Reguera Delgado a76055
environment is, the three module types you can find in it and the
Alain Reguera Delgado a76055
correct way of execute each one of them.
Alain Reguera Delgado a76055
Alain Reguera Delgado a76055
[[module-environment]]
Alain Reguera Delgado a76055
Module Environment
Alain Reguera Delgado a76055
------------------
Alain Reguera Delgado a76055
Alain Reguera Delgado a76055
When you execute the *centos-art.sh* script you create an execution
Alain Reguera Delgado a76055
environment in which variables and functions are defined. The
Alain Reguera Delgado a76055
execution environment is the higher environment inside *centos-art.sh*
Alain Reguera Delgado 1e834d
script. It is considered to have a ``global'' scope, so variables and
Alain Reguera Delgado a76055
functions defined in it are always available for any function
Alain Reguera Delgado 1e834d
execution made from it. You can control the execution environment of
Alain Reguera Delgado 1e834d
*centos-art.sh* script through files +centos-art.sh+ and
Alain Reguera Delgado 1e834d
+centos-art.conf.sh+. These files don't provide too much functionality
Alain Reguera Delgado 1e834d
so module environments are executed from +centos-art.sh+, to extend
Alain Reguera Delgado 1e834d
its functionality.
Alain Reguera Delgado a76055
Alain Reguera Delgado a76055
Module environments are made of small functions that perform small
Alain Reguera Delgado 1e834d
tasks and can be further executed in a specific order to produce the
Alain Reguera Delgado a76055
desired result.  Module environments are executed and destroyed at
Alain Reguera Delgado a76055
demand.  Inside *centos-art.sh*, module environments can be either
Alain Reguera Delgado a76055
``parent modules,'' ``child modules,'' or ``sibling modules.''
Alain Reguera Delgado a76055
Alain Reguera Delgado a76055
Parent Modules
Alain Reguera Delgado a76055
~~~~~~~~~~~~~~
Alain Reguera Delgado a76055
Alain Reguera Delgado a76055
Parent modules are initiated by executing the
Alain Reguera Delgado a76055
*tcar_setModuleEnvironment* function with the *-t parent* option set
Alain Reguera Delgado a76055
on it. Parent modules are very simple in design and you can use them
Alain Reguera Delgado a76055
to implement simple solutions quickly. Normally, when you execute a
Alain Reguera Delgado a76055
parent module, you initiate the highest module environment possible
Alain Reguera Delgado a76055
inside *centos-art.sh* script.  Because of such high scope, parent
Alain Reguera Delgado a76055
modules are frequently used to define module's global variables,
Alain Reguera Delgado a76055
interpret module-specific options passed through the command-line and
Alain Reguera Delgado a76055
execute the appropriate actions based on them.
Alain Reguera Delgado a76055
Alain Reguera Delgado a76055
In <<debug-parent-modules>>, we have executed the *hello* module with
Alain Reguera Delgado a76055
the *--greeting=hi* and *--debug* options through the command-line. In
Alain Reguera Delgado a76055
this example, *centos-art.sh* script executes a parent module named
Alain Reguera Delgado a76055
*hello*, processes the module-specific options passed through the
Alain Reguera Delgado a76055
command-line, prints a greeting message to standard output and exits
Alain Reguera Delgado a76055
successfully.
Alain Reguera Delgado a76055
Alain Reguera Delgado a76055
[[debug-parent-modules]]
Alain Reguera Delgado a76055
.Debugging execution of parent modules
Alain Reguera Delgado a76055
======================================================================
Alain Reguera Delgado a76055
----------------------------------------------------------------------
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:53:28 PM CDT =========================>      [0] | main
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:53:28 PM CDT TCAR_MODULE_BASEDIR             Automation/Modules
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:53:28 PM CDT TCAR_MODULE_NAME                [0]=hello
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:53:28 PM CDT TCAR_MODULE_TYPE                parent
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:53:28 PM CDT TCAR_MODULE_ARGUMENT            --greeting=hi  
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:53:28 PM CDT TCAR_MODULE_LIST                hello|help|locale|prepare|render|tuneup|vcs
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:53:28 PM CDT TCAR_MODULE_DIR                 Automation/Modules/Hello
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:53:28 PM CDT TCAR_MODULE_DIR_MODULES         Automation/Modules/Hello/Modules
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:53:28 PM CDT TCAR_MODULE_DIR_MANUALS         Automation/Modules/Hello/Manuals
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:53:28 PM CDT TCAR_MODULE_DIR_LOCALES         Automation/Modules/Hello/Locales
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:53:28 PM CDT TCAR_MODULE_DIR_CONFIGS         Automation/Modules/Hello/Configs
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:53:28 PM CDT TCAR_MODULE_INIT_FILE           Automation/Modules/Hello/hello.sh
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:53:28 PM CDT TEXTDOMAIN                      hello.sh
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:53:28 PM CDT TEXTDOMAINDIR                   Automation/Modules/Hello/Locales
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:53:28 PM CDT export -f                       hello
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:53:28 PM CDT export -f                       hello_getOptions
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:53:28 PM CDT ------------------------->      hello --greeting=hi  
Alain Reguera Delgado a76055
hi             
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:53:28 PM CDT <-------------------------      hello 
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:53:28 PM CDT unset -f                        hello
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:53:28 PM CDT unset -f                        hello_getOptions
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:53:28 PM CDT <=========================      [0] | main
Alain Reguera Delgado a76055
----------------------------------------------------------------------
Alain Reguera Delgado a76055
======================================================================
Alain Reguera Delgado 393983
Alain Reguera Delgado a76055
<<debug-parent-modules>> describes an entire module environment in
Alain Reguera Delgado a76055
action. With this information you can create your own module
Alain Reguera Delgado a76055
environment, already. However, when your module is getting too much
Alain Reguera Delgado a76055
complicated you probably want to divide it in smaller pieces that you
Alain Reguera Delgado a76055
can execute accordingly, based on the purpose you defined for it. Such
Alain Reguera Delgado a76055
kind of division can be implemented through ``modules' related
Alain Reguera Delgado a76055
functions.''
Alain Reguera Delgado a76055
Alain Reguera Delgado a76055
Module's related functions are stored in the same directory of your
Alain Reguera Delgado a76055
module's initialization file and they are very useful when you are
Alain Reguera Delgado a76055
refactoring it.  Definitions of module's related functions are loaded
Alain Reguera Delgado a76055
before the initialization file does, so it is a good practice to
Alain Reguera Delgado a76055
create them only when you are absolutely sure they will be executed in
Alain Reguera Delgado a76055
your module. Otherwise they may be loaded and never be used, which
Alain Reguera Delgado a76055
make the script to waste memory unnecessarily. In these cases, when
Alain Reguera Delgado a76055
you need to divide the logic of a module in smaller pieces where these
Alain Reguera Delgado a76055
pieces may or may not be executed based on specific conditions, all
Alain Reguera Delgado 1e834d
taking place in the same iteration, then using ``_child modules_'' is
Alain Reguera Delgado 1e834d
a more suitable approach.
Alain Reguera Delgado a76055
Alain Reguera Delgado a76055
[[child-modules]]
Alain Reguera Delgado a76055
Child Modules
Alain Reguera Delgado a76055
~~~~~~~~~~~~~
Alain Reguera Delgado a76055
Alain Reguera Delgado a76055
Child modules are initiated by executing the
Alain Reguera Delgado a76055
*tcar_setModuleEnvironment* function with the *-t child* option set on
Alain Reguera Delgado a76055
it.  Child modules have the characteristic of being nested modules.
Alain Reguera Delgado a76055
They cannot be executed from the command-line. Normally, child modules
Alain Reguera Delgado a76055
are executed from parent modules but they can be executed from other
Alain Reguera Delgado a76055
child modules, too.  When several child modules are executed in one
Alain Reguera Delgado 1e834d
single iteration of *centos-art.sh*, they create a chain of modules.
Alain Reguera Delgado a76055
A chain of modules is very useful in situations where you want to
Alain Reguera Delgado a76055
divide one large task into smaller tasks and also control which of
Alain Reguera Delgado a76055
these smaller tasks is executed based on specific conditions (e.g.,
Alain Reguera Delgado a76055
you may want to render images or documentation, but not both, in one
Alain Reguera Delgado 1e834d
single iteration of *centos-art.sh* script).  In a chain of modules,
Alain Reguera Delgado a76055
lower modules in the chain (those started last) have access to
Alain Reguera Delgado a76055
information set by modules higher in the chain (those started first),
Alain Reguera Delgado a76055
but not the opposite. When processing information this way, modules
Alain Reguera Delgado a76055
aren't destroyed until the last module executed in the chain has
Alain Reguera Delgado a76055
finished its work (e.g., all the commands inside it have been
Alain Reguera Delgado a76055
executed). At that point, child modules are destroyed in the reverse
Alain Reguera Delgado a76055
order they were executed.
Alain Reguera Delgado a76055
Alain Reguera Delgado a76055
For example, when you execute the *hello* module with both *--debug*
Alain Reguera Delgado a76055
and *--upper* option, *centos-art.sh* script creates a chain of three
Alain Reguera Delgado a76055
modules to produce the greeting message.  Firstly, it begins by
Alain Reguera Delgado a76055
executing the parent module named *hello*, then it continues with the
Alain Reguera Delgado a76055
child module named *output* which in turn executes the child module
Alain Reguera Delgado a76055
name *lower* to finally print the expected greeting message.  In this
Alain Reguera Delgado a76055
example, the module named *lower* is the last module in the chain of
Alain Reguera Delgado a76055
executed modules. It has access to all information defined by earlier
Alain Reguera Delgado a76055
modules (e.g., in *hello* and *output* modules) and none of its earlier
Alain Reguera Delgado a76055
modules will be destroyed until it has finished its work. This process
Alain Reguera Delgado a76055
becomes more visible when you take a look at <<debug-child-modules>>.
Alain Reguera Delgado a76055
Alain Reguera Delgado a76055
[[debug-child-modules]]
Alain Reguera Delgado a76055
.Debugging execution of child modules
Alain Reguera Delgado 393983
======================================================================
Alain Reguera Delgado a76055
----------------------------------------------------------------------
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT =========================>      [0] | main
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_BASEDIR             Automation/Modules
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_NAME                [0]=hello
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_TYPE                parent
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_ARGUMENT            --upper --greeting=hi  
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_LIST                hello|help|locale|prepare|render|tuneup|vcs
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_DIR                 Automation/Modules/Hello
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_DIR_MODULES         Automation/Modules/Hello/Modules
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_DIR_MANUALS         Automation/Modules/Hello/Manuals
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_DIR_LOCALES         Automation/Modules/Hello/Locales
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_DIR_CONFIGS         Automation/Modules/Hello/Configs
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_INIT_FILE           Automation/Modules/Hello/hello.sh
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TEXTDOMAIN                      hello.sh
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TEXTDOMAINDIR                   Automation/Modules/Hello/Locales
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT export -f                       hello
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT export -f                       hello_getOptions
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT ------------------------->      hello --upper --greeting=hi  
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT =========================>      [1] | hello
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_BASEDIR             Automation/Modules/Hello/Modules
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_NAME                [1]=output
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_TYPE                child
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_ARGUMENT             
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_LIST                output
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_DIR                 Automation/Modules/Hello/Modules/Output
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_DIR_MODULES         Automation/Modules/Hello/Modules/Output/Modules
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_DIR_MANUALS         Automation/Modules/Hello/Modules/Output/Manuals
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_DIR_LOCALES         Automation/Modules/Hello/Modules/Output/Locales
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_DIR_CONFIGS         Automation/Modules/Hello/Modules/Output/Configs
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_INIT_FILE           Automation/Modules/Hello/Modules/Output/output.sh
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TEXTDOMAIN                      output.sh
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TEXTDOMAINDIR                   Automation/Modules/Hello/Modules/Output/Locales
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT export -f                       output
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT ------------------------->      output  
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT =========================>      [2] | output
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_BASEDIR             Automation/Modules/Hello/Modules/Output/Modules
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_NAME                [2]=upper
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_TYPE                child
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_ARGUMENT             
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_LIST                camel|lower|random|upper
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_DIR                 Automation/Modules/Hello/Modules/Output/Modules/Upper
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:41 PM CDT TCAR_MODULE_DIR_MODULES         Automation/Modules/Hello/Modules/Output/Modules/Upper/Modules
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:42 PM CDT TCAR_MODULE_DIR_MANUALS         Automation/Modules/Hello/Modules/Output/Modules/Upper/Manuals
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:42 PM CDT TCAR_MODULE_DIR_LOCALES         Automation/Modules/Hello/Modules/Output/Modules/Upper/Locales
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:42 PM CDT TCAR_MODULE_DIR_CONFIGS         Automation/Modules/Hello/Modules/Output/Modules/Upper/Configs
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:42 PM CDT TCAR_MODULE_INIT_FILE           Automation/Modules/Hello/Modules/Output/Modules/Upper/upper.sh
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:42 PM CDT TEXTDOMAIN                      upper.sh
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:42 PM CDT TEXTDOMAINDIR                   Automation/Modules/Hello/Modules/Output/Modules/Upper/Locales
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:42 PM CDT export -f                       upper
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:42 PM CDT ------------------------->      upper  
Alain Reguera Delgado a76055
HI             
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:42 PM CDT <-------------------------      upper  
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:42 PM CDT unset -f                        upper
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:42 PM CDT <=========================      [2] | output 
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:42 PM CDT <-------------------------      output  
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:42 PM CDT unset -f                        output
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:42 PM CDT <=========================      [1] | hello 
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:42 PM CDT <-------------------------      hello 
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:42 PM CDT unset -f                        hello
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:42 PM CDT unset -f                        hello_getOptions
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:52:42 PM CDT <=========================      [0] | main 
Alain Reguera Delgado a76055
----------------------------------------------------------------------
Alain Reguera Delgado 393983
======================================================================
Alain Reguera Delgado 393983
Alain Reguera Delgado a76055
The module environment described in <<debug-child-modules>> shows the
Alain Reguera Delgado a76055
child modules' ability of reducing scope as they get deeper in the
Alain Reguera Delgado a76055
chain of executed modules. However, child modules lack the possibility
Alain Reguera Delgado a76055
of nest modules that share the same scope. For example, in the *hello*
Alain Reguera Delgado a76055
module described above, you cannot execute the modules *lower*  or
Alain Reguera Delgado a76055
*upper* from *camel* module, as if they were child modules of it.
Alain Reguera Delgado a76055
That is not possible because they all have the same scope, which is,
Alain Reguera Delgado a76055
to print the greeting message to standard output. Child modules are
Alain Reguera Delgado a76055
conceived to reduce the module scope as new child modules are
Alain Reguera Delgado a76055
executed. When you need to execute new module environments and, also,
Alain Reguera Delgado a76055
retain the last scope from which the new module is executed, you need
Alain Reguera Delgado a76055
to use ``_sibling modules_,'' instead.
Alain Reguera Delgado a76055
Alain Reguera Delgado a76055
Sibling Modules
Alain Reguera Delgado a76055
~~~~~~~~~~~~~~~
Alain Reguera Delgado a76055
Alain Reguera Delgado a76055
Sibling modules are initiated by executing the
Alain Reguera Delgado a76055
*tcar_setModuleEnvironment* function with the *-t sibling* option set
Alain Reguera Delgado a76055
on it.  Sibling modules are another type of nested modules but, in
Alain Reguera Delgado a76055
contrast with child modules, sibling modules cannot be executed from
Alain Reguera Delgado a76055
parent modules. Normally, sibling modules are executed from other
Alain Reguera Delgado a76055
sibling modules but, considering the context, they can be executed
Alain Reguera Delgado a76055
from child module too, to initiate sibling processing. When several
Alain Reguera Delgado a76055
siblings modules are executed, they also build a chain of modules. In
Alain Reguera Delgado a76055
contrast with the chain of child modules, the chain of sibling modules
Alain Reguera Delgado a76055
destroys the last sibling module executed before executing the next
Alain Reguera Delgado a76055
sibling module. This make the chain to stop its growing at sibling
Alain Reguera Delgado a76055
module processing, unless you call a child module from a sibling
Alain Reguera Delgado a76055
module. In this case, the chain expansion would continue as long as
Alain Reguera Delgado a76055
the number of child modules you execute. This process becomes more
Alain Reguera Delgado a76055
visible when you take a look at <<debug-sibling-modules>>.
Alain Reguera Delgado a76055
Alain Reguera Delgado a76055
In <<debug-sibling-modules>>, we've executed the *hello* module with
Alain Reguera Delgado a76055
the *--greeting=hi*, *--camel*, and *--debug* options. In this
Alain Reguera Delgado a76055
example, *centos-art.sh* script executes the *hello* module then the
Alain Reguera Delgado a76055
*output* module which in turn executes the *camel* module. At this
Alain Reguera Delgado a76055
point, can appreciate how the chain of modules stop growing. Observe
Alain Reguera Delgado a76055
that *camel* module has gained the position 2 in the chain of modules
Alain Reguera Delgado a76055
and executes the *upper* module which takes the position 3, as
Alain Reguera Delgado a76055
expected. Now, when *upper* module finishes its work it is destroyed
Alain Reguera Delgado a76055
and the module's counter is reset to its previous value which is 2
Alain Reguera Delgado a76055
(the one set by *camel* module). Then, *camel* executes the *lower*
Alain Reguera Delgado a76055
module which take position 3 at the chain of modules until it
Alain Reguera Delgado a76055
finishes. When it finishes, the *camel* module finishes its work and
Alain Reguera Delgado a76055
is destroyed, then *output*, then *hello*.
Alain Reguera Delgado a76055
Alain Reguera Delgado a76055
[[debug-sibling-modules]]
Alain Reguera Delgado a76055
.Debugging execution of sibling modules
Alain Reguera Delgado 393983
======================================================================
Alain Reguera Delgado 393983
----------------------------------------------------------------------
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:42 PM CDT =========================>      [0] | main
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:42 PM CDT TCAR_MODULE_BASEDIR             Automation/Modules
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:42 PM CDT TCAR_MODULE_NAME                [0]=hello
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:42 PM CDT TCAR_MODULE_TYPE                parent
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:42 PM CDT TCAR_MODULE_ARGUMENT            --camel --greeting=hi  
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:42 PM CDT TCAR_MODULE_LIST                hello|help|locale|prepare|render|tuneup|vcs
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:42 PM CDT TCAR_MODULE_DIR                 Automation/Modules/Hello
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:42 PM CDT TCAR_MODULE_DIR_MODULES         Automation/Modules/Hello/Modules
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:42 PM CDT TCAR_MODULE_DIR_MANUALS         Automation/Modules/Hello/Manuals
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:42 PM CDT TCAR_MODULE_DIR_LOCALES         Automation/Modules/Hello/Locales
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:42 PM CDT TCAR_MODULE_DIR_CONFIGS         Automation/Modules/Hello/Configs
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:42 PM CDT TCAR_MODULE_INIT_FILE           Automation/Modules/Hello/hello.sh
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:42 PM CDT TEXTDOMAIN                      hello.sh
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:42 PM CDT TEXTDOMAINDIR                   Automation/Modules/Hello/Locales
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT export -f                       hello
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT export -f                       hello_getOptions
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT ------------------------->      hello --camel --greeting=hi  
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT =========================>      [1] | hello
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_BASEDIR             Automation/Modules/Hello/Modules
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_NAME                [1]=output
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_TYPE                child
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_ARGUMENT             
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_LIST                output
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_DIR                 Automation/Modules/Hello/Modules/Output
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_DIR_MODULES         Automation/Modules/Hello/Modules/Output/Modules
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_DIR_MANUALS         Automation/Modules/Hello/Modules/Output/Manuals
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_DIR_LOCALES         Automation/Modules/Hello/Modules/Output/Locales
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_DIR_CONFIGS         Automation/Modules/Hello/Modules/Output/Configs
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_INIT_FILE           Automation/Modules/Hello/Modules/Output/output.sh
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TEXTDOMAIN                      output.sh
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TEXTDOMAINDIR                   Automation/Modules/Hello/Modules/Output/Locales
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT export -f                       output
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT ------------------------->      output  
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT =========================>      [2] | output
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_BASEDIR             Automation/Modules/Hello/Modules/Output/Modules
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_NAME                [2]=camel
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_TYPE                child
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_ARGUMENT             
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_LIST                camel|lower|random|upper
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_DIR                 Automation/Modules/Hello/Modules/Output/Modules/Camel
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_DIR_MODULES         Automation/Modules/Hello/Modules/Output/Modules/Camel/Modules
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_DIR_MANUALS         Automation/Modules/Hello/Modules/Output/Modules/Camel/Manuals
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_DIR_LOCALES         Automation/Modules/Hello/Modules/Output/Modules/Camel/Locales
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_DIR_CONFIGS         Automation/Modules/Hello/Modules/Output/Modules/Camel/Configs
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_INIT_FILE           Automation/Modules/Hello/Modules/Output/Modules/Camel/camel.sh
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TEXTDOMAIN                      camel.sh
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TEXTDOMAINDIR                   Automation/Modules/Hello/Modules/Output/Modules/Camel/Locales
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT export -f                       camel
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT ------------------------->      camel  
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT =========================>      [3] | camel
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_BASEDIR             Automation/Modules/Hello/Modules/Output/Modules
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_NAME                [3]=upper
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_TYPE                sibling
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_ARGUMENT             
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_LIST                camel|lower|random|upper
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_DIR                 Automation/Modules/Hello/Modules/Output/Modules/Upper
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_DIR_MODULES         Automation/Modules/Hello/Modules/Output/Modules/Upper/Modules
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_DIR_MANUALS         Automation/Modules/Hello/Modules/Output/Modules/Upper/Manuals
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_DIR_LOCALES         Automation/Modules/Hello/Modules/Output/Modules/Upper/Locales
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_DIR_CONFIGS         Automation/Modules/Hello/Modules/Output/Modules/Upper/Configs
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_INIT_FILE           Automation/Modules/Hello/Modules/Output/Modules/Upper/upper.sh
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TEXTDOMAIN                      upper.sh
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TEXTDOMAINDIR                   Automation/Modules/Hello/Modules/Output/Modules/Upper/Locales
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT export -f                       upper
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT ------------------------->      upper  
Alain Reguera Delgado a76055
H              
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT <-------------------------      upper  
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT unset -f                        upper
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT <=========================      [3] | camel 
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT =========================>      [3] | camel
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_BASEDIR             Automation/Modules/Hello/Modules/Output/Modules
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_NAME                [3]=lower
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_TYPE                sibling
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_ARGUMENT             
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_LIST                camel|lower|random|upper
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_DIR                 Automation/Modules/Hello/Modules/Output/Modules/Lower
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:43 PM CDT TCAR_MODULE_DIR_MODULES         Automation/Modules/Hello/Modules/Output/Modules/Lower/Modules
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:44 PM CDT TCAR_MODULE_DIR_MANUALS         Automation/Modules/Hello/Modules/Output/Modules/Lower/Manuals
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:44 PM CDT TCAR_MODULE_DIR_LOCALES         Automation/Modules/Hello/Modules/Output/Modules/Lower/Locales
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:44 PM CDT TCAR_MODULE_DIR_CONFIGS         Automation/Modules/Hello/Modules/Output/Modules/Lower/Configs
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:44 PM CDT TCAR_MODULE_INIT_FILE           Automation/Modules/Hello/Modules/Output/Modules/Lower/lower.sh
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:44 PM CDT TEXTDOMAIN                      lower.sh
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:44 PM CDT TEXTDOMAINDIR                   Automation/Modules/Hello/Modules/Output/Modules/Lower/Locales
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:44 PM CDT export -f                       lower
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:44 PM CDT ------------------------->      lower  
Alain Reguera Delgado a76055
i              
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:44 PM CDT <-------------------------      lower  
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:44 PM CDT unset -f                        lower
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:44 PM CDT <=========================      [3] | camel 
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:44 PM CDT <-------------------------      camel  
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:44 PM CDT unset -f                        camel
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:44 PM CDT <=========================      [2] | output 
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:44 PM CDT <-------------------------      output  
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:44 PM CDT unset -f                        output
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:44 PM CDT <=========================      [1] | hello 
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:44 PM CDT <-------------------------      hello 
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:44 PM CDT unset -f                        hello
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:44 PM CDT unset -f                        hello_getOptions
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:51:44 PM CDT <=========================      [0] | main
Alain Reguera Delgado a76055
----------------------------------------------------------------------
Alain Reguera Delgado a76055
======================================================================
Alain Reguera Delgado a76055
Alain Reguera Delgado 1e834d
<<debug-sibling-modules>> shows a single iteration of *centos-art.sh*
Alain Reguera Delgado 1e834d
script executing different types of modules. Normally, one module is
Alain Reguera Delgado 1e834d
executed at some point and destroyed at the same point when it has
Alain Reguera Delgado 1e834d
finished its work, however, what if the next immediate module you are
Alain Reguera Delgado 1e834d
about to execute is the same module you are about to destroyed? This
Alain Reguera Delgado 1e834d
is, you need to execute the last module in the chain of executed
Alain Reguera Delgado 1e834d
modules again, but, this time, from itself.  In cases like this, the
Alain Reguera Delgado 1e834d
*centos-art.sh* script doesn't destroy the last module.  It cannot,
Alain Reguera Delgado 1e834d
because you are certainly executing a new module from itself, so it
Alain Reguera Delgado 1e834d
has to wait for this new call to finish in order to be destroyed. This
Alain Reguera Delgado 1e834d
kind of processing is known as _processing modules recursively._
Alain Reguera Delgado a76055
Alain Reguera Delgado a76055
Recursive Modules
Alain Reguera Delgado a76055
~~~~~~~~~~~~~~~~~
Alain Reguera Delgado a76055
Alain Reguera Delgado a76055
When one module environment executes itself we are in presence of a
Alain Reguera Delgado a76055
recursive module execution. The execution of modules recursively
Alain Reguera Delgado a76055
doesn't destroy the last module in the chain of executed modules and
Alain Reguera Delgado a76055
doesn't increment or decrement the module counter either. The module
Alain Reguera Delgado a76055
counter is somehow frozen until a different module environment is
Alain Reguera Delgado a76055
executed. In this cases, the last module environment remains in memory
Alain Reguera Delgado a76055
for the new module execution to make use of. This process becomes more visible
Alain Reguera Delgado a76055
when you take a look at <<debug-recursive-modules>>.
Alain Reguera Delgado a76055
Alain Reguera Delgado a76055
[CAUTION]
Alain Reguera Delgado a76055
When you execute modules recursively, you should be very careful not
Alain Reguera Delgado a76055
to get trapped into an endless loop.
Alain Reguera Delgado a76055
Alain Reguera Delgado a76055
In <<debug-recursive-modules>>, we've executed the *hello* module with
Alain Reguera Delgado a76055
the *--greeting=hello*, *--random*, and *--debug* options. In this
Alain Reguera Delgado a76055
example, *centos-art.sh* script executes a parent module named *hello*
Alain Reguera Delgado a76055
which in turn executes a child module named *output* which in turn
Alain Reguera Delgado a76055
executes a child module named *random*. At this point, the *random*
Alain Reguera Delgado a76055
modules executes itself five times (the number of characters passed as
Alain Reguera Delgado a76055
value to greeting option) to print out random letters from the
Alain Reguera Delgado a76055
greeting message. The output may have no much sense on itself but the
Alain Reguera Delgado a76055
related debugging information helps to understand the execution of
Alain Reguera Delgado a76055
modules recursively.
Alain Reguera Delgado a76055
Alain Reguera Delgado a76055
[[debug-recursive-modules]]
Alain Reguera Delgado a76055
.Processing execution of modules recursively
Alain Reguera Delgado a76055
======================================================================
Alain Reguera Delgado a76055
----------------------------------------------------------------------
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:03 PM CDT =========================>      [0] | main
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:03 PM CDT TCAR_MODULE_BASEDIR             Automation/Modules
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:03 PM CDT TCAR_MODULE_NAME                [0]=hello
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:03 PM CDT TCAR_MODULE_TYPE                parent
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:03 PM CDT TCAR_MODULE_ARGUMENT            --random --greeting=Hello  
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:03 PM CDT TCAR_MODULE_LIST                hello|help|locale|prepare|render|tuneup|vcs
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:03 PM CDT TCAR_MODULE_DIR                 Automation/Modules/Hello
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:03 PM CDT TCAR_MODULE_DIR_MODULES         Automation/Modules/Hello/Modules
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:03 PM CDT TCAR_MODULE_DIR_MANUALS         Automation/Modules/Hello/Manuals
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TCAR_MODULE_DIR_LOCALES         Automation/Modules/Hello/Locales
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TCAR_MODULE_DIR_CONFIGS         Automation/Modules/Hello/Configs
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TCAR_MODULE_INIT_FILE           Automation/Modules/Hello/hello.sh
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TEXTDOMAIN                      hello.sh
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TEXTDOMAINDIR                   Automation/Modules/Hello/Locales
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT export -f                       hello
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT export -f                       hello_getOptions
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT ------------------------->      hello --random --greeting=Hello  
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT =========================>      [1] | hello
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TCAR_MODULE_BASEDIR             Automation/Modules/Hello/Modules
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TCAR_MODULE_NAME                [1]=output
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TCAR_MODULE_TYPE                child
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TCAR_MODULE_ARGUMENT             
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TCAR_MODULE_LIST                output
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TCAR_MODULE_DIR                 Automation/Modules/Hello/Modules/Output
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TCAR_MODULE_DIR_MODULES         Automation/Modules/Hello/Modules/Output/Modules
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TCAR_MODULE_DIR_MANUALS         Automation/Modules/Hello/Modules/Output/Manuals
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TCAR_MODULE_DIR_LOCALES         Automation/Modules/Hello/Modules/Output/Locales
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TCAR_MODULE_DIR_CONFIGS         Automation/Modules/Hello/Modules/Output/Configs
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TCAR_MODULE_INIT_FILE           Automation/Modules/Hello/Modules/Output/output.sh
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TEXTDOMAIN                      output.sh
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TEXTDOMAINDIR                   Automation/Modules/Hello/Modules/Output/Locales
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT export -f                       output
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT ------------------------->      output  
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT =========================>      [2] | output
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TCAR_MODULE_BASEDIR             Automation/Modules/Hello/Modules/Output/Modules
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TCAR_MODULE_NAME                [2]=random
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TCAR_MODULE_TYPE                child
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TCAR_MODULE_ARGUMENT             
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TCAR_MODULE_LIST                camel|lower|random|upper
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TCAR_MODULE_DIR                 Automation/Modules/Hello/Modules/Output/Modules/Random
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TCAR_MODULE_DIR_MODULES         Automation/Modules/Hello/Modules/Output/Modules/Random/Modules
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TCAR_MODULE_DIR_MANUALS         Automation/Modules/Hello/Modules/Output/Modules/Random/Manuals
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TCAR_MODULE_DIR_LOCALES         Automation/Modules/Hello/Modules/Output/Modules/Random/Locales
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TCAR_MODULE_DIR_CONFIGS         Automation/Modules/Hello/Modules/Output/Modules/Random/Configs
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TCAR_MODULE_INIT_FILE           Automation/Modules/Hello/Modules/Output/Modules/Random/random.sh
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TEXTDOMAIN                      random.sh
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT TEXTDOMAINDIR                   Automation/Modules/Hello/Modules/Output/Modules/Random/Locales
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT export -f                       random
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT ------------------------->      random  
Alain Reguera Delgado a76055
H              
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT ~~~~~~~~~~~~~~~~~~~~~~~~~>      random  
Alain Reguera Delgado a76055
H              
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT ~~~~~~~~~~~~~~~~~~~~~~~~~>      random  
Alain Reguera Delgado a76055
l              
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT ~~~~~~~~~~~~~~~~~~~~~~~~~>      random  
Alain Reguera Delgado a76055
l              
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT ~~~~~~~~~~~~~~~~~~~~~~~~~>      random  
Alain Reguera Delgado a76055
H              
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT <-------------------------      random  
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT unset -f                        random
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT <=========================      [2] | output 
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:04 PM CDT <-------------------------      output  
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:05 PM CDT unset -f                        output
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:05 PM CDT <=========================      [1] | hello 
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:05 PM CDT <-------------------------      hello 
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:05 PM CDT unset -f                        hello
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:05 PM CDT unset -f                        hello_getOptions
Alain Reguera Delgado a76055
Thu 10 Oct 2013 11:50:05 PM CDT <=========================      [0] | main 
Alain Reguera Delgado 393983
----------------------------------------------------------------------
Alain Reguera Delgado 393983
======================================================================
Alain Reguera Delgado 393983
Alain Reguera Delgado a76055
Recursive execution of modules occurs only when the module you are
Alain Reguera Delgado a76055
executing is considered sibling of the last module executed in the
Alain Reguera Delgado a76055
chain of executed modules and they both have the same name. The fact
Alain Reguera Delgado a76055
that no variable name is printed out in <<debug-recursive-modules>>
Alain Reguera Delgado a76055
means that they were not created. The change in the arrows shown in
Alain Reguera Delgado a76055
the example, from +->+ to +~>+, means that module's related functions
Alain Reguera Delgado a76055
weren't exported for the new module execution either. It also means
Alain Reguera Delgado a76055
that the initialization script is reusing both module's related
Alain Reguera Delgado a76055
functions variables from the last module's environment in the chain of
Alain Reguera Delgado a76055
executed modules. In this case *random* module itself.
Alain Reguera Delgado a76055
Alain Reguera Delgado a76055
Summary
Alain Reguera Delgado a76055
~~~~~~~
Alain Reguera Delgado a76055
Alain Reguera Delgado a76055
This section has covered the module environment inside *centos-art.sh*
Alain Reguera Delgado a76055
script, including module types and possible combinations of them. The
Alain Reguera Delgado a76055
next section takes these concepts and focuses on the implementation of
Alain Reguera Delgado a76055
them. Once you finish it, you should be able of writing your own
Alain Reguera Delgado a76055
module environments from scratch inside *centos-art.sh* script.
Alain Reguera Delgado a76055
Alain Reguera Delgado 1e834d
[[module-implementation]]
Alain Reguera Delgado a76055
Module Implementation
Alain Reguera Delgado a76055
---------------------
Alain Reguera Delgado a76055
Alain Reguera Delgado 1e834d
The *centos-art.sh* script implements module environments inside the
Alain Reguera Delgado 1e834d
``+Modules+'' directory. Inside this directory, each module
Alain Reguera Delgado 1e834d
environment has its own directory.  Inside each module directory there
Alain Reguera Delgado 1e834d
is one initialization file and, optionally, module-related stuff like
Alain Reguera Delgado 1e834d
functions, locales, documentation, configuration and dependent
Alain Reguera Delgado 1e834d
modules.  Inside the +Modules+ directory, module directories are
Alain Reguera Delgado 1e834d
written capitalized while initialization files, inside them, are
Alain Reguera Delgado 1e834d
written in lower case.  Even though module directories and
Alain Reguera Delgado 1e834d
initialization files are written differently, they both make a single
Alain Reguera Delgado 1e834d
module because they use the same single name.
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
For example, consider the creation of a module named *hello*. The
Alain Reguera Delgado 1e834d
purpose of this module is to print a greeting message to standard
Alain Reguera Delgado 1e834d
output and then exit successfully. To create such a module, we need to
Alain Reguera Delgado 1e834d
create a directory named ``Hello'' inside the ``Modules'' directory
Alain Reguera Delgado 1e834d
and put an initialization file named ``hello.sh'' inside it.  Because
Alain Reguera Delgado 1e834d
we want to execute the *hello* module from *centos-art.sh* script
Alain Reguera Delgado 1e834d
command-line, we put it in the first level of directories of +Modules+
Alain Reguera Delgado 1e834d
directory. See <<parent-module-layout>>.
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
[[parent-module-layout]]
Alain Reguera Delgado 1e834d
.Directory layout used by parent modules
Alain Reguera Delgado 393983
======================================================================
Alain Reguera Delgado 393983
----------------------------------------------------------------------
Alain Reguera Delgado 393983
.
Alain Reguera Delgado 1e834d
|-- COPYING                 <1>
Alain Reguera Delgado 1e834d
|-- Locales/                <2>
Alain Reguera Delgado 1e834d
|-- Manuals/                <3>
Alain Reguera Delgado 1e834d
|-- Modules/                <4>
Alain Reguera Delgado 1e834d
|   `-- Hello/              <5>
Alain Reguera Delgado 1e834d
|       `-- hello.sh        <6>
Alain Reguera Delgado 1e834d
|-- Scripts/                <7>
Alain Reguera Delgado 1e834d
|-- centos-art.conf.sh      <8>
Alain Reguera Delgado 1e834d
`-- centos-art.sh           <9>
Alain Reguera Delgado 393983
----------------------------------------------------------------------
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
<1> Script's copying conditions.
Alain Reguera Delgado 1e834d
<2> Script's localization files.
Alain Reguera Delgado 1e834d
<3> Script's documentation files.
Alain Reguera Delgado 1e834d
<4> Script's modules. Here is where you store parent modules.
Alain Reguera Delgado 1e834d
<5> Parent directory of module named hello.
Alain Reguera Delgado 1e834d
<6> Initialization file of module named hello.
Alain Reguera Delgado 1e834d
<7> Script's global functions.
Alain Reguera Delgado 1e834d
<8> Script's configuration file.
Alain Reguera Delgado 1e834d
<9> Script's initialization file.
Alain Reguera Delgado 393983
======================================================================
Alain Reguera Delgado 393983
Alain Reguera Delgado 1e834d
<<parent-module-layout>> presents a complete module layout you can use
Alain Reguera Delgado 1e834d
as reference to create your own module implementations. However, it is
Alain Reguera Delgado 1e834d
not complete yet.  At this point, when you execute *centos-art.sh*, it
Alain Reguera Delgado 1e834d
is able to find out *hello* module's initialization file and execute
Alain Reguera Delgado 1e834d
it but that prints an error message because the initialization file
Alain Reguera Delgado 1e834d
doesn't have a function definition inside. It is completely empty.  In
Alain Reguera Delgado 1e834d
order for *centos-art.sh* script to do something useful, you need to
Alain Reguera Delgado 1e834d
write a function definition inside the initialization file, as
Alain Reguera Delgado 1e834d
described in <<module-init-file>>.
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
[[module-init-file]]
Alain Reguera Delgado 1e834d
The Initialization File
Alain Reguera Delgado 1e834d
~~~~~~~~~~~~~~~~~~~~~~~
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
The module's initialization file contains the module's main function
Alain Reguera Delgado 1e834d
definition and a comment describing what it does on top of it.  This
Alain Reguera Delgado 1e834d
comment includes a small description about what the function does, a
Alain Reguera Delgado 1e834d
written by section, the copyright note and the legal status of the
Alain Reguera Delgado 1e834d
file. The function definition is set later and must be written using
Alain Reguera Delgado 1e834d
the long definition format (i.e., it must begin with the word
Alain Reguera Delgado 1e834d
``+function+,'' then the function name, and finally the ``+{+''
Alain Reguera Delgado 1e834d
character).  The name of the function is exactly the same of the
Alain Reguera Delgado 1e834d
initialization file but without the +.sh+ extension. These conditions
Alain Reguera Delgado 1e834d
are required in order for *centos-art.sh* script to execute the
Alain Reguera Delgado 1e834d
function definition and destroy it when it is no longer used.  See
Alain Reguera Delgado 1e834d
<<initialization-file>>.
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
The function definition is where you write all the commands you want
Alain Reguera Delgado 1e834d
the module runs, once executed.  The function definition can be as
Alain Reguera Delgado 1e834d
simple as just one single line of code or as complex as you can
Alain Reguera Delgado 1e834d
imagine. It is the place where you express your solutions. However,
Alain Reguera Delgado 1e834d
when writing initialization files, it is considered a good practice to
Alain Reguera Delgado 1e834d
avoid any sort of complexity.  Instead, try to write small and simple
Alain Reguera Delgado 1e834d
initialization files.  In case you notice the initialization file is
Alain Reguera Delgado 1e834d
growing up inevitably, you can reduce its code by refactoring it.  To
Alain Reguera Delgado 1e834d
do this, you can use resources like module related functions and child
Alain Reguera Delgado 1e834d
modules. These resources are described in
Alain Reguera Delgado 1e834d
<<extended-module-implementation>>, and they help you to keep the
Alain Reguera Delgado 1e834d
initialization file in a clean state, easy to understand, maintain and
Alain Reguera Delgado 1e834d
debug.
Alain Reguera Delgado 393983
Alain Reguera Delgado 393983
[[initialization-file]]
Alain Reguera Delgado 1e834d
.Initialization file used by hello module
Alain Reguera Delgado 393983
======================================================================
Alain Reguera Delgado 393983
----------------------------------------------------------------------
Alain Reguera Delgado 393983
#!/bin/bash
Alain Reguera Delgado 393983
######################################################################
Alain Reguera Delgado 393983
#
Alain Reguera Delgado 393983
#   hello.sh -- Print out greetings to standard output and exit
Alain Reguera Delgado 393983
#   successfully.
Alain Reguera Delgado 393983
#
Alain Reguera Delgado 393983
#   Written by:
Alain Reguera Delgado 393983
#   * Alain Reguera Delgado <al@centos.org.cu>, 2013
Alain Reguera Delgado 393983
#
Alain Reguera Delgado 393983
# Copyright (C) 2009-2013 The CentOS Artwork SIG
Alain Reguera Delgado 393983
#
Alain Reguera Delgado 393983
# This program is free software; you can redistribute it and/or modify
Alain Reguera Delgado 393983
# it under the terms of the GNU General Public License as published by
Alain Reguera Delgado 393983
# the Free Software Foundation; either version 2 of the License, or (at
Alain Reguera Delgado 393983
# your option) any later version.
Alain Reguera Delgado 393983
#
Alain Reguera Delgado 393983
# This program is distributed in the hope that it will be useful, but
Alain Reguera Delgado 393983
# WITHOUT ANY WARRANTY; without even the implied warranty of
Alain Reguera Delgado 393983
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Alain Reguera Delgado 393983
# General Public License for more details.
Alain Reguera Delgado 393983
#
Alain Reguera Delgado 393983
# You should have received a copy of the GNU General Public License
Alain Reguera Delgado 393983
# along with this program; if not, write to the Free Software
Alain Reguera Delgado 393983
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Alain Reguera Delgado 393983
#
Alain Reguera Delgado 393983
######################################################################
Alain Reguera Delgado 393983
Alain Reguera Delgado 393983
function hello {
Alain Reguera Delgado 393983
Alain Reguera Delgado 1e834d
    tcar_printMessage "`gettext "Hello, World!"`" --as-stdout-line
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
}
Alain Reguera Delgado 1e834d
----------------------------------------------------------------------
Alain Reguera Delgado 1e834d
======================================================================
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
The function definition described in <<initialization-file>> uses the
Alain Reguera Delgado 1e834d
*tcar_printMessage* global function to print localized versions of the
Alain Reguera Delgado 1e834d
string ``Hello, World!'' to standard output. Because there isn't no
Alain Reguera Delgado 1e834d
other command in the function definition, when the greeting message is
Alain Reguera Delgado 1e834d
printed out, *centos-art.sh* destroys the *hello* module and exit
Alain Reguera Delgado 1e834d
successfully. This process is more visible when also pass the
Alain Reguera Delgado 1e834d
*--debug* option. See <<debug-parent-modules>>.
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
Summary
Alain Reguera Delgado 1e834d
~~~~~~~
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
Congratulations! You've implemented a module environment inside
Alain Reguera Delgado 1e834d
*centos-art.sh* script. With the information you have so far, you are
Alain Reguera Delgado 1e834d
able to create your own module environment implementations. The next
Alain Reguera Delgado 1e834d
section delves into available resources you can use to optimize module
Alain Reguera Delgado 1e834d
environments when the initialization file starts growing inevitably
Alain Reguera Delgado 1e834d
and complexity daemons begin hammering your head.
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
[[module-directory-structure]]
Alain Reguera Delgado 1e834d
Module Directory Structure
Alain Reguera Delgado 1e834d
--------------------------
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
Child modules and sibling modules are nested modules. They are stored
Alain Reguera Delgado 1e834d
inside other modules. Frequently we first write parent modules and
Alain Reguera Delgado 1e834d
extend them through child modules. This, when function related files
Alain Reguera Delgado 1e834d
cannot fix the problem efficiently.  Module related function files are
Alain Reguera Delgado 1e834d
stored at the same level of initialization file inside the module's
Alain Reguera Delgado 1e834d
directory.
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
[[child-module-layout]]
Alain Reguera Delgado 1e834d
.The directory structure of child and sibling modules
Alain Reguera Delgado 1e834d
======================================================================
Alain Reguera Delgado 1e834d
----------------------------------------------------------------------
Alain Reguera Delgado 1e834d
.
Alain Reguera Delgado 1e834d
|-- COPYING
Alain Reguera Delgado 1e834d
|-- Locales/
Alain Reguera Delgado 1e834d
|-- Manuals/
Alain Reguera Delgado 1e834d
|-- Modules/
Alain Reguera Delgado 1e834d
|   `-- Hello/
Alain Reguera Delgado 1e834d
|       |-- Modules/
Alain Reguera Delgado 1e834d
|       |   `-- Output/             <1>
Alain Reguera Delgado 1e834d
|       |       |-- Lower/          <2>
Alain Reguera Delgado 1e834d
|       |       |   `-- lower.sh    <3>
Alain Reguera Delgado 1e834d
|       |       |-- Upper/          <4>
Alain Reguera Delgado 1e834d
|       |       |   `-- upper.sh    <5>
Alain Reguera Delgado 1e834d
|       |       `-- output.sh       <6>
Alain Reguera Delgado 1e834d
|       |-- hello.sh
Alain Reguera Delgado 1e834d
|       `-- hello_getOptions.sh
Alain Reguera Delgado 1e834d
|-- Scripts/
Alain Reguera Delgado 1e834d
|-- centos-art.conf.sh
Alain Reguera Delgado 1e834d
`-- centos-art.sh
Alain Reguera Delgado 1e834d
----------------------------------------------------------------------
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
<1> Child module of hello module.
Alain Reguera Delgado 1e834d
<2> Child module of output module and sibling module of upper module.
Alain Reguera Delgado 1e834d
<3> Initialization file of lower module.
Alain Reguera Delgado 1e834d
<4> Child module of output module and sibling module of lower module.
Alain Reguera Delgado 1e834d
<5> Initialization file of upper module.
Alain Reguera Delgado 1e834d
<6> Initialization file of output module.
Alain Reguera Delgado 1e834d
======================================================================
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
The +Modules+ Directory
Alain Reguera Delgado 1e834d
~~~~~~~~~~~~~~~~~~~~~~~
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
Inside the +Modules+ directory, regardless its level, there is one
Alain Reguera Delgado 1e834d
directory for each module environment. Inside each module's directory
Alain Reguera Delgado 1e834d
there is one initialization file and, optionally, one or more
Alain Reguera Delgado 1e834d
module-related function files. and any of the following
Alain Reguera Delgado 1e834d
sub-directories:
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
+Modules/+::
Alain Reguera Delgado 1e834d
    Organizes child modules for the current module. This directory
Alain Reguera Delgado 1e834d
    share the same structural restrictions of its parent (e.g., each
Alain Reguera Delgado 1e834d
    module stored here needs to have a module directory and a
Alain Reguera Delgado 1e834d
    initialization file inside it to be functional). To know more
Alain Reguera Delgado 1e834d
    about this directory, see <<extended-module-implementation>>.
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
+Locales/+::
Alain Reguera Delgado 1e834d
    Organizes localization files for the current module. This
Alain Reguera Delgado 1e834d
    directory contains POT, PO and MO files, the *centos-art.sh*
Alain Reguera Delgado 1e834d
    script needs to print localized messages. Must of these files are
Alain Reguera Delgado 1e834d
    automatically created by *locale* module.  To know more about this
Alain Reguera Delgado 1e834d
    directory, see <<module-locales-directory>>.
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
+Manuals/+::
Alain Reguera Delgado 1e834d
    Organizes documentation files for the current module. This
Alain Reguera Delgado 1e834d
    directory contains asciidoc files used to produce documentation in
Alain Reguera Delgado 1e834d
    html and manpage format. The manpage format is used by
Alain Reguera Delgado 1e834d
    centos-art.sh script to print module's documentation when the
Alain Reguera Delgado 1e834d
    *--help* option is passed to the command-line. To know more about
Alain Reguera Delgado 1e834d
    this directory, see <<module-manuals-directory>>.
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
+Configs/+::
Alain Reguera Delgado 1e834d
    Organizes configuration files for the current module. This
Alain Reguera Delgado 1e834d
    directory contains non-sh files the current module depends on to
Alain Reguera Delgado 1e834d
    complete the task it was created for (e.g., sed scripts, gawk
Alain Reguera Delgado 1e834d
    scripts, etc.). To know more about this directory, see
Alain Reguera Delgado 1e834d
    <<module-configs-directory>>.
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
Module directories and module initialization files must have the same
Alain Reguera Delgado 1e834d
name.  Module directories are written capitalized and initialization
Alain Reguera Delgado 1e834d
files in lowercase. Module related functions are written in camel-case
Alain Reguera Delgado 1e834d
and use the module name as suffix. More about module-related functions
Alain Reguera Delgado 1e834d
and child modules, later, in <<extended-module-implementation>>.
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
... describes the root location of *centos-art.sh*
Alain Reguera Delgado 1e834d
script and <<parent-module-layout>> how it looks like after adding the
Alain Reguera Delgado 1e834d
*hello* module to it.  In this last example, the directory named
Alain Reguera Delgado 1e834d
``Hello'' contains the files related to *hello* module environment
Alain Reguera Delgado 1e834d
(e.g., the initialization file). Other components like module related
Alain Reguera Delgado 1e834d
functions were intentionally omitted for simplicity sake. They are
Alain Reguera Delgado 1e834d
covered later, in <<extended-module-implementation>>.
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
[[module-locales-directory]]
Alain Reguera Delgado 1e834d
The +Locales+ Directory
Alain Reguera Delgado 1e834d
~~~~~~~~~~~~~~~~~~~~~~~
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
Module localization ...
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
[[module-manuals-directory]]
Alain Reguera Delgado 1e834d
The +Manuals+ Directory
Alain Reguera Delgado 1e834d
~~~~~~~~~~~~~~~~~~~~~~~
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
Module documentation ...
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
[[module-configs-directory]]
Alain Reguera Delgado 1e834d
Module +Configs+ Directory
Alain Reguera Delgado 1e834d
~~~~~~~~~~~~~~~~~~~~~~~~~~
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
Module configuration ...
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
Summary
Alain Reguera Delgado 1e834d
~~~~~~~
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
This section described how you can create a functional module
Alain Reguera Delgado 1e834d
environment from scratch. However, it doesn't explain how you can
Alain Reguera Delgado 1e834d
extend the module environment using related functions or child
Alain Reguera Delgado 1e834d
modules.  The next section introduces the concept of module functions
Alain Reguera Delgado 1e834d
and explain how you can use them to extend the functionality of an
Alain Reguera Delgado 1e834d
existing module environment.
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
[[extended-module-implementation]]
Alain Reguera Delgado 1e834d
Extended Module Implementation
Alain Reguera Delgado 1e834d
------------------------------
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
Module-specific functions are stored in the same location you store
Alain Reguera Delgado 1e834d
module's initialization file. Definitions of module-specific functions
Alain Reguera Delgado 1e834d
are made available in the execution environment before executing the
Alain Reguera Delgado 1e834d
module's initialization file. This way, module-specific functions are
Alain Reguera Delgado 1e834d
always available inside the module's initialization file.
Alain Reguera Delgado 1e834d
Module-specific functions are very useful when you are refactoring the
Alain Reguera Delgado 1e834d
module's initialization file.
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
For example, consider extending the *hello* module, to vary the
Alain Reguera Delgado 1e834d
``Hello, World!'' greeting message to something else based on a
Alain Reguera Delgado 1e834d
*--greeting* option passed through the command-line. For this, we can
Alain Reguera Delgado 1e834d
write everything in the module's initialization file or create a
Alain Reguera Delgado 1e834d
module-specific function to take care of all related actions and then
Alain Reguera Delgado 1e834d
execute it from module's initialization file. Because we want to keep
Alain Reguera Delgado 1e834d
the module's initialization file small and clean, we decided to create
Alain Reguera Delgado 1e834d
a module-specific function named *hello_getOptions*. This function is
Alain Reguera Delgado 1e834d
stored in a file named +hello_getOptions.sh+, at the same location of
Alain Reguera Delgado 1e834d
+hello.sh+ module's initialization file. See <<script-main-layout-2>>.
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
[[script-main-layout-2]]
Alain Reguera Delgado 1e834d
.The module directory structure with related function
Alain Reguera Delgado 1e834d
======================================================================
Alain Reguera Delgado 1e834d
----------------------------------------------------------------------
Alain Reguera Delgado 1e834d
.
Alain Reguera Delgado 1e834d
|-- COPYING
Alain Reguera Delgado 1e834d
|-- Locales/
Alain Reguera Delgado 1e834d
|-- Manuals/
Alain Reguera Delgado 1e834d
|-- Modules/
Alain Reguera Delgado 1e834d
|   `-- Hello/
Alain Reguera Delgado 1e834d
|       |-- hello.sh
Alain Reguera Delgado 1e834d
|       `-- hello_getOptions.sh     <-- module-related function.
Alain Reguera Delgado 1e834d
|-- Scripts/
Alain Reguera Delgado 1e834d
|-- centos-art.conf.sh
Alain Reguera Delgado 1e834d
`-- centos-art.sh
Alain Reguera Delgado 1e834d
----------------------------------------------------------------------
Alain Reguera Delgado 1e834d
======================================================================
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
As name convention, module-specific functions must be written using
Alain Reguera Delgado 1e834d
the module's name as suffix, then an underscore, then a descriptive
Alain Reguera Delgado 1e834d
name to identify the function. This convention is important in order
Alain Reguera Delgado 1e834d
for *centos-art.sh* script to execute and destroy modules as expected.
Alain Reguera Delgado 1e834d
If you create module-specific functions with a different pattern they
Alain Reguera Delgado 1e834d
will not be executed nor available inside your module's initialization
Alain Reguera Delgado 1e834d
file.
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
The name of the module-specific function +hello_getOptions+ is result
Alain Reguera Delgado 1e834d
of another name convention we are using inside *centos-art.sh* script.
Alain Reguera Delgado 1e834d
This is, when you need to provide argument parsing for a parent
Alain Reguera Delgado 1e834d
module, create a module-specific function with +_getOptions+ as prefix
Alain Reguera Delgado 1e834d
on its file name, then put all the code related to argument parsing
Alain Reguera Delgado 1e834d
inside it. Using a different function name here doesn't affect the
Alain Reguera Delgado 1e834d
execution of your module (as long as you retain the module's name as
Alain Reguera Delgado 1e834d
suffix). However, using this name convention, helps to keep a
Alain Reguera Delgado 1e834d
consistent directory structure inside the script.
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
The content of the module-specific function named +hello_getOptions+
Alain Reguera Delgado 1e834d
is also considered even another convention, a procedural convention at
Alain Reguera Delgado 1e834d
this time.  It provides the standard construction you should use
Alain Reguera Delgado 1e834d
whenever you want to make parent modules able to process arguments
Alain Reguera Delgado 1e834d
passed through the command-line. Through this construction, you can
Alain Reguera Delgado 1e834d
define which are the short and long options the module you are writing
Alain Reguera Delgado 1e834d
accepts and the possible values assigned to them, when passed.
Alain Reguera Delgado 1e834d
Basically, this construction transform the option arguments passed in
Alain Reguera Delgado 1e834d
the command-line in a way they can be parsed predictably, then parses
Alain Reguera Delgado 1e834d
them leaving non-option arguments, only.footnote:[To know more about
Alain Reguera Delgado 1e834d
option parsing inside *centos-art.sh* script, read the article named
Alain Reguera Delgado 1e834d
``_Understanding Option Parsing._''] See <<processing-args-from-cmd>>.
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
[[processing-args-from-cmd]]
Alain Reguera Delgado 1e834d
.Processing arguments from the command-line
Alain Reguera Delgado 1e834d
======================================================================
Alain Reguera Delgado 1e834d
----------------------------------------------------------------------
Alain Reguera Delgado 1e834d
#!/bin/bash
Alain Reguera Delgado 1e834d
######################################################################
Alain Reguera Delgado 1e834d
#
Alain Reguera Delgado 1e834d
#   hello_getOptions.sh -- Interpret module-specific options for hello.
Alain Reguera Delgado 1e834d
#
Alain Reguera Delgado 1e834d
#   Written by:
Alain Reguera Delgado 1e834d
#   * Alain Reguera Delgado <al@centos.org.cu>, 2013
Alain Reguera Delgado 1e834d
#
Alain Reguera Delgado 1e834d
# Copyright (C) 2009-2013 The CentOS Artwork SIG
Alain Reguera Delgado 1e834d
#
Alain Reguera Delgado 1e834d
# This program is free software; you can redistribute it and/or modify
Alain Reguera Delgado 1e834d
# it under the terms of the GNU General Public License as published by
Alain Reguera Delgado 1e834d
# the Free Software Foundation; either version 2 of the License, or (at
Alain Reguera Delgado 1e834d
# your option) any later version.
Alain Reguera Delgado 1e834d
#
Alain Reguera Delgado 1e834d
# This program is distributed in the hope that it will be useful, but
Alain Reguera Delgado 1e834d
# WITHOUT ANY WARRANTY; without even the implied warranty of
Alain Reguera Delgado 1e834d
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Alain Reguera Delgado 1e834d
# General Public License for more details.
Alain Reguera Delgado 1e834d
#
Alain Reguera Delgado 1e834d
# You should have received a copy of the GNU General Public License
Alain Reguera Delgado 1e834d
# along with this program; if not, write to the Free Software
Alain Reguera Delgado 1e834d
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Alain Reguera Delgado 1e834d
#
Alain Reguera Delgado 1e834d
######################################################################
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
function hello_getOptions {
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
    # Define short options we want to support.
Alain Reguera Delgado 1e834d
    local ARGSS="h::,v,g:"
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
    # Define long options we want to support.
Alain Reguera Delgado 1e834d
    local ARGSL="help::,version,greeting:"
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
    # Redefine arguments using getopt(1) command parser.
Alain Reguera Delgado 1e834d
    tcar_setModuleArguments
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
    # Reset positional parameters on this function, using output
Alain Reguera Delgado 1e834d
    # produced from (getopt) arguments parser.
Alain Reguera Delgado 1e834d
    eval set -- "${TCAR_MODULE_ARGUMENT}"
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
    # Look for options passed through command-line.
Alain Reguera Delgado 1e834d
    while true; do
Alain Reguera Delgado 1e834d
        case "${1}" in
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
            -h | --help )
Alain Reguera Delgado 1e834d
                tcar_printHelp "${2}"
Alain Reguera Delgado 1e834d
                ;;
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
            -v | --version )
Alain Reguera Delgado 1e834d
                tcar_printVersion "${TCAR_MODULE_NAME}"
Alain Reguera Delgado 1e834d
                ;;
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
            -g | --greeting )
Alain Reguera Delgado 1e834d
                HELLO_WORLD="${2:-${HELLO_WORLD}}"
Alain Reguera Delgado 1e834d
                shift 2
Alain Reguera Delgado 1e834d
                ;;
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
            -- )
Alain Reguera Delgado 1e834d
                shift 1
Alain Reguera Delgado 1e834d
                break
Alain Reguera Delgado 1e834d
                ;;
Alain Reguera Delgado 1e834d
        esac
Alain Reguera Delgado 1e834d
    done
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
    # Redefine arguments using current positional parameters. Only
Alain Reguera Delgado 1e834d
    # paths should remain as arguments, at this point.
Alain Reguera Delgado 1e834d
    TCAR_MODULE_ARGUMENT="${@}"
Alain Reguera Delgado 393983
Alain Reguera Delgado 393983
}
Alain Reguera Delgado 393983
----------------------------------------------------------------------
Alain Reguera Delgado 393983
======================================================================
Alain Reguera Delgado 393983
Alain Reguera Delgado a76055
Child Modules
Alain Reguera Delgado a76055
~~~~~~~~~~~~~
Alain Reguera Delgado a76055
...
Alain Reguera Delgado 393983
Alain Reguera Delgado a76055
Sibling Modules
Alain Reguera Delgado a76055
~~~~~~~~~~~~~~~
Alain Reguera Delgado 393983
Alain Reguera Delgado a76055
...
Alain Reguera Delgado 393983
Alain Reguera Delgado a76055
Recursive Modules
Alain Reguera Delgado a76055
~~~~~~~~~~~~~~~~~
Alain Reguera Delgado a76055
...
Alain Reguera Delgado 393983
Alain Reguera Delgado a76055
Summary
Alain Reguera Delgado a76055
~~~~~~~
Alain Reguera Delgado a76055
Alain Reguera Delgado 1e834d
This section has covered ...
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
Conventions
Alain Reguera Delgado 1e834d
-----------
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
When you write modules to *centos-art.sh* script, consider the
Alain Reguera Delgado 1e834d
following common conventions:
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
* Module directories are written capitalized (e.g., `Hello') while
Alain Reguera Delgado 1e834d
  module initialization file (e.g., `hello.sh') are written in
Alain Reguera Delgado 1e834d
  lower-case.
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
* When you write related functions, use underscore (``_'') to separate
Alain Reguera Delgado 1e834d
  the module's name from the function's descriptive name. In these
Alain Reguera Delgado 1e834d
  cases, the function's descriptive name is always written in
Alain Reguera Delgado 1e834d
  camel-case (e.g., `hello_getOptions.sh').
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
* Module directories and files inside them use the module's name as
Alain Reguera Delgado 1e834d
  suffix in their file names to get identified. This is convention
Alain Reguera Delgado 1e834d
  should be followed in order for *centos-art.sh* script to execute
Alain Reguera Delgado 1e834d
  and destroy modules as expected.
Alain Reguera Delgado 1e834d
Alain Reguera Delgado 1e834d
* The directory structure of a module is made of an initialization
Alain Reguera Delgado 1e834d
  file, module-specific functions and module-specific directories.
Alain Reguera Delgado 1e834d
  From all these components, only the initialization file is required
Alain Reguera Delgado 1e834d
  in order to have a functional module. The module-specific functions
Alain Reguera Delgado 1e834d
  are useful for refactoring the initialization file. The
Alain Reguera Delgado 1e834d
  module-specific directories are optional but, if use, must have the
Alain Reguera Delgado 1e834d
  following names and meaning:
Alain Reguera Delgado 1e834d
+
Alain Reguera Delgado 1e834d
+Modules/+::
Alain Reguera Delgado 1e834d
  This directory contains module-specific child modules. The purpose
Alain Reguera Delgado 1e834d
  of Modules/ directory is extending the functionality of higher
Alain Reguera Delgado 1e834d
  module environments.
Alain Reguera Delgado 1e834d
+Manuals/+::
Alain Reguera Delgado 1e834d
  This directory contains module-specific documentation. Documentation
Alain Reguera Delgado 1e834d
  in this directory are written in asciidoc format and produced
Alain Reguera Delgado 1e834d
  through the *render* functionality of *centos-art.sh* script.
Alain Reguera Delgado 1e834d
+Configs/+::
Alain Reguera Delgado 1e834d
  This directory contains module-specific configuration. Some modules
Alain Reguera Delgado 1e834d
  (e.g., ``tuneup'') need to store auxiliary files required to achieve
Alain Reguera Delgado 1e834d
  its main goal (e.g., the ``tuneup'' module uses sed files to
Alain Reguera Delgado 1e834d
  transform the top-comment of scripts each time it is executed, the
Alain Reguera Delgado 1e834d
  sed file itself is stored in this directory). Whenever you need to
Alain Reguera Delgado 1e834d
  make reference to a file inside this directory, use the
Alain Reguera Delgado 1e834d
  ``TCAR_MODULE_DIR_CONFIGS'' variable. This variable provides the
Alain Reguera Delgado 1e834d
  absolute path of module-related configuration file.
Alain Reguera Delgado 1e834d
+Locales/+::
Alain Reguera Delgado 1e834d
  This directory contains module-specific localization files. The
Alain Reguera Delgado 1e834d
  content of this directory is automatically generated by *locale*
Alain Reguera Delgado 1e834d
  module of *centos-art.sh* script, when you execute it using the
Alain Reguera Delgado 1e834d
  initialization file as source and the *--update --sibling* options.
Alain Reguera Delgado 1e834d
  Once the localization files have been created, you need to edit PO
Alain Reguera Delgado 1e834d
  files to translate the strings from English to your preferred
Alain Reguera Delgado 1e834d
  language.  If the translatable strings inside the module's source
Alain Reguera Delgado 1e834d
  files change, you need to run the *locale* module again to update
Alain Reguera Delgado 1e834d
  the PO files and repeat the localization process all over again.
Alain Reguera Delgado 393983
Alain Reguera Delgado 393983
// vim: set syntax=asciidoc: