Blame Automation/Manuals/Understanding_Modules/understanding_modules.asciidoc

Alain Reguera Delgado 393983
Understanding Modules
Alain Reguera Delgado 393983
=====================
Alain Reguera Delgado 393983
Alain Reguera Delgado <al@centos.org.cu>
Alain Reguera Delgado 393983
v1.0, Oct 2013
Alain Reguera Delgado 393983
Alain Reguera Delgado 393983
Introduction
Alain Reguera Delgado 393983
------------
Alain Reguera Delgado 393983
Alain Reguera Delgado 393983
From version 0.5 of The CentOS Artwork Repository on, the
Alain Reguera Delgado 393983
*centos-art.sh* script was redesigned to introduce the idea of modules
Alain Reguera Delgado 393983
to its base design. Modules are a collection of functions written in
Alain Reguera Delgado 393983
Bash that can call one another to create individual execution
Alain Reguera Delgado 393983
environments. They may be nested efficiently 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
Inside the *centos-art.sh* script there are two kinds of functions,
Alain Reguera Delgado 393983
which are: "global functions" and "module-specific functions." The
Alain Reguera Delgado 393983
global functions are defined in the very beginning of *centos-art.sh*
Alain Reguera Delgado 393983
script and remain in memory for you to call whenever you need it using
Alain Reguera Delgado 393983
a regular function call syntax. The module-specific functions, on the
Alain Reguera Delgado 393983
other hand, are defined at demand for specific tasks and removed from
Alain Reguera Delgado 393983
memory once the task they were created for is over.  The collection of
Alain Reguera Delgado 393983
all module-specific functions related to the same task is what we call
Alain Reguera Delgado 393983
a module environment.  Module environments can be either top-module,
Alain Reguera Delgado 393983
sub-module or sib-module and all are executed through the
Alain Reguera Delgado 393983
*tcar_setModuleEnvironment* global function.
Alain Reguera Delgado 393983
Alain Reguera Delgado 393983
This article describes the modular design of *centos-art.sh* script.
Alain Reguera Delgado 393983
It is a good place to start if you are planning to contribute new
Alain Reguera Delgado 393983
module environments to *centos-art.sh* script. The next section
Alain Reguera Delgado 393983
delves into what a module environment is, the tree module types you
Alain Reguera Delgado 393983
can find and the correct way of execute them.
Alain Reguera Delgado 393983
Alain Reguera Delgado 393983
The Module Environment
Alain Reguera Delgado 393983
----------------------
Alain Reguera Delgado 393983
Alain Reguera Delgado 393983
The module environment provides an array of strings (called the
Alain Reguera Delgado 393983
environment). You can use this environment to deploy solutions for
Alain Reguera Delgado 393983
specific problems.  Inside the *centos-art.sh* script, module
Alain Reguera Delgado 393983
environments are made of small functions that create small
Alain Reguera Delgado 393983
environments to solve small problems. Then they are combined in a
Alain Reguera Delgado 393983
specific order to solve bigger problems.  The process of initiating a
Alain Reguera Delgado 393983
module environment inside *centos-art.sh* script starts at the end of
Alain Reguera Delgado 393983
the *centos-art.sh* file itself, with the invocation of the
Alain Reguera Delgado 393983
*tcar_setModuleEnvironment* function. This function, at this point,
Alain Reguera Delgado 393983
executes the module environment for the module name you specified in
Alain Reguera Delgado 393983
the first argument of the command-line.  The modules you specified in
Alain Reguera Delgado 393983
the command-line are also known as top-modules.
Alain Reguera Delgado 393983
Alain Reguera Delgado 393983
Top-modules initiate the higher module environment inside
Alain Reguera Delgado 393983
*centos-art.sh* script. This means that variables and functions
Alain Reguera Delgado 393983
defined inside it will be available as long as its execution-time
Alain Reguera Delgado 393983
last.  Top-modules are stored directly inside the +Modules/+ directory
Alain Reguera Delgado 393983
of *centos-art.sh* script, as described in <<directory-structure>>.
Alain Reguera Delgado 393983
Top-modules use to be small and have well defined goals. Top-modules
Alain Reguera Delgado 393983
exist to define global variables for task-specific actions, interpret
Alain Reguera Delgado 393983
module-specific options passed through the command-line and execute
Alain Reguera Delgado 393983
the appropriate actions based on them. These actions can be involve
Alain Reguera Delgado 393983
calling other top-modules or sub-modules.
Alain Reguera Delgado 393983
Alain Reguera Delgado 393983
Sub-modules are also module environments. They are executed by the
Alain Reguera Delgado 393983
*tcar_setModuleEnvironment* function when the *-t sub-module* option
Alain Reguera Delgado 393983
is passed to it. Sub-modules have the characteristic of being nested
Alain Reguera Delgado 393983
modules. They are generally executed one inside another to create a
Alain Reguera Delgado 393983
chain of module environments. A chain of module environments is very
Alain Reguera Delgado 393983
useful in situations where you want to divide one large task into
Alain Reguera Delgado 393983
smaller tasks and also control which of those smaller tasks are loaded
Alain Reguera Delgado 393983
based on specific conditions (e.g., you want to render both images and
Alain Reguera Delgado 393983
documentation).  In a chain of modules, module environments at a lower
Alain Reguera Delgado 393983
level in the chain (those started last) have access to higher module
Alain Reguera Delgado 393983
environments (those started first), but not the opposite. When
Alain Reguera Delgado 393983
processing information this way, module environments aren't destroyed
Alain Reguera Delgado 393983
until the last module environment loaded is done. At that point,
Alain Reguera Delgado 393983
module environments are destroyed in the reverse order they were
Alain Reguera Delgado 393983
loaded (e.g., if the chain of module was executed as
Alain Reguera Delgado 393983
``render->images->svg'', then, when ``svg'' module environment is
Alain Reguera Delgado 393983
done, the chain of modules will be destroy ``images'' and finally
Alain Reguera Delgado 393983
``render'').
Alain Reguera Delgado 393983
Alain Reguera Delgado 393983
Module environments can also share one common module environment on
Alain Reguera Delgado 393983
top of them to create sibling processing (sib-module). Sibling
Alain Reguera Delgado 393983
processing is very useful in situations where you start processing
Alain Reguera Delgado 393983
information in a way and then need to jump to another related but
Alain Reguera Delgado 393983
different kind of processing (e.g., when you are rendering
Alain Reguera Delgado 393983
documentation you first start rendering it as html and then jump into
Alain Reguera Delgado 393983
manpage). In this situation, you open a module environment that
Alain Reguera Delgado 393983
contains information useful for two or more different but related kind
Alain Reguera Delgado 393983
of processing and jump from one to another without destroying the
Alain Reguera Delgado 393983
common information.  However, when one of the specific ways of
Alain Reguera Delgado 393983
processing information is done, it is destroyed. This, before opening
Alain Reguera Delgado 393983
a new way of processing (e.g., once html processing is done, the html
Alain Reguera Delgado 393983
module is destroyed and, then, the manpage module is loaded).  So,
Alain Reguera Delgado 393983
only the required modules are active while processing information.
Alain Reguera Delgado 393983
Alain Reguera Delgado 393983
When we say that a module environment is destroyed it means that all
Alain Reguera Delgado 393983
the related variables and functions which make that module environment
Alain Reguera Delgado 393983
useful are removed from *centos-art.sh* script execution environment,
Alain Reguera Delgado 393983
which make the module environment inoperable to all effects, indeed.
Alain Reguera Delgado 393983
However, it is worth to know that all global array variables the
Alain Reguera Delgado 393983
*tcar_setModuleEnvironment* function uses to store module-specific
Alain Reguera Delgado 393983
information remain active until the last module environment is
Alain Reguera Delgado 393983
destroyed (i.e., the top-module executed from the command-line).  This
Alain Reguera Delgado 393983
make possible for *centos-art.sh* script to ``remember'' information
Alain Reguera Delgado 393983
about all different but related module environments loaded to perform
Alain Reguera Delgado 393983
specific tasks. Such remembering feature is what make possible to
Alain Reguera Delgado 393983
implement sib-modules as described above.
Alain Reguera Delgado 393983
Alain Reguera Delgado 393983
[[module-implementation]]
Alain Reguera Delgado 393983
Module Implementation
Alain Reguera Delgado 393983
---------------------
Alain Reguera Delgado 393983
Alain Reguera Delgado 393983
The implementation of module environments take place in two locations.
Alain Reguera Delgado 393983
The first location is the module directory structure and the second
Alain Reguera Delgado 393983
location *tcar_setModuleEnvironment* function. The module directory
Alain Reguera Delgado 393983
structure contains a standard distribution of files and directories
Alain Reguera Delgado 393983
that the *tcar_setModuleEnvironment* function recognizes and uses for
Alain Reguera Delgado 393983
executing functions inside it.  Each module environment you want to
Alain Reguera Delgado 393983
execute needs a module directory in the *centos-art.sh* script tree.
Alain Reguera Delgado 393983
In this directory you organize the functions that make your module
Alain Reguera Delgado 393983
environment useful. The directory structure of your module directory
Alain Reguera Delgado 393983
is important because *tcar_setModuleEnvironment* makes use of it to
Alain Reguera Delgado 393983
know module-specific information.
Alain Reguera Delgado 393983
Alain Reguera Delgado 393983
The *tcar_setModuleEnvironment* function is stored in the +Scripts/+
Alain Reguera Delgado 393983
directory. It uses global array variables to store information about
Alain Reguera Delgado 393983
the modules and (non-array) local variables to handle the information
Alain Reguera Delgado 393983
stored about modules in each call of the function. Each time you call
Alain Reguera Delgado 393983
the *tcar_setModuleEnvironment* function, it increments the array
Alain Reguera Delgado 393983
variables counter, stores module-specific information in the array
Alain Reguera Delgado 393983
variables, reset (non-array) local variables using the current
Alain Reguera Delgado 393983
module's information stored in the array variables and executes the
Alain Reguera Delgado 393983
module's initialization script from (non-array) local variables.  When
Alain Reguera Delgado 393983
the module's environment finishes its execution, the array counter
Alain Reguera Delgado 393983
decrements and the module's environment is destroyed, to free the
Alain Reguera Delgado 393983
memory it was using.  This process repeats continually, each time you
Alain Reguera Delgado 393983
call the *tcar_setModuleEnvironment* function.
Alain Reguera Delgado 393983
Alain Reguera Delgado 393983
[TIP]
Alain Reguera Delgado 393983
======================================================================
Alain Reguera Delgado 393983
In case you want to see how modules are created and destroyed inside,
Alain Reguera Delgado 393983
pass the *--debug* option to *centos-art.sh* script. It will activate
Alain Reguera Delgado 393983
the script internal debugger for you to see the whole process.
Alain Reguera Delgado 393983
======================================================================
Alain Reguera Delgado 393983
Alain Reguera Delgado 393983
To illustrate how modules need to be implemented inside
Alain Reguera Delgado 393983
*centos-art.sh* script in order for *tcar_setModuleEnvironment* to
Alain Reguera Delgado 393983
execute them correctly, we'll use a module named ``hello'' as example
Alain Reguera Delgado 393983
in the next sections to describe the steps you need to follow for
Alain Reguera Delgado 393983
creating new modules from scratch.  The purpose of *hello* module is
Alain Reguera Delgado 393983
to print out greetings to standard output and exit successfully. See
Alain Reguera Delgado 393983
*hello(1)*, for more information about it.
Alain Reguera Delgado 393983
Alain Reguera Delgado 393983
Planning New Module
Alain Reguera Delgado 393983
-------------------
Alain Reguera Delgado 393983
Alain Reguera Delgado 393983
Planning is probably the first thing you need to do in order to create
Alain Reguera Delgado 393983
a new module to *centos-art.sh* script. It would be very helpful if
Alain Reguera Delgado 393983
you read documentation and bugs related to modules and function in
Alain Reguera Delgado 393983
order to find out possible tasks you might take as motivation for your
Alain Reguera Delgado 393983
contributions. Such investigation always help.
Alain Reguera Delgado 393983
Alain Reguera Delgado 393983
The motivation behind the *hello* module came with the need of having
Alain Reguera Delgado 393983
a simple module that could be used as reference to describe how to
Alain Reguera Delgado 393983
create and execute new modules inside *centos-art.sh* script. The top
Alain Reguera Delgado 393983
modules we have by now aren't suitable for a simple description about
Alain Reguera Delgado 393983
how to create new modules from scratch.  Instead, I thought that
Alain Reguera Delgado 393983
creating a simple module for that purpose would be better. Suddenly, I
Alain Reguera Delgado 393983
recalled the GNU's hello package which describes their standards about
Alain Reguera Delgado 393983
well written GNU packages and found motivation enough to create a
Alain Reguera Delgado 393983
*hello* module under the same idea but this time focused on
Alain Reguera Delgado 393983
*centos-art.sh* script, instead.
Alain Reguera Delgado 393983
Alain Reguera Delgado 393983
The motivation for planning your own modules might vary. No matter
Alain Reguera Delgado 393983
what it would be, use it with confidence, plan your module, set the
Alain Reguera Delgado 393983
final spot where you want to get to and then, read the next section.
Alain Reguera Delgado 393983
It describes the steps you need to follow in order to write a
Alain Reguera Delgado 393983
functional module inside *centos-art.sh* script.
Alain Reguera Delgado 393983
Alain Reguera Delgado 393983
Creating New Module
Alain Reguera Delgado 393983
-------------------
Alain Reguera Delgado 393983
Alain Reguera Delgado 393983
The <<directory-structure>>, shows a basic module structure. In this
Alain Reguera Delgado 393983
example, we see that module directories are written capitalized while
Alain Reguera Delgado 393983
module initialization file and related functions are all written in
Alain Reguera Delgado 393983
lower-case. Note also how the module directory and files inside it use
Alain Reguera Delgado 393983
the module's name in their file names to get identified. This is a
Alain Reguera Delgado 393983
convention that should be followed in order for *centos-art.sh* script
Alain Reguera Delgado 393983
to execute modules. Another convention you should follow, when
Alain Reguera Delgado 393983
creating related functions, is using underscore (``_'') to separate
Alain Reguera Delgado 393983
the module's name from the function's descriptive name. In these
Alain Reguera Delgado 393983
cases, the function's descriptive name is always written in camel-case
Alain Reguera Delgado 393983
followed by the +.sh+ extension.
Alain Reguera Delgado 393983
Alain Reguera Delgado 393983
[[directory-structure]]
Alain Reguera Delgado 393983
.The directory structure
Alain Reguera Delgado 393983
======================================================================
Alain Reguera Delgado 393983
----------------------------------------------------------------------
Alain Reguera Delgado 393983
.
Alain Reguera Delgado 393983
|-- COPYING                     <-- Contains the GPL license.
Alain Reguera Delgado 393983
|-- Locales/                    <-- localization of all sh files.
Alain Reguera Delgado 393983
|-- Manuals/                    <-- manuals for main and global functions.
Alain Reguera Delgado 393983
|-- Modules/                    <-- top-modules are stored here.
Alain Reguera Delgado 393983
|   `-- Hello/                  <-- top-module directory.
Alain Reguera Delgado 393983
|       `-- hello.sh            <-- top-module initialization file.
Alain Reguera Delgado 393983
|-- Scripts/                    <-- global functions are stored here.
Alain Reguera Delgado 393983
|-- centos-art.conf.sh          <-- main configuration file.
Alain Reguera Delgado 393983
`-- centos-art.sh               <-- main initialization file.
Alain Reguera Delgado 393983
----------------------------------------------------------------------
Alain Reguera Delgado 393983
======================================================================
Alain Reguera Delgado 393983
Alain Reguera Delgado 393983
[[directory-structure-extended]]
Alain Reguera Delgado 393983
.The directory structure with extended functionality
Alain Reguera Delgado 393983
======================================================================
Alain Reguera Delgado 393983
----------------------------------------------------------------------
Alain Reguera Delgado 393983
.
Alain Reguera Delgado 393983
|-- COPYING
Alain Reguera Delgado 393983
|-- Locales/
Alain Reguera Delgado 393983
|-- Manuals/
Alain Reguera Delgado 393983
|-- Modules/
Alain Reguera Delgado 393983
|   `-- Hello/
Alain Reguera Delgado 393983
|       |-- Modules/            <-- Hello sub-modules are stored here.
Alain Reguera Delgado 393983
|       |   |-- Actions/        <-- Sub-module of Hello but sib-module of Lowercase and Uppercase
Alain Reguera Delgado 393983
|       |   |   `-- actions.sh  <-- sub-module initialization file.
Alain Reguera Delgado 393983
|       |   |-- Lowercase/      <-- Sub-module of Hello but sib-module of Actions and Uppercase.
Alain Reguera Delgado 393983
|       |   |   `-- lowercase.sh
Alain Reguera Delgado 393983
|       |   `-- Uppercase/      <-- Sub-module of Hello but sib-module of Actions and Lowercase.
Alain Reguera Delgado 393983
|       |       `-- uppercase.sh
Alain Reguera Delgado 393983
|       `-- hello.sh
Alain Reguera Delgado 393983
|-- Scripts/
Alain Reguera Delgado 393983
|-- centos-art.conf.sh
Alain Reguera Delgado 393983
`-- centos-art.sh
Alain Reguera Delgado 393983
----------------------------------------------------------------------
Alain Reguera Delgado 393983
======================================================================
Alain Reguera Delgado 393983
Alain Reguera Delgado 393983
The module's initialization file contains the main function definition
Alain Reguera Delgado 393983
of your module. It is a good place to define variables that must be
Alain Reguera Delgado 393983
always available inside the module. There is also a top-comment that
Alain Reguera Delgado 393983
collects information about the function files you are writing (e.g., a
Alain Reguera Delgado 393983
small description, a written by section, the copyright note and the
Alain Reguera Delgado 393983
legal status of the file). Even using a top comment like this is not
Alain Reguera Delgado 393983
required for *centos-art.sh* script to execute modules properly, it is
Alain Reguera Delgado 393983
very useful as matter of consistency and style inside it (and the
Alain Reguera Delgado 393983
copyright and legal notice might be required for legal protection of
Alain Reguera Delgado 393983
your code as set by GPL).  Finally, there is the function definition
Alain Reguera Delgado 393983
named +hello+ just as the directory that holds it but all in lowercase.
Alain Reguera Delgado 393983
Inside this function definition is where we write what we want the
Alain Reguera Delgado 393983
*hello* module does for us. This way, following with the *hello* example,
Alain Reguera Delgado 393983
we create an array variable inside it holding all the suggestions we
Alain Reguera Delgado 393983
would like to print, as described in <<initialization-file>>.
Alain Reguera Delgado 393983
Alain Reguera Delgado 393983
[[initialization-file]]
Alain Reguera Delgado 393983
.The initialization file of 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 393983
    tcar_printMessage "Hello, World!"
