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