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