Alain Reguera Delgado 393983
Alain Reguera Delgado 393983
}
Alain Reguera Delgado 393983
----------------------------------------------------------------------
Alain Reguera Delgado 393983
======================================================================
Alain Reguera Delgado 393983
Alain Reguera Delgado 393983
You can nest modules by creating directory structures like this,
Alain Reguera Delgado 393983
inside the Modules/ directory of the higher module you want to extend
Alain Reguera Delgado 393983
its functionality.
Alain Reguera Delgado 393983
Alain Reguera Delgado 393983
Inside the repository, modules related to *centos-art.sh* script are
Alain Reguera Delgado 393983
stored in the directory +Automation/Modules/${MODULE_NAME}/+.
Alain Reguera Delgado 393983
Alain Reguera Delgado 393983
*Modules/*::
Alain Reguera Delgado 393983
    This directory contains module's modules.
Alain Reguera Delgado 393983
*Manuals/*::
Alain Reguera Delgado 393983
    This directory contains module's documentation produced by *help*
Alain Reguera Delgado 393983
    module.  The structure of this directory looks as follow:
Alain Reguera Delgado 393983
+
Alain Reguera Delgado 393983
----------------------------------------------------------------------
Alain Reguera Delgado 393983
Manuals/
Alain Reguera Delgado 393983
|-- ${LANG}/
Alain Reguera Delgado 393983
|   |-- man${SECTION_NUMBER}
Alain Reguera Delgado 393983
|   `-- ${MODULE_NAME}.${SECTION_NUMBER}
Alain Reguera Delgado 393983
`-- man${SECTION_NUMBER}
Alain Reguera Delgado 393983
    `-- ${MODULE_NAME}.${SECTION_NUMBER}
Alain Reguera Delgado 393983
----------------------------------------------------------------------
Alain Reguera Delgado 393983
Alain Reguera Delgado 393983
*Locales/*::
Alain Reguera Delgado 393983
    This directory contains module's translations produced by *locale*
Alain Reguera Delgado 393983
    module. The structure of this directory looks as follow:
Alain Reguera Delgado 393983
+
Alain Reguera Delgado 393983
----------------------------------------------------------------------
Alain Reguera Delgado 393983
Locales/
Alain Reguera Delgado 393983
`-- ${LANG}/
Alain Reguera Delgado 393983
    |-- LC_MESSAGES
Alain Reguera Delgado 393983
    |   |-- ${MODULE_NAME}.sh.mo
Alain Reguera Delgado 393983
    |   `-- ${MODULE_NAME}.docbook.mo
Alain Reguera Delgado 393983
    |-- ${MODULE_NAME}.sh.po
Alain Reguera Delgado 393983
    |-- ${MODULE_NAME}.sh.pot
Alain Reguera Delgado 393983
    |-- ${MODULE_NAME}.docbook.po
Alain Reguera Delgado 393983
    `-- ${MODULE_NAME}.docbook.pot
Alain Reguera Delgado 393983
----------------------------------------------------------------------
Alain Reguera Delgado 393983
Alain Reguera Delgado 393983
*Scripts/*::
Alain Reguera Delgado 393983
    This directory contains function scripts written by module's
Alain Reguera Delgado 393983
    writers. Here is where all the tasks the module is useful for are
Alain Reguera Delgado 393983
    written and stored in.  As convention the following structure is
Alain Reguera Delgado 393983
    used:
Alain Reguera Delgado 393983
+
Alain Reguera Delgado 393983
----------------------------------------------------------------------
Alain Reguera Delgado 393983
Scripts/
Alain Reguera Delgado 393983
`-- ${MODULE_NAME}_${FUNCTION_NAME}.sh
Alain Reguera Delgado 393983
----------------------------------------------------------------------
Alain Reguera Delgado 393983
+
Alain Reguera Delgado 393983
{asccidoc-br}
Alain Reguera Delgado 393983
+
Alain Reguera Delgado 393983
Inside each function script, there is a top comment where you should
Alain Reguera Delgado 393983
put the name of the function script, a brief description about what it
Alain Reguera Delgado 393983
does, as well as author and copying information. After the top comment
Alain Reguera Delgado 393983
and separated by one white line, you should define the function
Alain Reguera Delgado 393983
sentence using the long format.
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
#   ${MODULE_NAME}_${FUNCTION_NAME}.sh -- ${FUNCTION_DESCRIPTION}
Alain Reguera Delgado 393983
#
Alain Reguera Delgado 393983
#   Written by:
Alain Reguera Delgado 393983
#   * ${AUTHOR_NAME} <${AUTHOR_EMAIL}>, ${YEARS}
Alain Reguera Delgado 393983
#
Alain Reguera Delgado 393983
# Copyright (C) ${YEAR} 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
Alain Reguera Delgado 393983
# (at 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 ${MODULE_NAME}_${FUNCTION_NAME} {
Alain Reguera Delgado 393983
    ...
Alain Reguera Delgado 393983
}
Alain Reguera Delgado 393983
----------------------------------------------------------------------
Alain Reguera Delgado 393983
+
Alain Reguera Delgado 393983
[NOTE]
Alain Reguera Delgado 393983
If your are planning to contribute a new module to *centos-art.sh*
Alain Reguera Delgado 393983
script, please, consider using the layout described above for all your
Alain Reguera Delgado 393983
function scripts, consistently.
Alain Reguera Delgado 393983
Alain Reguera Delgado 393983
*$\{MODULE_NAME}.asciidoc*::
Alain Reguera Delgado 393983
    This file contains the module's documentation source. From this
Alain Reguera Delgado 393983
    file it is possible to produce the same documentation in other
Alain Reguera Delgado 393983
    formats including manpage, html and pdf. Whenever you need to
Alain Reguera Delgado 393983
    improve the module's documentation, edit this file.
Alain Reguera Delgado 393983
*$\{MODULE_NAME}.conf*::
Alain Reguera Delgado 393983
    This file contains the module's configuration variables. These
Alain Reguera Delgado 393983
    variables are exported to the environment and remain there as long
Alain Reguera Delgado 393983
    as the script execution environment is alive. Some variables are
Alain Reguera Delgado 393983
    read-only others not.
Alain Reguera Delgado 393983
+
Alain Reguera Delgado 393983
The configuration file provides explanation about each environment
Alain Reguera Delgado 393983
variable it exports. If you want to know more about what these
Alain Reguera Delgado 393983
variables are, open this file and read the comments near each
Alain Reguera Delgado 393983
variable.
Alain Reguera Delgado 393983
Alain Reguera Delgado 393983
*$\{MODULE_NAME}.sh*::
Alain Reguera Delgado 393983
    This is the module's initialization script. The first file
Alain Reguera Delgado 393983
    executed when the module called from the command-line. This file
Alain Reguera Delgado 393983
    provides access to argument parsing and controls how
Alain Reguera Delgado 393983
    module-specific function scripts are called. This is the starting
Alain Reguera Delgado 393983
    point for writing modules. You can write a complete module using
Alain Reguera Delgado 393983
    this file only but, frequently, it is convenient as the module
Alain Reguera Delgado 393983
    complexity grows to divide it in smaller pieces (function scripts)
Alain Reguera Delgado 393983
    to improve maintainability and error findings.
Alain Reguera Delgado 393983
Alain Reguera Delgado 393983
// vim: set syntax=asciidoc: