|
Alain Reguera Delgado |
06ab0f |
tcar_setModuleEnvironment.sh(1)
|
|
Alain Reguera Delgado |
06ab0f |
===============================
|
|
Alain Reguera Delgado |
06ab0f |
|
|
Alain Reguera Delgado |
06ab0f |
Name
|
|
Alain Reguera Delgado |
06ab0f |
----
|
|
Alain Reguera Delgado |
06ab0f |
|
|
Alain Reguera Delgado |
06ab0f |
tcar_setModuleEnvironment.sh - Initiate module environments.
|
|
Alain Reguera Delgado |
06ab0f |
|
|
Alain Reguera Delgado |
06ab0f |
Synopsis
|
|
Alain Reguera Delgado |
06ab0f |
--------
|
|
Alain Reguera Delgado |
06ab0f |
|
|
Alain Reguera Delgado |
e36b89 |
*tcar_setModuleEnvironment [-m "MODULE_NAME"] [-t "MODULE_TYPE"] [-g MODULE_ARGUMENT] ...*
|
|
Alain Reguera Delgado |
06ab0f |
|
|
Alain Reguera Delgado |
06ab0f |
Description
|
|
Alain Reguera Delgado |
06ab0f |
-----------
|
|
Alain Reguera Delgado |
06ab0f |
|
|
Alain Reguera Delgado |
e36b89 |
From version 0.5 of The CentOS Artwork Repository on, the
|
|
Alain Reguera Delgado |
e36b89 |
*centos-art.sh* script was redesigned to introduce the idea of modules
|
|
Alain Reguera Delgado |
e36b89 |
to its base design. Modules are a collection of functions written in
|
|
Alain Reguera Delgado |
e36b89 |
Bash that can call one another to create individual execution
|
|
Alain Reguera Delgado |
e36b89 |
environments. They may be nested efficiently to achieve high levels of
|
|
Alain Reguera Delgado |
e36b89 |
maintainability and extensibility. This make possible for modules
|
|
Alain Reguera Delgado |
e36b89 |
writers to divide complicated tasks into smaller tasks that can be
|
|
Alain Reguera Delgado |
e36b89 |
easier to debug, maintain and share with other modules efficiently
|
|
Alain Reguera Delgado |
e36b89 |
(e.g., instead of loading modules all at once, they are only loaded at
|
|
Alain Reguera Delgado |
e36b89 |
demand and unset once they conclude their execution).
|
|
Alain Reguera Delgado |
e36b89 |
|
|
Alain Reguera Delgado |
e36b89 |
Inside the *centos-art.sh* script there are two kinds of functions,
|
|
Alain Reguera Delgado |
06ab0f |
which are "global functions" and "module-specific functions." The
|
|
Alain Reguera Delgado |
e36b89 |
global functions are loaded in the very beginning of *centos-art.sh*
|
|
Alain Reguera Delgado |
e36b89 |
script and remain in memory for you to use whenever you need it, using
|
|
Alain Reguera Delgado |
e36b89 |
a regular function call syntax. The module-specific functions, on the
|
|
Alain Reguera Delgado |
e36b89 |
other hand, are only loaded when they are needed and they are removed
|
|
Alain Reguera Delgado |
e36b89 |
from memory once the task they were created for is done. To load
|
|
Alain Reguera Delgado |
e36b89 |
module-specific functions inside the *centos-art.sh* script, you use
|
|
Alain Reguera Delgado |
e36b89 |
the *tcar_setModuleEnvironment* global function as described in the
|
|
Alain Reguera Delgado |
e36b89 |
synopsis section above.
|
|
Alain Reguera Delgado |
e36b89 |
|
|
Alain Reguera Delgado |
e36b89 |
Module Execution Environment
|
|
Alain Reguera Delgado |
e36b89 |
----------------------------
|
|
Alain Reguera Delgado |
e36b89 |
|
|
Alain Reguera Delgado |
e36b89 |
Each time you execute the *tcar_setModuleEnvironment* function, it
|
|
Alain Reguera Delgado |
e36b89 |
creates a new ``Module Environment.'' A module environment is a
|
|
Alain Reguera Delgado |
e36b89 |
logical space where you can deploy solutions for specific problems.
|
|
Alain Reguera Delgado |
e36b89 |
The implementation of these solutions take place in the Modules
|
|
Alain Reguera Delgado |
e36b89 |
directory of *centos-art.sh* script, as described in
|
|
Alain Reguera Delgado |
e36b89 |
<<module-implementation>>.
|
|
Alain Reguera Delgado |
e36b89 |
|
|
Alain Reguera Delgado |
e36b89 |
Module environments all begin with a ``top-module.'' These modules are
|
|
Alain Reguera Delgado |
e36b89 |
stored at the first level of Modules directory inside the
|
|
Alain Reguera Delgado |
e36b89 |
*centos-art.sh* script tree. These modules are small and their goal
|
|
Alain Reguera Delgado |
e36b89 |
main goal it to define global variables for task-specific actions,
|
|
Alain Reguera Delgado |
e36b89 |
interpret module-specific options passed in the command-line and
|
|
Alain Reguera Delgado |
e36b89 |
execute the appropriate sub-module based on it.
|
|
Alain Reguera Delgado |
e36b89 |
|
|
Alain Reguera Delgado |
e36b89 |
Sub-modules are module environments that nest one inside another
|
|
Alain Reguera Delgado |
e36b89 |
creating a chain of module environments. A chain of module
|
|
Alain Reguera Delgado |
e36b89 |
environments is very useful in situations where you want to divide one
|
|
Alain Reguera Delgado |
e36b89 |
large task into smaller tasks and also control which of those smaller
|
|
Alain Reguera Delgado |
e36b89 |
tasks are loaded based on specific conditions (e.g., you want to
|
|
Alain Reguera Delgado |
e36b89 |
render both images and documentation). In a chain of modules, module
|
|
Alain Reguera Delgado |
e36b89 |
environments at a lower level in the chain (those started last) have
|
|
Alain Reguera Delgado |
e36b89 |
access to higher module environments (those started first), but not
|
|
Alain Reguera Delgado |
e36b89 |
the opposite. When processing information this way, module
|
|
Alain Reguera Delgado |
e36b89 |
environments aren't destroyed until the last module environment loaded
|
|
Alain Reguera Delgado |
e36b89 |
is done. At that point, module environments are destroyed in the
|
|
Alain Reguera Delgado |
e36b89 |
reverse order they were loaded (e.g., if the chain of module was
|
|
Alain Reguera Delgado |
e36b89 |
executed as ``render->images->svg'', then, when ``svg'' module
|
|
Alain Reguera Delgado |
e36b89 |
environment is done, the chain of modules will be destroy ``images''
|
|
Alain Reguera Delgado |
e36b89 |
and finally ``render'').
|
|
Alain Reguera Delgado |
e36b89 |
|
|
Alain Reguera Delgado |
e36b89 |
Module environments can also share one common module environment on
|
|
Alain Reguera Delgado |
e36b89 |
top of them to create sibling processing (sib-module). Sibling
|
|
Alain Reguera Delgado |
e36b89 |
processing is very useful in situations where you start processing
|
|
Alain Reguera Delgado |
e36b89 |
information in a way and then need to jump to another kind of
|
|
Alain Reguera Delgado |
e36b89 |
processing (e.g., when you are rendering documentation you first start
|
|
Alain Reguera Delgado |
e36b89 |
rendering it as html and then jump into manpage). In this situation,
|
|
Alain Reguera Delgado |
e36b89 |
you open a module environment that contains information useful for two
|
|
Alain Reguera Delgado |
e36b89 |
or more different kind of information processing and jump from one
|
|
Alain Reguera Delgado |
e36b89 |
processing to another without destroying the common information.
|
|
Alain Reguera Delgado |
e36b89 |
However, when one of the specific way or processing information is
|
|
Alain Reguera Delgado |
e36b89 |
done, it is destroyed. This, before opening a new way of processing
|
|
Alain Reguera Delgado |
e36b89 |
(e.g., once html processing is done, the html module is destroyed and,
|
|
Alain Reguera Delgado |
e36b89 |
then, the manpage module is loaded). So, only the required modules are
|
|
Alain Reguera Delgado |
e36b89 |
active while processing information.
|
|
Alain Reguera Delgado |
e36b89 |
|
|
Alain Reguera Delgado |
e36b89 |
[[module-implementation]]
|
|
Alain Reguera Delgado |
e36b89 |
Module Implementation
|
|
Alain Reguera Delgado |
e36b89 |
---------------------
|
|
Alain Reguera Delgado |
e36b89 |
|
|
Alain Reguera Delgado |
e36b89 |
The implementation of *tcar_setModuleEnvironment* function uses global
|
|
Alain Reguera Delgado |
e36b89 |
array variables to store information about the modules and (non-array)
|
|
Alain Reguera Delgado |
e36b89 |
local variables to handle the information stored about modules in each
|
|
Alain Reguera Delgado |
e36b89 |
call of the function. Each time you call the
|
|
Alain Reguera Delgado |
e36b89 |
*tcar_setModuleEnvironment* function, it increments the array
|
|
Alain Reguera Delgado |
e36b89 |
variables counter, stores module-specific information in the array
|
|
Alain Reguera Delgado |
e36b89 |
variables, reset (non-array) local variables using the current
|
|
Alain Reguera Delgado |
e36b89 |
module's information stored in the array variables and executes the
|
|
Alain Reguera Delgado |
e36b89 |
module's initialization script from (non-array) local variables. When
|
|
Alain Reguera Delgado |
e36b89 |
the module's environment finishes its execution, the array counter
|
|
Alain Reguera Delgado |
e36b89 |
decrements and the module's environment is unset, to free the memory
|
|
Alain Reguera Delgado |
e36b89 |
it was using. This process repeats continually, each time you call
|
|
Alain Reguera Delgado |
e36b89 |
the *tcar_setModuleEnvironment* function.
|
|
Alain Reguera Delgado |
e36b89 |
|
|
Alain Reguera Delgado |
e36b89 |
[TIP]
|
|
Alain Reguera Delgado |
06ab0f |
======================================================================
|
|
Alain Reguera Delgado |
e36b89 |
In case you want to see how modules are created and destroyed inside,
|
|
Alain Reguera Delgado |
e36b89 |
pass the *--debug* option to *centos-art.sh* script. It will activate
|
|
Alain Reguera Delgado |
e36b89 |
the script internal debugger for you to see the whole process.
|
|
Alain Reguera Delgado |
06ab0f |
======================================================================
|
|
Alain Reguera Delgado |
06ab0f |
|
|
Alain Reguera Delgado |
e36b89 |
When we say that a module environment is destroyed it means that all
|
|
Alain Reguera Delgado |
e36b89 |
the related variables and functions which make that module environment
|
|
Alain Reguera Delgado |
e36b89 |
useful are removed from *centos-art.sh* script execution environment,
|
|
Alain Reguera Delgado |
e36b89 |
which make the module environment inoperable to all effects, indeed.
|
|
Alain Reguera Delgado |
e36b89 |
However, the global array variables used by
|
|
Alain Reguera Delgado |
e36b89 |
*tcar_setModuleEnvironment* function to store module-specific
|
|
Alain Reguera Delgado |
e36b89 |
information remain active until the last module environment is
|
|
Alain Reguera Delgado |
e36b89 |
destroyed. This make possible for *centos-art.sh* script to remember
|
|
Alain Reguera Delgado |
e36b89 |
information about the module environments required for a specific
|
|
Alain Reguera Delgado |
e36b89 |
tasks. It is also very useful when it is necessary to jump from one
|
|
Alain Reguera Delgado |
e36b89 |
module environment to another under the same parent module environment.
|
|
Alain Reguera Delgado |
e36b89 |
|
|
Alain Reguera Delgado |
e36b89 |
Each module environment you want to execute needs a module directory
|
|
Alain Reguera Delgado |
e36b89 |
in the *centos-art.sh* script tree. In this directory you organize the
|
|
Alain Reguera Delgado |
e36b89 |
functions that make your module environment useful. The directory
|
|
Alain Reguera Delgado |
e36b89 |
structure of your module directory is important because
|
|
Alain Reguera Delgado |
e36b89 |
*tcar_setModuleEnvironment* makes use of it to know module-specific
|
|
Alain Reguera Delgado |
e36b89 |
information.
|
|
Alain Reguera Delgado |
e36b89 |
|
|
Alain Reguera Delgado |
e36b89 |
To illustrate how modules need to be implemented inside
|
|
Alain Reguera Delgado |
e36b89 |
*centos-art.sh* script in order for *tcar_setModuleEnvironment* to
|
|
Alain Reguera Delgado |
e36b89 |
execute them, we are using an example module named ``greet''. The
|
|
Alain Reguera Delgado |
e36b89 |
purpose of greet module is instructive only. Because, greet has a
|
|
Alain Reguera Delgado |
e36b89 |
module directory structure for its own, its documentation is not in
|
|
Alain Reguera Delgado |
e36b89 |
this documentation page but in greet module own documentation page. To
|
|
Alain Reguera Delgado |
e36b89 |
read greet module's documentation page, run the following command:
|
|
Alain Reguera Delgado |
e36b89 |
*centos-art greet --help*.
|
|
Alain Reguera Delgado |
e36b89 |
|
|
Alain Reguera Delgado |
e36b89 |
[[options]]
|
|
Alain Reguera Delgado |
06ab0f |
Options
|
|
Alain Reguera Delgado |
06ab0f |
-------
|
|
Alain Reguera Delgado |
06ab0f |
|
|
Alain Reguera Delgado |
e36b89 |
The *tcar_setModuleEnvironment* function accepts the following
|
|
Alain Reguera Delgado |
e36b89 |
options:
|
|
Alain Reguera Delgado |
e36b89 |
|
|
Alain Reguera Delgado |
e36b89 |
-m ::
|
|
Alain Reguera Delgado |
e36b89 |
This option specifies the name of the module you want to load.
|
|
Alain Reguera Delgado |
e36b89 |
-t::
|
|
Alain Reguera Delgado |
e36b89 |
This option specifies the type of the module you want to load.
|
|
Alain Reguera Delgado |
e36b89 |
Modules can be one of the following types:
|
|
Alain Reguera Delgado |
e36b89 |
+
|
|
Alain Reguera Delgado |
e36b89 |
top-module;;
|
|
Alain Reguera Delgado |
e36b89 |
This modules are stored in the first level of Modules directory.
|
|
Alain Reguera Delgado |
e36b89 |
This type of modules initiate module environments for specific
|
|
Alain Reguera Delgado |
e36b89 |
tasks so it can be called from anywhere inside *centos-art.sh*
|
|
Alain Reguera Delgado |
e36b89 |
script.
|
|
Alain Reguera Delgado |
e36b89 |
sub-module;;
|
|
Alain Reguera Delgado |
e36b89 |
This modules are stored from the second-level of Modules directory
|
|
Alain Reguera Delgado |
e36b89 |
on. This type of modules can be executed from top-modules,
|
|
Alain Reguera Delgado |
e36b89 |
sub-modules, or sib-modules but never the *centos-art.sh* file
|
|
Alain Reguera Delgado |
e36b89 |
itself.
|
|
Alain Reguera Delgado |
e36b89 |
sib-module;;
|
|
Alain Reguera Delgado |
e36b89 |
This modules are stored from the second-level of Modules directory
|
|
Alain Reguera Delgado |
e36b89 |
on. This type of modules can be executed from sub-modules or
|
|
Alain Reguera Delgado |
e36b89 |
sib-modules, but never top-modules or the *centos-art.sh* file
|
|
Alain Reguera Delgado |
e36b89 |
itself.
|
|
Alain Reguera Delgado |
e36b89 |
-g::
|
|
Alain Reguera Delgado |
e36b89 |
This option specifies the module-specific option you want to pass
|
|
Alain Reguera Delgado |
e36b89 |
for processing in the module environment you are about to execute.
|
|
Alain Reguera Delgado |
e36b89 |
Generally, module-specific options are passed through
|
|
Alain Reguera Delgado |
e36b89 |
*centos-art.sh* command-line but you may need to pass them
|
|
Alain Reguera Delgado |
e36b89 |
internally in some cases (e.g., you are executing a top-module
|
|
Alain Reguera Delgado |
e36b89 |
from a sub-module). If you need to pass more than one option, then
|
|
Alain Reguera Delgado |
e36b89 |
you need to put the -g option before each option you want to pass.
|
|
Alain Reguera Delgado |
e36b89 |
|
|
Alain Reguera Delgado |
e36b89 |
Bugs
|
|
Alain Reguera Delgado |
e36b89 |
----
|
|
Alain Reguera Delgado |
e36b89 |
|
|
Alain Reguera Delgado |
e36b89 |
In the very beginning of *tcar_setModuleEnvironment* function, it used
|
|
Alain Reguera Delgado |
e36b89 |
just non-array variables and it worked fine for top-module and sub-module
|
|
Alain Reguera Delgado |
e36b89 |
processing, however when it was needed to do sibling processing, it
|
|
Alain Reguera Delgado |
e36b89 |
didn't work as expected. The failure was produced because a wrong
|
|
Alain Reguera Delgado |
e36b89 |
variable assignment when tried to set the path of the next module to
|
|
Alain Reguera Delgado |
e36b89 |
load. There was not a clean way to ``remember'' what was the base
|
|
Alain Reguera Delgado |
e36b89 |
directory of the parent directory, so it ended up using the last
|
|
Alain Reguera Delgado |
e36b89 |
loaded module base directory which made impossible to load a sibling
|
|
Alain Reguera Delgado |
e36b89 |
module. The *tcar_setModuleEnvironment* function as implemented in
|
|
Alain Reguera Delgado |
e36b89 |
version 0.5 of The CentOS Artwork Repository, fixes this issue
|
|
Alain Reguera Delgado |
e36b89 |
replacing non-array variables by array variables which can remember
|
|
Alain Reguera Delgado |
e36b89 |
module information.
|
|
Alain Reguera Delgado |
e36b89 |
|
|
Alain Reguera Delgado |
e36b89 |
See also: https://centos.org.cu/bugs/[https://centos.org.cu/bugs/]
|
|
Alain Reguera Delgado |
06ab0f |
|
|
Alain Reguera Delgado |
06ab0f |
Author
|
|
Alain Reguera Delgado |
06ab0f |
------
|
|
Alain Reguera Delgado |
06ab0f |
|
|
Alain Reguera Delgado |
06ab0f |
The *centos-art.sh* script has received contribution from the
|
|
Alain Reguera Delgado |
06ab0f |
following people:
|
|
Alain Reguera Delgado |
06ab0f |
|
|
Alain Reguera Delgado |
e36b89 |
* Alain Reguera Delgado <mailto:al@centos.org.cu[al@centos.org.cu]>, 2009-2013
|
|
Alain Reguera Delgado |
06ab0f |
|
|
Alain Reguera Delgado |
06ab0f |
Copyright
|
|
Alain Reguera Delgado |
06ab0f |
---------
|
|
Alain Reguera Delgado |
06ab0f |
|
|
Alain Reguera Delgado |
e36b89 |
Copyright (C) 2009-2013 The CentOS Artwork SIG
|
|
Alain Reguera Delgado |
06ab0f |
|
|
Alain Reguera Delgado |
06ab0f |
This program is free software; you can redistribute it and/or modify
|
|
Alain Reguera Delgado |
06ab0f |
it under the terms of the GNU General Public License as published by
|
|
Alain Reguera Delgado |
06ab0f |
the Free Software Foundation; either version 2 of the License, or (at
|
|
Alain Reguera Delgado |
06ab0f |
your option) any later version.
|
|
Alain Reguera Delgado |
06ab0f |
|
|
Alain Reguera Delgado |
06ab0f |
This program is distributed in the hope that it will be useful, but
|
|
Alain Reguera Delgado |
06ab0f |
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Alain Reguera Delgado |
06ab0f |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Alain Reguera Delgado |
06ab0f |
General Public License for more details.
|
|
Alain Reguera Delgado |
06ab0f |
|
|
Alain Reguera Delgado |
06ab0f |
You should have received a copy of the GNU General Public License
|
|
Alain Reguera Delgado |
06ab0f |
along with this program; if not, write to the Free Software
|
|
Alain Reguera Delgado |
06ab0f |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
Alain Reguera Delgado |
06ab0f |
|
|
Alain Reguera Delgado |
06ab0f |
// vim: set syntax=asciidoc:
|