Blame Documentation/Understanding_Modules/understanding_modules.asciidoc

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