From 788260e3e4a9953218eff634fec8a99041c8ea9c Mon Sep 17 00:00:00 2001 From: Alain Reguera Delgado Date: Sep 22 2013 05:54:51 +0000 Subject: Update centos-art.sh's prepare module. - Previously, the prepare module doesn't fit inside the modular design of centos-art.sh script. As consequence, the prepare actions didn't work. This updates makes the prepare module to fit the centos-art.sh script modular design and prepare module now runs as expected. - The command-line options changed. See centos-art.sh-prepare.1 documentation, also added with this update inside the Manuals directory. Notice that, in this update, the --links option doesn't work because the symlink sub-module isn't implemented inside render module yet. This is an issue of render module not prepare module. - Previously, the prepare module hasn't any documentation in its structure. In this update an initial documentation written in centos-art.sh-prepare.asciidoc file was put in the Manuals directory of prepare module. In this directory there is also a render.conf file that can be used to produce both html and man pages from the asciidoc file. The update of centos-art.sh-preapre module required the following updates to centos-art.sh common scripts: - Add tcar_checkFnEnvironment.sh and tcar_setSubModuleEnvironment.sh files. - Previously, the tcar_checkFiles function didn't verify whether the FILES variable had an empty value or not. Since the FILES variable is used as data source for the loop, all the verifications could be skipped because no data was provided. Because verification were not applied, the work flow continues as no error would be present. This would provoke further calls that required the file to continue to fail because no file was present. This updates the tcar_checkFiles function to verify whether FILES variable has an empty value or not, letting the script execution to finish with an error the way we expect in case of empty value. - Previously, it was not possible to refer the current working directory using the ./ form from the centos-art.sh script command line. With this update the tcar_checkRepoDirSource function was changed to let referring the current directory using the form ./. - Previously, it was not possible to refer the repository's root directory from a place different to repository's root directory. This update changes the tcar_checkRepoDirsource function to let referring the repository's root directory using a single slash (/) as argument to centos-art.sh command. In case more than one slash be passed instead of a single one, they all will be removed in the sake of a single slash only. This way the final location is returned clean. - Previously, module documentation was read from files in the form MODULE_NAME.1, produced from MODULE_NAME.asciidoc files. This may bring confusion to users since it is possible that some modules has the same name of other commands outside centos-art.sh script. To avoid confusion, this update changes the tcar_printHelp function to start using the form centos-art.sh-MODULE_NAME.1 to all modules' documentation. - Previously, error messages produced by tcar_printMessage function were all output to standard error. When errors where produced by functions called inside variable assignment, the error messages produced by tcar_printMessage was stored in the variable and printed in unexpected ways later. This update changes the tcar_printMessage to redirect error messages to standard error. This change fixes the issue of saving error messages inside variables but don't fixes the problem of stop script execution after an error triggered this way. To workaround this last script execution issue, do all the verifications you need before calling functions in the right side of variable assignment constructions. To do that be sure the functions you call will not fail in any way. - Remove the tcar_setFnEnvironment function from Scripts/ directory. The tcar_setModuleEnvironment function should be used instead. We are re-organizing code in a modular fashion and tcar_setFnEnvironment doesn't fit in it. In fact, the tcar_setFnEnvironment has evolved into tcar_setModuleEnvironment. - Previously, when tcar_setModuleEnvironment function tried to load a module and the module didn't exist, it printed an error message telling so, but no reference to the exact non-existent module was mentioned in the error message. This update changes the tcar_setModuleEnvironment function to tell what the non-existent module is. - Previously, everything was treated as a module. Even modules inside modules. It seems like there is no problem with this design when there is no need to call parent modules from children modules. However, when we need to call parents modules from children modules, we cannot use the same name space for both of them because path information is remember only for the last module loaded. If we try to load a parent module from a children module the children module will try to load a module children to it with the name of the parent module we tried to load. If such module doesn't exist, centos-art.sh script shows an error message. To solve this issue, we created two module name-spaces inside the centos-art.sh script. One for parent modules defined by the function tcar_setModuleEnvironment and other for children modules defined for the function tcar_setSubModuleEnvironment. When the centos-art.sh script is executed, it is executed with a parent module that may call several levels of children modules one inside another so the last children has all the information of its parents. In this configuration, you cannot call parent modules from children modules unless the module you are calling is in the first level of modules' directory structure (i.e., Automation/Modules/) and use the tcar_setModuleEnvironment function for that. --- diff --git a/Automation/Modules/Prepare/Configs/render.conf b/Automation/Modules/Prepare/Configs/render.conf deleted file mode 100755 index ddc0201..0000000 --- a/Automation/Modules/Prepare/Configs/render.conf +++ /dev/null @@ -1,8 +0,0 @@ -# -# This file contains the link information used by render module to -# connect vim's configuration. -# -[vimrc] -render-as = "symbolic-link" -source = "${HOME}/.vimrc" -comment = "Default vim's configuration inside the repository." diff --git a/Automation/Modules/Prepare/Configs/vimrc b/Automation/Modules/Prepare/Configs/vimrc deleted file mode 100755 index 5737ebd..0000000 --- a/Automation/Modules/Prepare/Configs/vimrc +++ /dev/null @@ -1,8 +0,0 @@ -set nu -set textwidth=70 -set autoindent -set tabstop=4 -set softtabstop=4 -set shiftwidth=4 -set expandtab -set tags=./tags,tags diff --git a/Automation/Modules/Prepare/Manuals/centos-art.sh-prepare.asciidoc b/Automation/Modules/Prepare/Manuals/centos-art.sh-prepare.asciidoc new file mode 100644 index 0000000..7e8b290 --- /dev/null +++ b/Automation/Modules/Prepare/Manuals/centos-art.sh-prepare.asciidoc @@ -0,0 +1,157 @@ +centos-art.sh-prepare(1) +======================== + +Name +---- + +centos-art.sh-prepare - Prepare your workstation for using the repository. + +Synopsis +-------- + +*centos-art.sh prepare [OPTIONS]* + +Description +----------- + +The first time you download the CentOS artwork repository into your +workstation, you only find source files inside the repository. In +order to produce each component of CentOS corporate visual identity, +it is necessary that you first transform the source files (e.g., ++.svgz+, +.asciidoc+, +.po+) into final files (e.g., +.png+, +.html+, ++.mo+). This process is known as _preparing your workstation to use +the repository_ and is standardized through the *prepare* module. This +way, the *prepare* module is the first command you execute after +downloading a fresh copy of CentOS artwork repository. + +When you execute the *prepare* module without any option, it first +checks existence of required packages (see --packages), then updates +the locale information required by *centos-art.sh* script to show +messages in your current locale, later renders documentation (see +--documents) and images (see --images) using source files available +inside the repository. Finally, it updates the link relation that +connects content inside the repository and the applications outside it +(see --links). + +When you execute the *prepare* module with options, the order in which +preparation actions take place is set by the order in which you passed +the options. See <>, for more information about available +options and what they do. + +Once the *prepare* module completes its execution, both your +workstation and your copy of CentOS artwork repository will be ready +for production. + +[[options]] +Options +------- + +The *prepare* module accepts the following options: + +*--help*:: +*--help="FILE.sh"*:: + When no argument is provided to this option, it shows the module's + documentation for regular users. When a filename and its extension + is provided to this option, documentation for developers is + printed instead. Developers' documentation adds information about + the module's execution environment while user's documentation + doesn't. In order to print developer documentation, the file name + you provide must be part of the module you request help to and + having a related manpage inside the module's Manuals directory. + +*--version*:: + This option shows the module's name and version. + +*--packages*:: + This option verifies whether you have installed the required + packages in your workstation or not. If they are not installed an + error will be printed telling you what the missing package is, so + you can install it. It is important that all the required packages + be installed for *centos-art.sh* script modules to work as + expected. ++ +[NOTE] +====================================================================== +When you are verifying packages, be aware that it is required that you +have installed EPEL repository. The EPEL configuration package +(*epel-release*) isn't part of CentOS distribution and you need to +download it and install it manually. The *epel-release* package can be +found in either of the locations (based on your system version): + + * For CentOS-5: http://download.fedoraproject.org/pub/epel/5/i386/[http://download.fedoraproject.org/pub/epel/5/i386/] + * For CentOS-6: http://download.fedoraproject.org/pub/epel/6/i386/[http://download.fedoraproject.org/pub/epel/6/i386/] +====================================================================== + +*--locales*:: + This option looks for all translatable strings inside the + *centos-art.sh* script, updates the related POT and PO files and + produces the related MO file using the specific locale environment + information the script was run in. If the PO file already have + translations, they are preserved and used to build the MO file. + +*--links*:: + This updates the link information that connects the information + inside the repository with the information outside the repository. + For example, inside the repository we have the font information + required to build messages in specific typography, such + information isn't by default in the default system locations so we + install them in the home directory of the user running the + *prepare* module, using symbolic links. ++ +Whenever you need to update this information, use this option. Take +care that all links previously created in the target location will be +removed and recreated again. So, you can change the name relation in +the configuration files and install the changes without leaving broken +links in the target location. ++ +The file that controls the link configuration is inside the repository +at +Automation/Modules/Prepare/Modules/Links/Configs/render.conf+. + +*--images*:: + This option produces images from source files available inside the + repository, using the correct order. When you use this option, + centos-art.sh script calls the render module internally which + produces content for all configuration (+render.conf+) files found + inside the repository. + +*--documents*:: + This options produces documentation from source files available + inside the repository. When you pass this option, the current + locale information is considered to produce the documentation. If + the current locale doesn't have translation files set for the + current locale information, English language is used as default + language. + +Author +------ + +The *prepare* module has received contributions from the following +people: + + * Alain Reguera Delgado , 2009-2013 + +Copyright +--------- + +Copyright (C) 2009-2013 The CentOS Project + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at +your option) any later version. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +See Also +-------- + +centos-art.sh(1), centos-art.sh-render(1), centos-art.sh-locale(1) + +// vim: set syntax=asciidoc: diff --git a/Automation/Modules/Prepare/Manuals/render.conf b/Automation/Modules/Prepare/Manuals/render.conf new file mode 100644 index 0000000..5a3c4e3 --- /dev/null +++ b/Automation/Modules/Prepare/Manuals/render.conf @@ -0,0 +1,7 @@ +[centos-art.sh-prepare] +render-type = "asciidoc" +render-flow = "manpage" +render-from = "centos-art.sh-prepare.asciidoc" +locale-from = "${TCAR_SCRIPT_LANG_LC}/prepare.po" +formats = "xhtml manpage" +mansect = "1" diff --git a/Automation/Modules/Prepare/Modules/Documents/documents.sh b/Automation/Modules/Prepare/Modules/Documents/documents.sh new file mode 100755 index 0000000..52e24b6 --- /dev/null +++ b/Automation/Modules/Prepare/Modules/Documents/documents.sh @@ -0,0 +1,46 @@ +#!/bin/bash +###################################################################### +# +# documents.sh -- This function renders all documentation files +# inside the repository using the render module. +# +# Written by: +# * Alain Reguera Delgado , 2009-2013 +# +# Copyright (C) 2009-2013 The CentOS Project +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +###################################################################### + +function documents { + + # Define base location where configuration files will be searched + # from. You can provide more than one location here. + local DIRS='/' + + # Define the name of the option you want to look configuration + # files for. + local NAME='render-type' + + # Define the value of the option you want to look configuration + # files for. + local VALUE='asciidoc' + + # Render configuration files that match specified options and + # values in the search directories. + prepare_setRenderEnvironment -o "${NAME}" -v "${VALUE}" "${DIRS}" + +} diff --git a/Automation/Modules/Prepare/Modules/Images/images.sh b/Automation/Modules/Prepare/Modules/Images/images.sh new file mode 100755 index 0000000..cdcee29 --- /dev/null +++ b/Automation/Modules/Prepare/Modules/Images/images.sh @@ -0,0 +1,58 @@ +#!/bin/bash +###################################################################### +# +# images.sh -- This function renders all configuration images files +# inside the repository, using the render module and the correct +# production order. +# +# Written by: +# * Alain Reguera Delgado , 2009-2013 +# +# Copyright (C) 2009-2013 The CentOS Project +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +###################################################################### + +function images { + + # CAUTION: The order in which repository components are processed + # affect the final result. For instance, in order for theme images + # to hold the CentOS branding information the `Artworks/Brands' + # directory must be rendered before the `Artworks/Themes' + # directory. The reason of this is that brand images are not + # drawn inside theme design models but combined with them using + # ImageMagick, once they both have been rendered as PNG files. + + # Define base location where configuration files will be searched + # from. You can provide more than one location here. + local DIRS="\ + Artworks/Brands\ + Artworks/Documentation\ + Artworks/Themes" + + # Define the name of the option you want to look configuration + # files for. + local NAME='render-type' + + # Define the value of the option you want to look configuration + # files for. + local VALUE='svg' + + # Render configuration files that match specified options and + # values in the search directories. + prepare_setRenderEnvironment -o "${NAME}" -v "${VALUE}" "${DIRS}" + +} diff --git a/Automation/Modules/Prepare/Modules/Links/Configs/render.conf b/Automation/Modules/Prepare/Modules/Links/Configs/render.conf new file mode 100755 index 0000000..c104585 --- /dev/null +++ b/Automation/Modules/Prepare/Modules/Links/Configs/render.conf @@ -0,0 +1,26 @@ +# Install centos-art command. +[centos-art] +render-type = "symlink" +link-source = "${HOME}/bin/" +link-target = "${TCAR_BASEDIR}/Automation/centos-art.sh" + +# Install vim's settings used as convention to edit files inside the +# repository. In case the conventions change, and link-target is +# updated inside the repository, the new conventions will be available +# to you immediately after fetching changes from central repository. +[vimrc] +render-type = "symlink" +link-source = "${HOME}/.vimrc" +link-target = "${TCAR_BASEDIR}/Modules/Prepare/Modules/Links/Configs/vimrc" + +# Install corporate typography. +[denmark.ttf] +render-type = "symlink" +link-source = "${HOME}/.fonts/denmark.ttf" +link-target = "${TCAR_BASEDIR}/Artworks/Fonts/denmark.ttf" + +# Install corporate palette of colors (for inkscape). +[corporate.gpl] +render-type = "symlink" +link-source = "${HOME}/.inkscape/palettes/corporate.gpl" +link-target = "${TCAR_BASEDIR}/Artworks/Palettes/corporate.gpl" diff --git a/Automation/Modules/Prepare/Modules/Links/Configs/vimrc b/Automation/Modules/Prepare/Modules/Links/Configs/vimrc new file mode 100755 index 0000000..5737ebd --- /dev/null +++ b/Automation/Modules/Prepare/Modules/Links/Configs/vimrc @@ -0,0 +1,8 @@ +set nu +set textwidth=70 +set autoindent +set tabstop=4 +set softtabstop=4 +set shiftwidth=4 +set expandtab +set tags=./tags,tags diff --git a/Automation/Modules/Prepare/Modules/Links/links.sh b/Automation/Modules/Prepare/Modules/Links/links.sh new file mode 100755 index 0000000..8b77cc5 --- /dev/null +++ b/Automation/Modules/Prepare/Modules/Links/links.sh @@ -0,0 +1,50 @@ +#!/bin/bash +###################################################################### +# +# links.sh -- This function renders configuration files inside +# automation scripts directory structure, using the render module. +# These configuration files are mainly used to connect content +# inside the repository with applications outside the repository, +# using symbolic links. +# +# Written by: +# * Alain Reguera Delgado , 2009-2013 +# +# Copyright (C) 2009-2013 The CentOS Project +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +###################################################################### + +function links { + + # Define base location where configuration files will be searched + # from. You can provide more than one location here. + local DIRS="/" + + # Define the name of the option you want to look configuration + # files for. + local NAME='render-type' + + # Define the value of the option you want to look configuration + # files for. + local VALUE='symlink' + + # Render configuration files that match specified options and + # values in the search directories. + prepare_setRenderEnvironment -o "${NAME}" -v "${VALUE}" "${DIRS}" + +} + diff --git a/Automation/Modules/Prepare/Modules/Locales/locales.sh b/Automation/Modules/Prepare/Modules/Locales/locales.sh new file mode 100755 index 0000000..c07ddac --- /dev/null +++ b/Automation/Modules/Prepare/Modules/Locales/locales.sh @@ -0,0 +1,33 @@ +#!/bin/bash +###################################################################### +# +# locales.sh -- This module retrieves translatable strings from +# automation scripts and creates the related machine objects, so +# script messages can be rendered in different languages. +# +# Written by: +# * Alain Reguera Delgado , 2009-2013 +# +# Copyright (C) 2009-2013 The CentOS Project +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +###################################################################### + +function locales { + + tcar_setModuleEnvironment locale "Automation/centos-art.sh" --update + +} diff --git a/Automation/Modules/Prepare/Modules/Packages/packages.sh b/Automation/Modules/Prepare/Modules/Packages/packages.sh new file mode 100755 index 0000000..74dc9db --- /dev/null +++ b/Automation/Modules/Prepare/Modules/Packages/packages.sh @@ -0,0 +1,56 @@ +#!/bin/bash +###################################################################### +# +# packages.sh -- This function defines and verifies packages +# required by centos-art.sh script. +# +# Written by: +# * Alain Reguera Delgado , 2009-2013 +# +# Copyright (C) 2009-2013 The CentOS Project +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +###################################################################### + +function packages { + + # Define required packages used by centos-art.sh script inside + # CentOS base repository. + local BASE_PACKAGES="ImageMagick netpbm netpbm-progs syslinux gimp + coreutils texinfo texinfo-tex info tetex-latex tetex-fonts + tetex-xdvi tetex-dvips gettext texi2html libxml2 + gnome-doc-utils elinks docbook-style-xsl docbook-utils + docbook-dtds docbook-style-dsssl docbook-simple + docbook-utils-pdf docbook-slides firefox sudo yum rpm ctags + vim-enhanced" + + # Define required packages used by centos-art.sh script inside + # EPEL repository. Start verifying the package that contains + # repository configuration, then everything else. + local EPEL_PACKAGES="epel-release inkscape asciidoc" + + # Verify required packages. The order in which packages are + # verified my help to reduce some loops (e.g., verify packages + # containing the repository's configuration files first and + # packages from that repository later. It is rather possible that + # you won't be able to install any package from a repository you + # don't have configuration files for, in first place). + tcar_checkFiles -n ${BASE_PACKAGES} ${EPEL_PACKAGES} + + # Print a confirmation message here. + tcar_printMessage "`gettext "All required packages are installed already."`" --as-stdout-line + +} diff --git a/Automation/Modules/Prepare/prepare.conf.sh b/Automation/Modules/Prepare/prepare.conf.sh deleted file mode 100755 index e53951b..0000000 --- a/Automation/Modules/Prepare/prepare.conf.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash -###################################################################### -# -# prepare.conf.sh -- This file provides the configuration variables -# used by prepare module. -# -# Written by: -# * Alain Reguera Delgado , 2013 -# -# Copyright (C) 2013 The CentOS Project -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or (at -# your option) any later version. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -# -###################################################################### - -declare -xr MODULE_VERSION='0.1' -declare -x MODULE_ACTIONS='' diff --git a/Automation/Modules/Prepare/prepare.sh b/Automation/Modules/Prepare/prepare.sh index 3e1a945..6c15cfd 100755 --- a/Automation/Modules/Prepare/prepare.sh +++ b/Automation/Modules/Prepare/prepare.sh @@ -1,8 +1,8 @@ #!/bin/bash ###################################################################### # -# prepare.sh -- This function standardizes configuration tasks -# needed by files inside the working copy. +# prepare.sh -- This module standardizes repository configuration +# tasks. # # When you download a fresh working copy of CentOS artwork # repository, most of its content is in source format. You need to @@ -36,16 +36,19 @@ function prepare { - # Interpret arguments and options passed through command-line. + local SUBMODULE='' + local SUBMODULES='' + prepare_getOptions "${@}" - # Reset positional parameters on this function, using output - # produced from (getopt) arguments parser. eval set -- "${TCAR_ARGUMENTS}" - # Execute module-specific actions. - for MODULE_ACTION in ${MODULE_ACTIONS};do - ${MODULE_ACTION} "${@}" + if [[ -z ${SUBMODULES} ]];then + SUBMODULES='packages locales images docs links' + fi + + for SUBMODULE in ${SUBMODULES};do + tcar_setSubModuleEnvironment "${SUBMODULE}" "${@}" done } diff --git a/Automation/Modules/Prepare/prepare_getOptions.sh b/Automation/Modules/Prepare/prepare_getOptions.sh index 7c06e41..558ebd1 100755 --- a/Automation/Modules/Prepare/prepare_getOptions.sh +++ b/Automation/Modules/Prepare/prepare_getOptions.sh @@ -30,15 +30,10 @@ function prepare_getOptions { # Define short options we want to support. - local ARGSS="h,v,q,y" + local ARGSS="h::,v" # Define long options we want to support. - local ARGSL="help,version,quiet,yes,packages,repository" - - # Define module arguments local to this function. This is very - # important in order to provide option parsing for different - # function environment levels. - local TCAR_ARGUMENTS='' + local ARGSL="help::,version,packages,locales,links,documents,images" # Redefine arguments using getopt(1) command parser. tcar_setArguments "${@}" @@ -49,7 +44,7 @@ function prepare_getOptions { # Look for options passed through command-line. while true; do - case "$1" in + case "${1}" in -h | --help ) tcar_printHelp @@ -59,36 +54,32 @@ function prepare_getOptions { tcar_printVersion ;; - -q | --quiet ) - TCAR_FLAG_QUIET="true" + --packages ) + SUBMODULES="${SUBMODULES} packages" shift 1 ;; - -y | --yes ) - TCAR_FLAG_YES="true" + --locales ) + SUBMODULES="${SUBMODULES} locales" shift 1 ;; - --packages ) - MODULE_ACTIONS="${MODULE_ACTIONS} prepare_setPackages" + --links ) + SUBMODULES="${SUBMODULES} links" shift 1 ;; - --repository ) - MODULE_ACTIONS="${MODULE_ACTIONS} prepare_setRepository" + --documents ) + SUBMODULES="${SUBMODULES} documents" + shift 1 + ;; + + --images ) + SUBMODULES="${SUBMODULES} images" shift 1 ;; -- ) - # Remove the `--' argument from the list of arguments - # in order for processing non-option arguments - # correctly. At this point all option arguments have - # been processed already but the `--' argument still - # remains to mark ending of option arguments and - # beginning of non-option arguments. The `--' argument - # needs to be removed here in order to avoid - # centos-art.sh script to process it as a path inside - # the repository, which obviously is not. shift 1 break ;; @@ -96,4 +87,8 @@ function prepare_getOptions { esac done + # Redefine arguments using current positional parameters. Only + # paths should remain as arguments, at this point. + TCAR_ARGUMENTS="${@}" + } diff --git a/Automation/Modules/Prepare/prepare_setPackages.sh b/Automation/Modules/Prepare/prepare_setPackages.sh deleted file mode 100755 index 142ed66..0000000 --- a/Automation/Modules/Prepare/prepare_setPackages.sh +++ /dev/null @@ -1,72 +0,0 @@ -#!/bin/bash -###################################################################### -# -# prepare_setPackages.sh -- This function verifies packages -# required by centos-art.sh script and prints a list of installed -# and missing packages based on it. -# -# Written by: -# * Alain Reguera Delgado , 2009-2013 -# -# Copyright (C) 2009-2013 The CentOS Project -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or (at -# your option) any later version. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -# -###################################################################### - -function prepare_setPackages { - - local PACKAGES_REQUIRED="inkscape ImageMagick netpbm - netpbm-progs syslinux gimp coreutils texinfo texinfo-tex info - tetex-latex tetex-fonts tetex-xdvi tetex-dvips gettext texi2html - gnome-doc-utils elinks docbook-style-xsl docbook-utils - docbook-dtds docbook-style-dsssl docbook-simple docbook-utils-pdf - docbook-slides firefox sudo yum rpm ctags vim-enhanced asciidoc - dblatex" - - local -x PACKAGES_THIRDPARTY='(inkscape|asciidoc|dblatex)' - - for PACKAGE in ${PACKAGES_REQUIRED};do - rpm -q ${PACKAGE} --quiet - if [[ $? -ne 0 ]];then - PACKAGES_UNINSTALLED="${PACKAGES_UNINSTALLED} ${PACKAGE}" - fi - done - - local YUM_OPTIONS='' - if [[ ${TCAR_FLAG_YES} == 'true' ]];then - YUM_OPTIONS='-y' - fi - if [[ ${TCAR_FLAG_QUIET} == 'true' ]];then - YUM_OPTIONS="${YUM_OPTIONS} --quiet" - fi - - if [[ ! -z ${PACKAGES_UNINSTALLED} ]];then - tcar_printMessage "`gettext "The following packages need to be installed:"`" --as-banner-line - for PACKAGE in ${PACKAGES_UNINSTALLED};do - if [[ ${PACKAGE} =~ ${PACKAGES_THIRDPARTY} ]];then - tcar_printMessage "${PACKAGE} (`gettext "from third party repository"`)" --as-response-line - else - tcar_printMessage "${PACKAGE}" --as-response-line - fi - done - tcar_printMessage '-' --as-separator-line - tcar_printMessage "`gettext "Do you want to continue"`" --as-yesornorequest-line - sudo yum install ${YUM_OPTIONS} ${PACKAGES_UNINSTALLED} - else - tcar_printMessage "`gettext "All required packages are already installed."`" --as-banner-line - fi - -} diff --git a/Automation/Modules/Prepare/prepare_setRenderEnvironment.sh b/Automation/Modules/Prepare/prepare_setRenderEnvironment.sh new file mode 100755 index 0000000..84c3668 --- /dev/null +++ b/Automation/Modules/Prepare/prepare_setRenderEnvironment.sh @@ -0,0 +1,114 @@ +#!/bin/bash +###################################################################### +# +# prepare_setRenderEnvironment.sh -- This function provides a secure +# interface to render content outside the render module. You can use +# this function to call the render module from other modules, +# safely. +# +# This function builds a list of all available configuration files +# in locations passed as argument and reduces the list by applying +# regular expression patterns to each file in the list. Only files +# that match the regular expression pattern will remain in the final +# list. The regular expression patterns are applied to file's +# content, generally to find out if it has an specific option, value +# or combination of both inside. Later, the resultant list of +# configuration files is passed to render module for processing. +# +# This function verifies the search path provided to render module +# to grant it is inside the repository before passing it to render +# module for processing. +# +# Written by: +# * Alain Reguera Delgado , 2009-2013 +# +# Copyright (C) 2009-2013 The CentOS Project +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +###################################################################### + +function prepare_setRenderEnvironment { + + OPTIND=1 + while getopts "o:,v:" OPTION ${@}; do + + case "${OPTION}" in + + o ) + # Define the name of the option you want to look + # configuration files for. + local OPTION_NAME=${OPTARG} + if [[ -z ${OPTION_NAME} ]];then + tcar_printMessage "`gettext "The option name cannot be empty."`" --as-error-line + fi + ;; + + v ) + # Define the value of the option you want to look + # configuration files for. + local OPTION_VALUE=${OPTARG} + if [[ -z ${OPTION_VALUE} ]];then + tcar_printMessage "`gettext "The option value cannot be empty."`" --as-error-line + fi + ;; + + esac + + done + + # Clean up positional parameters to reflect the fact that options + # have been processed already. + shift $(( ${OPTIND} - 1 )) + + # Now that option arguments have been removed from positional + # parameter, verify all other remaining arguments (the search + # paths) do exist. They are required to search. + if [[ -z ${@} ]];then + tcar_printMessage "`gettext "The search path cannot be empty."`" --as-error-line + fi + + # Define array variable to store configuration file paths. + local -a CONFIGURATION + + # Define final filter regular expression. This regular expression + # must match the option = "value" format we are using inside + # configuration files. + local CONFIGURATION_PATTERN="^${OPTION_NAME}[[:space:]]*=[[:space:]]*\"${OPTION_VALUE}\"$" + + for DIRECTORY in ${@};do + + # Clean-up the search path. This location must point a + # directory inside the repository. References to directories + # outside the repository are not supported. + DIRECTORY=$(tcar_checkRepoDirSource ${DIRECTORY}) + + # Verify the search path. It must exist and being a directory. + tcar_checkFiles -ed ${DIRECTORY} + + # Define the list of configuration files the render module + # will use as reference to produce documentation. At this + # point it is very difficult that DIRECTORY doesn't exist or + # be outside the repository directory structure. + CONFIGURATION[++((${#CONFIGURATION[*]}))]=$(tcar_getFilesList \ + ${DIRECTORY} --pattern='.+\.conf$' --type='f' \ + | xargs egrep ${CONFIGURATION_PATTERN} | cut -d: -f1 | sort | uniq) + + done + + # Process the list of configuration files using the render module. + tcar_setModuleEnvironment render ${CONFIGURATION[*]} + +} diff --git a/Automation/Modules/Prepare/prepare_setRepository.sh b/Automation/Modules/Prepare/prepare_setRepository.sh deleted file mode 100755 index 345789f..0000000 --- a/Automation/Modules/Prepare/prepare_setRepository.sh +++ /dev/null @@ -1,61 +0,0 @@ -#!/bin/bash -###################################################################### -# -# prepare_setRepository.sh -- This function builds a list of all -# configuration files inside the repository and calls the render -# module for processing it. -# -# Written by: -# * Alain Reguera Delgado , 2009-2013 -# -# Copyright (C) 2009-2013 The CentOS Project -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or (at -# your option) any later version. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -# -###################################################################### - -function prepare_setRepository { - - # Build list of configuration files to be produced. - local CONFIGURATION_FILES=$(tcar_getFilesList \ - ${TCAR_BASEDIR} --type="f" --pattern=".+/${FILENAME}\.conf") - - # Verify list of configuration files. - if [[ -z ${CONFIGURATION_FILES} ]];then - return - fi - - # CAUTION: The order in which configuration files are processed is - # relevant to final production result. For example, in order for - # theme images to hold the branding information the - # `Artworks/Brands' directory must be rendered before the - # `Artworks/Themes' directory. The reason of this is that brand - # images are not drawn inside theme design models themselves, but - # combined with theme images using the ImageMagick tool suite once - # they both have been rendered as PNG files. - - # Rebuild the list of configuration files to grant brand correct - # production order when they are included in the list of files to - # produce. - echo "${CONFIGURATION_FILES}" | grep "${TCAR_BASEDIR}/Artworks/Brands" > /dev/null - if [[ $? -eq 0 ]];then - CONFIGURATION_FILES="${TCAR_BASEDIR}/Artworks/Brands - $(echo "${CONFIGURATION_FILES}" | grep -v "${TCAR_BASEDIR}/Artworks/Brands")" - fi - - # Process configuration files using render module. - tcar_setFnEnvironment render ${CONFIGURATION_FILES} - -} diff --git a/Automation/Scripts/tcar_checkFiles.sh b/Automation/Scripts/tcar_checkFiles.sh index 24638e9..6c47486 100755 --- a/Automation/Scripts/tcar_checkFiles.sh +++ b/Automation/Scripts/tcar_checkFiles.sh @@ -107,6 +107,13 @@ function tcar_checkFiles { local FILE='' local FILES=${@} + # Verify existence of files to prevent centos-art.sh script from + # using the current location in cases when it shouldn't (e.g., + # here it is expecting a list of files to process.). + if [[ -z ${FILES} ]];then + tcar_printMessage "`gettext "No file for processing found."`" --as-error-line + fi + for FILE in ${FILES};do until [[ ${COUNTER} -eq ${#CONDITION_PATTERN[*]} ]];do @@ -118,14 +125,6 @@ function tcar_checkFiles { || tcar_printMessage "${FILE} ${CONDITION_MESSAGE[${COUNTER}]}" --as-error-line ;; - "centos-art" ) - # Don't create another level for error messages here - # (that would duplicate them unnecessarily). Instead, - # set error messages inside specific functionalities - # and use them directly from there. - tcar_setFnEnvironment ${CONDITION_PATTERN[${COUNTER}]} ${FILE} - ;; - "/usr/bin/file" ) if [[ ! $(${CONDITION_COMMAND[${COUNTER}]} ${CONDITION_PATTERN[${COUNTER}]} ${FILE}) =~ "^${MIME}" ]];then tcar_printMessage "${FILE} ${CONDITION_MESSAGE[${COUNTER}]}" --as-error-line diff --git a/Automation/Scripts/tcar_checkRepoDirSource.sh b/Automation/Scripts/tcar_checkRepoDirSource.sh index 0b70b4b..4a92253 100755 --- a/Automation/Scripts/tcar_checkRepoDirSource.sh +++ b/Automation/Scripts/tcar_checkRepoDirSource.sh @@ -5,7 +5,7 @@ # construction of directories inside the working copy, using # absolute paths. This function transforms relative paths passed as # non-option arguments to centos-art.sh script command-line into -# absolute paths inside the working copy based on whether you are +# absolute paths inside the working copy, based on whether you are # using Subversion or Git as version control system. Further # verifications, (e.g., whether they really exist as directories # inside the working copy or not) should be realized outside this @@ -51,11 +51,11 @@ function tcar_checkRepoDirSource { # used as default location). However, it might be useful to use a # dot as argument when you want to include the current location in # a list of arguments to process. Don't forget that dot slash can - # be used to refere locations relatively. - LOCATION=$(echo "${LOCATION}" | sed -r "s,^\.(/[[:alnum:]_/-.]+)?$,$(pwd)\1,g") + # be used to refer locations relatively. + LOCATION=$(echo "${LOCATION}" | sed -r "s,^\.(/([[:alnum:]_/-.]+)?)?$,$(pwd)\1,g") - # Remove the working directory absolute path from location to - # avoid path duplications here. + # Remove the path to repository's base directory from location in + # order to avoid path duplications here. LOCATION=$(echo "${LOCATION}" | sed "s,${TCAR_BASEDIR}/,,g") # When we use Git as version control system, there isn't a need of @@ -85,7 +85,11 @@ function tcar_checkRepoDirSource { # stored inside variables.). LOCATION=${TCAR_BASEDIR}/${LOCATION} - # Output the absolute path to location. - echo "${LOCATION}" + # Remove trailing slashes passed as argument. The single slash + # form is used to refer the repository's root directory. The + # single slash form passed as argument of centos-art.sh script is + # useful to execute commands over the + # entire repository tree. + echo "${LOCATION}" | sed -r -e 's,/+,/,g' -e 's,/+$,,g' } diff --git a/Automation/Scripts/tcar_printHelp.sh b/Automation/Scripts/tcar_printHelp.sh index f62b703..7f279b2 100755 --- a/Automation/Scripts/tcar_printHelp.sh +++ b/Automation/Scripts/tcar_printHelp.sh @@ -27,9 +27,9 @@ function tcar_printHelp { - local MANPAGE="${MODULE_NAME}" + local MANPAGE="${TCAR_SCRIPT_NAME}-${MODULE_NAME}" - if [[ ! -z ${1} ]];then + if [[ -n ${1} ]];then MANPAGE=${1} fi diff --git a/Automation/Scripts/tcar_printMessage.sh b/Automation/Scripts/tcar_printMessage.sh index 473ce88..48da419 100755 --- a/Automation/Scripts/tcar_printMessage.sh +++ b/Automation/Scripts/tcar_printMessage.sh @@ -77,7 +77,7 @@ function tcar_printMessage { # Build the error message. tcar_printMessage '-' --as-separator-line - tcar_printMessage "$(tcar_printCaller 1) ${MESSAGE}" --as-stdout-line + tcar_printMessage "$(tcar_printCaller 1) ${MESSAGE}" --as-stderr-line tcar_printMessage '-' --as-separator-line # Finish script execution with exit status 1 (SIGHUP) to @@ -99,10 +99,10 @@ function tcar_printMessage { echo "${TCAR_SCRIPT_BASEDIR}/${TCAR_SCRIPT_NAME}" 1>&2 while [[ ${COUNT} -gt 0 ]];do if [[ ${COUNT} -eq $(( ${#FN[*]} - 2 )) ]];then - echo ${SEPARATOR} ${FN[${COUNT}]} + echo ${SEPARATOR} ${FN[${COUNT}]} 1>&2 else echo ${FN[${COUNT}]} \ - | gawk '{ printf "%'${SPACES}'s%s %s\n", "", "'${SEPARATOR}'", $1 }' + | gawk '{ printf "%'${SPACES}'s%s %s\n", "", "'${SEPARATOR}'", $1 }' 1>&2 fi COUNT=$((${COUNT} - 1)) SPACES=$((${SPACES} + 4)) @@ -112,9 +112,9 @@ function tcar_printMessage { --as-suggestion-line ) # Build the error message. - tcar_printMessage "${TCAR_SCRIPT_COMMAND} ($(tcar_printCaller 1)):" --as-stdout-line - tcar_printMessage "`gettext "The path provided cannot be processed the way you entered it."`" --as-stdout-line - tcar_printMessage "`gettext "Instead, try the following equivalence:"` ${MESSAGE}" --as-stdout-line + tcar_printMessage "${TCAR_SCRIPT_COMMAND} ($(tcar_printCaller 1)):" --as-stderr-line + tcar_printMessage "`gettext "The path provided cannot be processed the way you entered it."`" --as-stderr-line + tcar_printMessage "`gettext "Instead, try the following equivalence:"` ${MESSAGE}" --as-stderr-line tcar_printMessage "${MODULE_NAME}" --as-toknowmore-line # Finish script execution with exit status 1 (SIGHUP) to @@ -125,7 +125,7 @@ function tcar_printMessage { ;; --as-toknowmore-line ) - tcar_printMessage "`gettext "To know more, run"` ${TCAR_SCRIPT_COMMAND} ${MESSAGE} --help" --as-stdout-line + tcar_printMessage "`gettext "To know more, run"` ${TCAR_SCRIPT_COMMAND} ${MESSAGE} --help" --as-stderr-line ;; --as-yesornorequest-line ) diff --git a/Automation/Scripts/tcar_setFnEnvironment.sh b/Automation/Scripts/tcar_setFnEnvironment.sh deleted file mode 100755 index 8e3461d..0000000 --- a/Automation/Scripts/tcar_setFnEnvironment.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/bash -###################################################################### -# -# tcar_setFnEnvironment.sh -- This function standardizes the way -# centos-art.sh script is called to itself. The main purpose of this -# somehow own interface is to control the parent script flow based -# on specific function environments exit status. -# -# Written by: -# * Alain Reguera Delgado , 2009-2013 -# -# Copyright (C) 2009-2013 The CentOS Project -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or (at -# your option) any later version. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -# -###################################################################### - -function tcar_setFnEnvironment { - - # Execute specific function environment. - ${MODULE_NAME} ${@} - - # Retrieve exit status. - local STATUS=$? - - # Finish script execution based on exit status. - if [[ ${STATUS} -ne 0 ]];then - exit ${STATUS} - fi - -} diff --git a/Automation/Scripts/tcar_setModuleEnvironment.sh b/Automation/Scripts/tcar_setModuleEnvironment.sh index 84cfc26..1bc3907 100755 --- a/Automation/Scripts/tcar_setModuleEnvironment.sh +++ b/Automation/Scripts/tcar_setModuleEnvironment.sh @@ -1,8 +1,9 @@ #!/bin/bash ###################################################################### # -# tcar_setModuleEnvironment.sh -- This function initiates module -# environments inside the centos-art.sh script. +# tcar_setModuleEnvironment.sh -- This function initiates +# first-level module (or simply, module) environments inside the +# centos-art.sh script. # # Written by: # * Alain Reguera Delgado , 2009-2013 @@ -37,7 +38,7 @@ function tcar_setModuleEnvironment { # Check module's name possible values. if [[ ! ${MODULE_NAME} =~ "^(${MODULE_NAME_LIST})$" ]];then - tcar_printMessage "`gettext "The module provided isn't valid."`" --as-error-line + tcar_printMessage "`eval_gettext "The module (\\\$MODULE_NAME) isn't supported yet."`" --as-error-line fi # Define module's directory. @@ -48,6 +49,10 @@ function tcar_setModuleEnvironment { local MODULE_DIR_MANUALS=${MODULE_DIR}/Manuals local MODULE_DIR_CONFIGS=${MODULE_DIR}/Configs + # Define the sub-module's base directory where sub-module + # processing will start from. + local SUBMODULE_BASEDIR=${MODULE_DIR_MODULES} + # Define module's initialization file. local MODULE_INIT_FILE=${MODULE_DIR}/${MODULE_NAME}.sh @@ -59,23 +64,10 @@ function tcar_setModuleEnvironment { # start counting from second argument on, inclusively. shift 1 - # Redefine module-specific configuration values. - if [[ -f ${MODULE_DIR}/${MODULE_NAME}.conf.sh ]];then - . ${MODULE_DIR}/${MODULE_NAME}.conf.sh - fi - - # Verify the number of arguments passed to centos-art.sh script. - # By default, to all modules, when no argument is provided after - # the module name, use the current directory as default directory - # to look for configuration files. - if [[ $# -eq 0 ]];then - set -- ${PWD} - fi - # Load module-specific (function) scripts into current execution # environment. Keep the tcar_setModuleEnvironmentScripts function # call after all variables and arguments definitions. - tcar_setModuleEnvironmentScripts + tcar_setModuleEnvironmentScripts "${MODULE_DIR}" "${MODULE_NAME}" "${MODULE_INIT_FILE}" # Execute module-specific initialization script. ${MODULE_NAME} "${@}" diff --git a/Automation/Scripts/tcar_setModuleEnvironmentScripts.sh b/Automation/Scripts/tcar_setModuleEnvironmentScripts.sh index 25dc9c2..280069e 100755 --- a/Automation/Scripts/tcar_setModuleEnvironmentScripts.sh +++ b/Automation/Scripts/tcar_setModuleEnvironmentScripts.sh @@ -28,6 +28,10 @@ function tcar_setModuleEnvironmentScripts { + local MODULE_DIR="${1}" + local MODULE_NAME="${2}" + local MODULE_INIT_FILE="${3}" + # Define the pattern used to retrieve function names from function # files. local FUNCTION_PATTERN="^function[[:space:]]+${MODULE_NAME}(_[[:alnum:]]+)?[[:space:]]+{[[:space:]]*$" diff --git a/Automation/Scripts/tcar_setSubModuleEnvironment.sh b/Automation/Scripts/tcar_setSubModuleEnvironment.sh new file mode 100755 index 0000000..f1fbbfc --- /dev/null +++ b/Automation/Scripts/tcar_setSubModuleEnvironment.sh @@ -0,0 +1,83 @@ +#!/bin/bash +###################################################################### +# +# tcar_setSubModuleEnvironment.sh -- This function initiates +# modules' sub-module environments inside the centos-art.sh script. +# +# Written by: +# * Alain Reguera Delgado , 2009-2013 +# +# Copyright (C) 2013 The CentOS Project +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +###################################################################### + +function tcar_setSubModuleEnvironment { + + # Define sub-module's name (SUBMODULE_NAME) using the first + # argument in the command-line. + local SUBMODULE_NAME=$(tcar_getRepoName "${1}" "-f" | cut -d '-' -f1) + + # Define regular expression to match available sub-modules. + local SUBMODULE_NAME_LIST=$(ls ${SUBMODULE_BASEDIR} \ + | tr '\n' '|' | sed -r 's/\|$//' | tr '[[:upper:]]' '[[:lower:]]') + + # Check sub-module's name possible values. + if [[ ! ${SUBMODULE_NAME} =~ "^(${SUBMODULE_NAME_LIST})$" ]];then + tcar_printMessage "`eval_gettext "The sub-module (\\\$SUBMODULE_NAME) isn't supported yet."`" --as-error-line + fi + + # Define sub-module's directory. + local SUBMODULE_DIR=${SUBMODULE_BASEDIR}/$(tcar_getRepoName "${SUBMODULE_NAME}" "-d") + + # Define sub-module's related directories. + local SUBMODULE_DIR_MODULES=${SUBMODULE_DIR}/Modules + local SUBMODULE_DIR_MANUALS=${SUBMODULE_DIR}/Manuals + local SUBMODULE_DIR_CONFIGS=${SUBMODULE_DIR}/Configs + + # Reset sub-module's current directory. + local SUBMODULE_BASEDIR=${SUBMODULE_DIR_MODULES} + + # Define sub-module's initialization file. + local SUBMODULE_INIT_FILE=${SUBMODULE_DIR}/${SUBMODULE_NAME}.sh + + # Check function script execution rights. + tcar_checkFiles -ex ${SUBMODULE_INIT_FILE} + + # Remove the first argument passed to centos-art.sh command-line + # in order to build optional arguments inside functionalities. We + # start counting from second argument on, inclusively. + shift 1 + + # Verify the number of arguments passed to centos-art.sh script. + # By default, to all sub-modules, when no argument is provided + # after the sub-module name, use the current directory as default + # directory to look for configuration files. + if [[ $# -eq 0 ]];then + set -- ${PWD} + fi + + # Load sub-module-specific (function) scripts into current + # execution environment. + tcar_setModuleEnvironmentScripts "${SUBMODULE_DIR}" "${SUBMODULE_NAME}" "${SUBMODULE_INIT_FILE}" + + # Execute sub-module-specific initialization script. + ${SUBMODULE_NAME} "${@}" + + # Unset the sub-module environment. + tcar_unsetModuleEnvironment "${SUBMODULE_NAME}" + +} diff --git a/Automation/Scripts/tcar_synchronizeRepoChanges.sh b/Automation/Scripts/tcar_synchronizeRepoChanges.sh index 3e7d565..b4e04d2 100755 --- a/Automation/Scripts/tcar_synchronizeRepoChanges.sh +++ b/Automation/Scripts/tcar_synchronizeRepoChanges.sh @@ -38,6 +38,6 @@ function tcar_synchronizeRepoChanges { tcar_checkFiles -e ${@} # Synchronize changes. - tcar_setFnEnvironment vcs --synchronize ${@} + tcar_setModuleEnvironment vcs --synchronize ${@} } diff --git a/Automation/Scripts/tcar_unsetModuleEnvironment.sh b/Automation/Scripts/tcar_unsetModuleEnvironment.sh index cf74e16..dd09cac 100755 --- a/Automation/Scripts/tcar_unsetModuleEnvironment.sh +++ b/Automation/Scripts/tcar_unsetModuleEnvironment.sh @@ -30,10 +30,10 @@ function tcar_unsetModuleEnvironment { # Define export id used to retrieve function files. This is the # same export id used to export functions without the directory # part. - local FUNCTION_EXPORTID=$(basename "${1}") + local MODULE_NAME=$(basename "${1}") # Verify suffix value used to retrieve function files. - if [[ -z ${FUNCTION_EXPORTID} ]];then + if [[ -z ${MODULE_NAME} ]];then tcar_printMessage "`gettext "The export id was not provided."`" --as-error-line fi @@ -42,7 +42,7 @@ function tcar_unsetModuleEnvironment { # `tcar_setModuleEnvironmentScripts'. Be sure to limit the list to function # names that start with the suffix specified only. local FUNCTION_DEF='' - local FUNCTION_DEFS=$(declare -F | gawk '{ print $3 }' | egrep "^${FUNCTION_EXPORTID}") + local FUNCTION_DEFS=$(declare -F | gawk '{ print $3 }' | egrep "^${MODULE_NAME}") # Unset function names from current execution environment. for FUNCTION_DEF in ${FUNCTION_DEFS};do