diff --git a/Automation/Modules/centos-art.sh-cli/Scripts/cli_checkFiles.sh b/Automation/Modules/centos-art.sh-cli/Scripts/cli_checkFiles.sh index 9203244..0e4d50b 100755 --- a/Automation/Modules/centos-art.sh-cli/Scripts/cli_checkFiles.sh +++ b/Automation/Modules/centos-art.sh-cli/Scripts/cli_checkFiles.sh @@ -51,13 +51,13 @@ function cli_checkFiles { # variable to this function scope. Doing this is very important to # avoid any clash with higher execution environments. This # variable is shared for different function environments. - local TCAR_MODULE_ARGUMENTS='' + local TCAR_ARGUMENTS='' # Redefine arguments using current positional parameters. cli_setArguments "${@}" # Redefine positional parameters using arguments variable. - eval set -- "${TCAR_MODULE_ARGUMENTS}" + eval set -- "${TCAR_ARGUMENTS}" # Look for options passed through positional parameters. while true; do diff --git a/Automation/Modules/centos-art.sh-cli/Scripts/cli_expandTMarkers.sh b/Automation/Modules/centos-art.sh-cli/Scripts/cli_expandTMarkers.sh index fa9b00b..ebeaff7 100755 --- a/Automation/Modules/centos-art.sh-cli/Scripts/cli_expandTMarkers.sh +++ b/Automation/Modules/centos-art.sh-cli/Scripts/cli_expandTMarkers.sh @@ -54,13 +54,6 @@ function cli_expandTMarkers { SRC[((++${#SRC[*]}))]='=COPYRIGHT_HOLDER_PREDICATE=' DST[((++${#DST[*]}))]="$(cli_printCopyrightInfo --holder-predicate)" - # Define name of branding files. This files are mainly used under - # Identity/(Images|Models)/Brands/ directory structure. These - # file names may vary from one project to another so we use this - # variable to control the name of such files. - SRC[((++${#SRC[*]}))]='=BRAND=' - DST[((++${#DST[*]}))]="${TCAR_BRAND}" - # Define license translation markers. SRC[((++${#SRC[*]}))]='=LICENSE=' DST[((++${#DST[*]}))]="$(cli_printCopyrightInfo --license)" @@ -117,23 +110,23 @@ function cli_expandTMarkers { # Define locale translation markers. SRC[((++${#SRC[*]}))]='=LOCALE=' - DST[((++${#DST[*]}))]="${CLI_LANG_LC}" + DST[((++${#DST[*]}))]="${TCAR_SCRIPT_LANG_LC}" SRC[((++${#SRC[*]}))]='=LOCALE_LL=' - DST[((++${#DST[*]}))]="${CLI_LANG_LL}" + DST[((++${#DST[*]}))]="${TCAR_SCRIPT_LANG_LL}" SRC[((++${#SRC[*]}))]='=LOCALE_CC=' - DST[((++${#DST[*]}))]="${CLI_LANG_CC}" + DST[((++${#DST[*]}))]="${TCAR_SCRIPT_LANG_CC}" # Define domain translation markers for domains. SRC[((++${#SRC[*]}))]='=DOMAIN_LL=' - if [[ ! ${CLI_LANG_LL} =~ '^en' ]];then - DST[((++${#DST[*]}))]="${CLI_LANG_LL}" + if [[ ! ${TCAR_SCRIPT_LANG_LL} =~ '^en' ]];then + DST[((++${#DST[*]}))]="${TCAR_SCRIPT_LANG_LL}" else DST[((++${#DST[*]}))]="" fi # Define repository translation markers. - SRC[((++${#SRC[*]}))]='=(REPO_TLDIR|REPO_HOME|TCAR_USER_WRKDIR)=' - DST[((++${#DST[*]}))]="${TCAR_USER_WRKDIR}" + SRC[((++${#SRC[*]}))]='=(REPO_TLDIR|REPO_HOME|TCAR_BASEDIR)=' + DST[((++${#DST[*]}))]="${TCAR_BASEDIR}" # Do replacement of nested translation markers. while [[ ${COUNTDST} -lt ${#DST[@]} ]];do diff --git a/Automation/Modules/centos-art.sh-cli/Scripts/cli_exportFunctions.sh b/Automation/Modules/centos-art.sh-cli/Scripts/cli_exportFunctions.sh index c92a554..2b15a5a 100755 --- a/Automation/Modules/centos-art.sh-cli/Scripts/cli_exportFunctions.sh +++ b/Automation/Modules/centos-art.sh-cli/Scripts/cli_exportFunctions.sh @@ -46,8 +46,7 @@ function cli_exportFunctions { local FUNCTION_PATTERN="^function[[:space:]]+${MODULE_INIT_FILENAME}(_[[:alnum:]]+)?[[:space:]]+{[[:space:]]*$" # Define the list of files. - local MODULE_SCRIPT_FILE='' - local MODULE_SCRIPT_FILES="${MODULE_INIT_FILE} + local MODULE_SCRIPTS="${MODULE_INIT_FILE} $(cli_getFilesList ${MODULE_SCRIPTS_DIR} \ --pattern="${MODULE_DIR}/.+\.sh$" --maxdepth='1' \ --mindepth='1' --type='f')" @@ -56,30 +55,30 @@ function cli_exportFunctions { # location specified stop the script execution. Otherwise the # script will surely try to execute a function that haven't been # exported yet and report an error about it. - if [[ -z ${MODULE_SCRIPT_FILES} ]];then + if [[ -z ${MODULE_SCRIPTS} ]];then cli_printMessage "${FUNCNAME}: `gettext "No function file was found."`" --as-error-line fi # Process the list of files. - for MODULE_SCRIPT_FILE in ${MODULE_SCRIPT_FILES};do + for MODULE_SCRIPT in ${MODULE_SCRIPTS};do # Verify the execution rights for function file. - cli_checkFiles -x ${MODULE_SCRIPT_FILE} + cli_checkFiles -x ${MODULE_SCRIPT} # Verify that function files have not been already exported. # If they have been already exported don't export them again. # Instead, continue with the next function file in the list. - declare -F | gawk '{ print $3 }' | egrep "^${MODULE_SCRIPT_FILE}$" > /dev/null + declare -F | gawk '{ print $3 }' | egrep "^${MODULE_SCRIPT}$" > /dev/null if [[ $? -eq 0 ]];then continue fi # Initialize the function file. - . ${MODULE_SCRIPT_FILE} + . ${MODULE_SCRIPT} # Export the function names inside the file to current shell # script environment. - export -f $(egrep "${FUNCTION_PATTERN}" ${MODULE_SCRIPT_FILE} | gawk '{ print $2 }') + export -f $(egrep "${FUNCTION_PATTERN}" ${MODULE_SCRIPT} | gawk '{ print $2 }') done diff --git a/Automation/Modules/centos-art.sh-cli/Scripts/cli_getFilesList.sh b/Automation/Modules/centos-art.sh-cli/Scripts/cli_getFilesList.sh index 01f3591..8c4e2e2 100755 --- a/Automation/Modules/centos-art.sh-cli/Scripts/cli_getFilesList.sh +++ b/Automation/Modules/centos-art.sh-cli/Scripts/cli_getFilesList.sh @@ -45,15 +45,15 @@ function cli_getFilesList { # Initialize arguments with an empty value and set it as local # variable to this function scope. Doing this is very important to # avoid any clash with higher execution environments. - local TCAR_MODULE_ARGUMENTS='' + local TCAR_ARGUMENTS='' # Process all arguments currently available in this function # environment. If either ARGSS or ARGSL local variables have been # defined, argument processing goes through getopt for validation. cli_setArguments "${@}" - # Redefine positional parameters using TCAR_MODULE_ARGUMENTS variable. - eval set -- "${TCAR_MODULE_ARGUMENTS}" + # Redefine positional parameters using TCAR_ARGUMENTS variable. + eval set -- "${TCAR_ARGUMENTS}" while true;do case "${1}" in diff --git a/Automation/Modules/centos-art.sh-cli/Scripts/cli_getLocalizationDir.sh b/Automation/Modules/centos-art.sh-cli/Scripts/cli_getLocalizationDir.sh index 91ec8eb..4377c5b 100755 --- a/Automation/Modules/centos-art.sh-cli/Scripts/cli_getLocalizationDir.sh +++ b/Automation/Modules/centos-art.sh-cli/Scripts/cli_getLocalizationDir.sh @@ -51,7 +51,7 @@ function cli_getLocalizationDir { * ) LOCATION=$(echo "${LOCATION}" \ - | sed -r -e "s!(Identity|Scripts|Documentation)!Locales/\1!")/${CLI_LANG_LC} + | sed -r -e "s!(Identity|Scripts|Documentation)!Locales/\1!")/${TCAR_SCRIPT_LANG_LC} ;; esac diff --git a/Automation/Modules/centos-art.sh-cli/Scripts/cli_getOptions.sh b/Automation/Modules/centos-art.sh-cli/Scripts/cli_getOptions.sh new file mode 100755 index 0000000..b4d3f72 --- /dev/null +++ b/Automation/Modules/centos-art.sh-cli/Scripts/cli_getOptions.sh @@ -0,0 +1,92 @@ +#!/bin/bash +###################################################################### +# +# cli_getOptions.sh -- This function parses common options passed to +# to `centos-art.sh' script. Because option parsing is different for +# each function environment inside centos-art.sh script, we cannot +# use getopt here. That would enter in conflict with options from +# deeper function environments making impossible to parse both +# common and specific options through getopt in a modular way (e.g., +# without duplicating common option definition inside each different +# module the centos-art.sh script is made of). +# +# To solve this issue centos-art.sh script restricts the order in +# which common options are passed through the command line. This +# way, common options must be passed first and specific options +# later. Common options are defined in this file and specific +# options are defined in module-specific files. +# +# This introduces the nature of common options: common options do +# not modify the centos-art.sh script behaviour in any way. Common +# options exist to show information about centos-art.sh script and +# its modules only (e.g., --help and --version) and once done, exit +# successfully without processing any other option or argument +# passed in the command-line. +# +# Written by: +# * Alain Reguera Delgado , 2009-2013 +# Key fingerprint = D67D 0F82 4CBD 90BC 6421 DF28 7CCE 757C 17CA 3951 +# +# 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 cli_getOptions { + + # Define valid short options. + local ARGSS="h,v" + + # Define valid long options. + local ARGSL="help,version" + + # Initialize arguments local to this function environment. + local TCAR_ARGUMENTS='' + + # Redefine arguments using getopt(1) command parser. + cli_setArguments "${@}" + + # Reset positional parameters on this function, using output + # produced from (getopt) arguments parser. + eval set -- "${TCAR_ARGUMENTS}" + + # Look for options passed through command-line. + while true; do + case ${1} in + + -h | --help ) + cli_printHelp + ;; + + -v | --version ) + cli_printVersion + ;; + + * ) + # At this point none of the valid options were + # provided so, finish the script execution. This is + # not absolutely needed because getopt will complain + # about non-valid options and probably never execution + # reaches this point. Consider this a backup + # verification. + exit 0 + ;; + + esac + + done + +} diff --git a/Automation/Modules/centos-art.sh-cli/Scripts/cli_getPathComponent.sh b/Automation/Modules/centos-art.sh-cli/Scripts/cli_getPathComponent.sh index 9afb59c..a563f5c 100755 --- a/Automation/Modules/centos-art.sh-cli/Scripts/cli_getPathComponent.sh +++ b/Automation/Modules/centos-art.sh-cli/Scripts/cli_getPathComponent.sh @@ -51,15 +51,15 @@ function cli_getPathComponent { # Initialize arguments with an empty value and set it as local # variable to this function scope. Doing this is very important to # avoid any clash with higher execution environments. - local TCAR_MODULE_ARGUMENTS='' + local TCAR_ARGUMENTS='' # Process all arguments currently available in this function # environment. If either ARGSS or ARGSL local variables have been # defined, argument processing goes through getopt for validation. cli_setArguments "${@}" - # Redefine positional parameters using TCAR_MODULE_ARGUMENTS variable. - eval set -- "${TCAR_MODULE_ARGUMENTS}" + # Redefine positional parameters using TCAR_ARGUMENTS variable. + eval set -- "${TCAR_ARGUMENTS}" # Define location we want to apply verifications to. local LOCATION=$(echo ${@} | sed -r 's!^.*--[[:space:]](.+)$!\1!') diff --git a/Automation/Modules/centos-art.sh-cli/Scripts/cli_getTemporalFile.sh b/Automation/Modules/centos-art.sh-cli/Scripts/cli_getTemporalFile.sh index 502eb91..84f4e85 100755 --- a/Automation/Modules/centos-art.sh-cli/Scripts/cli_getTemporalFile.sh +++ b/Automation/Modules/centos-art.sh-cli/Scripts/cli_getTemporalFile.sh @@ -34,18 +34,16 @@ function cli_getTemporalFile { # instances are created previous to be parsed by inkscape in order # to be exported as png. In such cases .svg file extension is # required in order to avoid complains from inkscape. - local NAME="$(cli_getRepoName ${1} -f)" + local FILENAME="$(cli_getRepoName ${1} -f)" # Check default base name for temporal file, it can't be an empty # value. - if [[ "${NAME}" == '' ]];then + if [[ -z "${FILENAME}" ]];then cli_printMessage "`gettext "The first argument cannot be empty."`" --as-error-line fi - # Define absolute path for temporal file. - local TEMPFILE="${TCAR_CLI_TEMPDIR}/${NAME}" - - # Output absolute path to final temporal file. - echo ${TEMPFILE} + # Define absolute path for temporal file and send it out to + # standard output. + echo "${TCAR_SCRIPT_TEMPDIR}/${FILENAME}" } diff --git a/Automation/Modules/centos-art.sh-cli/Scripts/cli_printHelp.sh b/Automation/Modules/centos-art.sh-cli/Scripts/cli_printHelp.sh new file mode 100755 index 0000000..86f1c0a --- /dev/null +++ b/Automation/Modules/centos-art.sh-cli/Scripts/cli_printHelp.sh @@ -0,0 +1,34 @@ +#!/bin/bash +###################################################################### +# +# cli_printHelp.sh -- This function standardizes the way +# centos-art.sh script prints help about itself. +# +# Written by: +# * Alain Reguera Delgado , 2009-2013 +# Key fingerprint = D67D 0F82 4CBD 90BC 6421 DF28 7CCE 757C 17CA 3951 +# +# 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 cli_printHelp { + + ${TCAR_MANUAL_READER} "${MODULE_NAME}" + exit 0 + +} diff --git a/Automation/Modules/centos-art.sh-cli/Scripts/cli_printMailingList.sh b/Automation/Modules/centos-art.sh-cli/Scripts/cli_printMailingList.sh index b1b3166..94086da 100755 --- a/Automation/Modules/centos-art.sh-cli/Scripts/cli_printMailingList.sh +++ b/Automation/Modules/centos-art.sh-cli/Scripts/cli_printMailingList.sh @@ -40,15 +40,15 @@ function cli_printMailingList { # Initialize arguments with an empty value and set it as local # variable to this function scope. Doing this is very important to # avoid any clash with higher execution environments. - local TCAR_MODULE_ARGUMENTS='' + local TCAR_ARGUMENTS='' # Process all arguments currently available in this function # environment. If either ARGSS or ARGSL local variables have been # defined, argument processing goes through getopt for validation. cli_setArguments "${@}" - # Redefine positional parameters using TCAR_MODULE_ARGUMENTS variable. - eval set -- "${TCAR_MODULE_ARGUMENTS}" + # Redefine positional parameters using TCAR_ARGUMENTS variable. + eval set -- "${TCAR_ARGUMENTS}" # Look for options passed through command-line. while true; do diff --git a/Automation/Modules/centos-art.sh-cli/Scripts/cli_printMessage.sh b/Automation/Modules/centos-art.sh-cli/Scripts/cli_printMessage.sh index 3266934..4d156c5 100755 --- a/Automation/Modules/centos-art.sh-cli/Scripts/cli_printMessage.sh +++ b/Automation/Modules/centos-art.sh-cli/Scripts/cli_printMessage.sh @@ -72,8 +72,8 @@ function cli_printMessage { --as-error-line ) # Build the error message. - cli_printMessage "${TCAR_CLI_COMMAND} ($(cli_printCaller 2)): ${MESSAGE}" --as-stderr-line - cli_printMessage "$(cli_printCaller "2" "--name")" --as-toknowmore-line + cli_printMessage "${TCAR_SCRIPT_COMMAND} ($(cli_printCaller 1)): ${MESSAGE}" --as-stderr-line + cli_printMessage "${MODULE_NAME}" --as-toknowmore-line # Finish script execution with exit status 1 (SIGHUP) to # imply the script finished because an error. We are @@ -85,7 +85,7 @@ function cli_printMessage { --as-suggestion-line ) # Build the error message. - cli_printMessage "${TACAR_CLI_COMMAND} ($(cli_printCaller 2)):" --as-stderr-line + cli_printMessage "${TCAR_SCRIPT_COMMAND} ($(cli_printCaller 1)):" --as-stderr-line cli_printMessage "`gettext "The path provided cannot be processed the way you entered it."`" --as-stderr-line cli_printMessage "`gettext "Instead, try the following equivalence:"` ${MESSAGE}" --as-stderr-line cli_printMessage "${MODULE_NAME}" --as-toknowmore-line @@ -98,7 +98,7 @@ function cli_printMessage { ;; --as-toknowmore-line ) - cli_printMessage "`gettext "To know more, run"` ${TCAR_CLI_COMMAND} help --id=${MESSAGE} " --as-stderr-line + cli_printMessage "`gettext "To know more, run"` ${TCAR_SCRIPT_COMMAND} ${MESSAGE} --help" --as-stderr-line ;; --as-yesornorequest-line ) diff --git a/Automation/Modules/centos-art.sh-cli/Scripts/cli_printUrl.sh b/Automation/Modules/centos-art.sh-cli/Scripts/cli_printUrl.sh index 58f2c65..40c8d78 100755 --- a/Automation/Modules/centos-art.sh-cli/Scripts/cli_printUrl.sh +++ b/Automation/Modules/centos-art.sh-cli/Scripts/cli_printUrl.sh @@ -41,15 +41,15 @@ function cli_printUrl { # Initialize arguments with an empty value and set it as local # variable to this function scope. Doing this is very important to # avoid any clash with higher execution environments. - local TCAR_MODULE_ARGUMENTS='' + local TCAR_ARGUMENTS='' # Process all arguments currently available in this function # environment. If either ARGSS or ARGSL local variables have been # defined, argument processing goes through getopt for validation. cli_setArguments "${@}" - # Redefine positional parameters using TCAR_MODULE_ARGUMENTS variable. - eval set -- "${TCAR_MODULE_ARGUMENTS}" + # Redefine positional parameters using TCAR_ARGUMENTS variable. + eval set -- "${TCAR_ARGUMENTS}" # Look for options passed through command-line. while true; do @@ -127,7 +127,7 @@ function cli_printUrl { --with-locale ) if [[ ! ${LANG} =~ '^en' ]];then - URL="${URL}${CLI_LANG_LL}/" + URL="${URL}${TCAR_SCRIPT_LANG_LL}/" fi shift 1 ;; diff --git a/Automation/Modules/centos-art.sh-cli/Scripts/cli_printVersion.sh b/Automation/Modules/centos-art.sh-cli/Scripts/cli_printVersion.sh new file mode 100755 index 0000000..0bf3592 --- /dev/null +++ b/Automation/Modules/centos-art.sh-cli/Scripts/cli_printVersion.sh @@ -0,0 +1,34 @@ +#!/bin/bash +###################################################################### +# +# cli_printVersion.sh -- This function standardizes the way +# centos-art.sh script prints version about itself. +# +# Written by: +# * Alain Reguera Delgado , 2009-2013 +# Key fingerprint = D67D 0F82 4CBD 90BC 6421 DF28 7CCE 757C 17CA 3951 +# +# 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 cli_printVersion { + + cli_printMessage "`eval_gettext "Running module $MODULE_NAME (v$MODULE_VERSION) through $TCAR_SCRIPT_NAME (v$TCAR_SCRIPT_VERSION)."`" --as-stdout-line + exit 0 + +} diff --git a/Automation/Modules/centos-art.sh-cli/Scripts/cli_runFnEnvironment.sh b/Automation/Modules/centos-art.sh-cli/Scripts/cli_runFnEnvironment.sh index a54f554..3fe5fe2 100755 --- a/Automation/Modules/centos-art.sh-cli/Scripts/cli_runFnEnvironment.sh +++ b/Automation/Modules/centos-art.sh-cli/Scripts/cli_runFnEnvironment.sh @@ -31,7 +31,7 @@ function cli_runFnEnvironment { # Execute specific function environment. - ${CLI_NAME} ${@} + ${MODULE_NAME} ${@} # Retrieve exit status. local STATUS=$? diff --git a/Automation/Modules/centos-art.sh-cli/Scripts/cli_setArguments.sh b/Automation/Modules/centos-art.sh-cli/Scripts/cli_setArguments.sh index 9f862fb..474da4b 100755 --- a/Automation/Modules/centos-art.sh-cli/Scripts/cli_setArguments.sh +++ b/Automation/Modules/centos-art.sh-cli/Scripts/cli_setArguments.sh @@ -12,7 +12,7 @@ # ARGSL # Stores getopt long arguments definition. # -# TCAR_MODULE_ARGUMENTS +# TCAR_ARGUMENTS # Stores arguments passed to functions or command-line # interface depending the context it is defined. # @@ -55,7 +55,7 @@ function cli_setArguments { # Fill up arguments global variable with current positional # parameter information. To avoid interpretation problems, use - # single quotes to enclose each argument (TCAR_MODULE_ARGUMENTS) from + # single quotes to enclose each argument (TCAR_ARGUMENTS) from # command-line individually. for ARGUMENT in "${@}"; do @@ -66,26 +66,36 @@ function cli_setArguments { # Concatenate arguments and enclose them to let getopt to # process them when they have spaces inside. - TCAR_MODULE_ARGUMENTS="${TCAR_MODULE_ARGUMENTS} '${ARGUMENT}'" + TCAR_ARGUMENTS="${TCAR_ARGUMENTS} '${ARGUMENT}'" done # Verify non-option arguments passed to command-line. If there - # isn't any or dot is provided, redefine the TCAR_MODULE_ARGUMENTS variable to - # use the current location the centos-art.sh script was called - # from. - if [[ -z "${TCAR_MODULE_ARGUMENTS}" ]];then - TCAR_MODULE_ARGUMENTS=${PWD} + # isn't any or dot is provided, redefine the TCAR_ARGUMENTS + # variable to use the current location the centos-art.sh script + # was called from. + if [[ -z "${TCAR_ARGUMENTS}" ]];then + TCAR_ARGUMENTS=${PWD} fi - # Redefine positional parameters using TCAR_MODULE_ARGUMENTS variable. + # Verify presence of either short or long options in the + # environment. If they are present apply option validation through + # getopt. if [[ ! -z ${ARGSS} ]] || [[ ! -z ${ARGSL} ]];then - eval set -- "${TCAR_MODULE_ARGUMENTS}" - TCAR_MODULE_ARGUMENTS=$(getopt -o "${ARGSS}" -l "${ARGSL}" \ - -n "${TCAR_CLI_COMMAND} ($(cli_printCaller 2))" -- "${@}") + + # Redefine positional parameters using TCAR_ARGUMENTS variable. + eval set -- "${TCAR_ARGUMENTS}" + + # Process positional parameters using getopt's option validation. + TCAR_ARGUMENTS=$(getopt -o "${ARGSS}" -l "${ARGSL}" \ + -n "${TCAR_SCRIPT_COMMAND} (${MODULE_NAME})" -- "${@}") + + # Verify getopt's exit status and finish the script execution + # with an error message, if it failed. if [[ $? -ne 0 ]];then cli_printMessage "`gettext "The argument verification failed."`" --as-error-line fi + fi } diff --git a/Automation/Modules/centos-art.sh-cli/Scripts/cli_terminateScriptExecution.sh b/Automation/Modules/centos-art.sh-cli/Scripts/cli_terminateScriptExecution.sh index 09b1d20..2e3daa5 100755 --- a/Automation/Modules/centos-art.sh-cli/Scripts/cli_terminateScriptExecution.sh +++ b/Automation/Modules/centos-art.sh-cli/Scripts/cli_terminateScriptExecution.sh @@ -32,7 +32,7 @@ function cli_terminateScriptExecution { # Remove temporal directory. - rm -r ${TCAR_CLI_TEMPDIR} + rm -r ${TCAR_SCRIPT_TEMPDIR} # NOTE: Don't specify an exit status here. As convenction we do # this when error messages are triggerd. See `--as-error-line' diff --git a/Automation/Modules/centos-art.sh-cli/cli.conf b/Automation/Modules/centos-art.sh-cli/cli.conf index c28a599..6359c68 100644 --- a/Automation/Modules/centos-art.sh-cli/cli.conf +++ b/Automation/Modules/centos-art.sh-cli/cli.conf @@ -1,7 +1,7 @@ #!/bin/bash ###################################################################### # -# cli.conf -- This file initiates configuration values to +# cli.conf -- This file redefines configuration values to # centos-art.sh-cli module. # # Written by: @@ -26,7 +26,20 @@ # ###################################################################### -# Initialize internationalization configuration values. -. gettext.sh -declare -x TEXTDOMAIN=${TCAR_CLI_NAME}-cli -declare -x TEXTDOMAINDIR=${TCAR_CLI_INIT_DIR}/Locales/Scripts +# ---------------------------------------------------------------------- +# Command-line interface (read-only) configuration variables. +# ---------------------------------------------------------------------- +declare -xr MODULE_VERSION='0.1' + +# ---------------------------------------------------------------------- +# Internationalization configuration variables. +# ---------------------------------------------------------------------- +declare -x TEXTDOMAIN=${MODULE_NAME} +declare -x TEXTDOMAINDIR=${MODULE_DIR}/Locales + +# ---------------------------------------------------------------------- +# Redefine manuals configuration values. +# ---------------------------------------------------------------------- +declare -x TCAR_MANUAL_FILE=${MODULE_DIR}/${MODULE_NAME}.asciidoc +declare -x TCAR_MANUAL_SEARCHPATH=${MODULE_DIR}/Manuals +declare -x TCAR_MANUAL_READER="/usr/bin/man -M ${TCAR_MANUAL_SEARCHPATH}" diff --git a/Automation/Modules/centos-art.sh-cli/cli.sh b/Automation/Modules/centos-art.sh-cli/cli.sh index e2730d1..207b174 100755 --- a/Automation/Modules/centos-art.sh-cli/cli.sh +++ b/Automation/Modules/centos-art.sh-cli/cli.sh @@ -30,17 +30,17 @@ function cli { # Initialize command-line interface default configuration values. - if [[ -f ${TCAR_CLI_INIT_DIR}/cli.conf ]];then - . ${TCAR_CLI_INIT_DIR}/cli.conf + if [[ -f ${TCAR_SCRIPT_INIT_DIR}/cli.conf ]];then + . ${TCAR_SCRIPT_INIT_DIR}/cli.conf fi # Initialize list of common functionalities to load. - for CLI_FUNCTION in $(ls ${TCAR_CLI_INIT_DIR}/Scripts/*.sh);do - if [[ -x ${CLI_FUNCTION} ]];then - . ${CLI_FUNCTION} - export -f $(grep '^function ' ${CLI_FUNCTION} | cut -d' ' -f2) + for MODULE_SCRIPT in $(ls ${TCAR_SCRIPT_INIT_DIR}/Scripts/*.sh);do + if [[ -x ${MODULE_SCRIPT} ]];then + . ${MODULE_SCRIPT} + export -f $(grep '^function ' ${MODULE_SCRIPT} | cut -d' ' -f2) else - echo "${CLI_FUNCTION} `gettext "has not execution rights."`" + echo "${MODULE_SCRIPT} `gettext "has not execution rights."`" fi done @@ -54,37 +54,30 @@ function cli { # `Ctrl+C'). trap cli_terminateScriptExecution 0 - # Redefine arguments using current positional parameters. - cli_setArguments "${@}" + # 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='' - # Redefine positional parameters using arguments variable. - eval set -- "${TCAR_MODULE_ARGUMENTS}" - - # Check the number of arguments passed in the command-line - # interface. The first argument must be the name of the module - # you want to execute. So at least one argument must be provided + # Define module's name (MODULE_NAME) using the first argument # in the command-line. - if [[ $# -lt 1 ]];then - cli_printHelp ${TCAR_CLI_NAME} - else - # Check module's name. The module's name is critical for - # centos-art.sh script to do something coherent. If it is not - # provided or provided incorrectly, finish the script - # execution with help information. - if [[ ! "${1}" =~ '^[[:alpha:]]+$' ]];then - cli_printHelp ${TCAR_CLI_NAME}-cli - fi - fi + local MODULE_NAME=$(cli_getRepoName "${1}" "-f" | cut -d '-' -f1) - # Define function name (MODULE_INIT_NAME) using the first argument - # in the command-line. - local MODULE_INIT_NAME=$(cli_getRepoName ${1} -f | cut -d '-' -f1) + # Define regular expression to match available modules. + local MODULE_NAME_LIST=$(ls ${TCAR_SCRIPT_BASEDIR}/Modules/ \ + | sed -r 's/.+-([[:alnum:]]+)$/\1/' \ + | tr '\n' '|' | sed -r 's/\|$//') + + # Check module's name possible values. + if [[ ! ${MODULE_NAME} =~ "^(${MODULE_NAME_LIST})$" ]];then + cli_printMessage "`gettext "The module provided isn't valid."`" --as-error-line + fi # Define function directory. - local MODULE_INIT_DIR=${TCAR_CLI_BASEDIR}/Modules/${TCAR_CLI_NAME}-${MODULE_INIT_NAME} + local MODULE_DIR=${TCAR_SCRIPT_BASEDIR}/Modules/${TCAR_SCRIPT_NAME}-${MODULE_NAME} # Define function file name. - local MODULE_INIT_FILE=${MODULE_INIT_DIR}/${MODULE_INIT_NAME}.sh + local MODULE_INIT_FILE=${MODULE_DIR}/${MODULE_NAME}.sh # Check function script execution rights. cli_checkFiles -x ${MODULE_INIT_FILE} @@ -94,6 +87,14 @@ function cli { # start counting from second argument (inclusive) on. shift 1 + # When the word cli is provided as module to centos-art.sh script, + # the cli module reduces its mission to just printing help and + # version information about itself. After that, it must finish the + # script execution successfully. + if [[ ${MODULE_NAME} == "${TCAR_SCRIPT_INIT}" ]];then + cli_getOptions "${@}" + fi + # Define default text editors used by centos-art.sh script. if [[ ! "${TCAR_USER_EDITOR}" =~ '/usr/bin/(vim|emacs|nano)' ]];then TCAR_USER_EDITOR='/usr/bin/vim' @@ -107,6 +108,6 @@ function cli { cli_exportFunctions "${MODULE_INIT_FILE}" # Execute function. - ${MODULE_INIT_NAME} "${@}" + ${MODULE_NAME} "${@}" }