Blame Automation/Modules/Cli/cli.sh

Alain Reguera Delgado 8f60cb
#!/bin/bash
Alain Reguera Delgado 615395
######################################################################
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 615395
#   cli.sh -- This function initiates the centos-art.sh script
Alain Reguera Delgado 615395
#   command-line interface. This is the first script the centos-art.sh
Alain Reguera Delgado 615395
#   runs, onces it has been executed in a terminal.
Alain Reguera Delgado 615395
#
Alain Reguera Delgado 615395
#   Written by: 
Alain Reguera Delgado 615395
#   * Alain Reguera Delgado <al@centos.org.cu>, 2009-2013
Alain Reguera Delgado 615395
#     Key fingerprint = D67D 0F82 4CBD 90BC 6421  DF28 7CCE 757C 17CA 3951
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# Copyright (C) 2009-2013 The CentOS Project
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# This program is free software; you can redistribute it and/or modify
Alain Reguera Delgado 8f60cb
# it under the terms of the GNU General Public License as published by
Alain Reguera Delgado 8f60cb
# the Free Software Foundation; either version 2 of the License, or (at
Alain Reguera Delgado 8f60cb
# your option) any later version.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# This program is distributed in the hope that it will be useful, but
Alain Reguera Delgado 8f60cb
# WITHOUT ANY WARRANTY; without even the implied warranty of
Alain Reguera Delgado 8f60cb
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Alain Reguera Delgado 8f60cb
# General Public License for more details.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# You should have received a copy of the GNU General Public License
Alain Reguera Delgado 8f60cb
# along with this program; if not, write to the Free Software
Alain Reguera Delgado 8f60cb
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 615395
######################################################################
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
function cli {
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 69f807
    # Initialize command-line interface common functions.
Alain Reguera Delgado ddf7d2
    for MODULE_SCRIPT in $(ls ${TCAR_SCRIPT_INIT_DIR}/Scripts/*.sh);do
Alain Reguera Delgado ddf7d2
        if [[ -x ${MODULE_SCRIPT} ]];then
Alain Reguera Delgado ddf7d2
            . ${MODULE_SCRIPT}
Alain Reguera Delgado ddf7d2
            export -f $(grep '^function ' ${MODULE_SCRIPT} | cut -d' ' -f2)
Alain Reguera Delgado 8f60cb
        else
Alain Reguera Delgado ddf7d2
            echo "${MODULE_SCRIPT} `gettext "has not execution rights."`"
Alain Reguera Delgado 8f60cb
        fi
Alain Reguera Delgado 8f60cb
    done
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Trap signals in order to terminate the script execution
Alain Reguera Delgado 8f60cb
    # correctly (e.g., removing all temporal files before leaving).
Alain Reguera Delgado 8f60cb
    # Trapping the exit signal seems to be enough by now, since it is
Alain Reguera Delgado 8f60cb
    # always present as part of the script execution flow. Each time
Alain Reguera Delgado 8f60cb
    # the centos-art.sh script is executed it will inevitably end with
Alain Reguera Delgado 8f60cb
    # an EXIT signal at some point of its execution, even if it is
Alain Reguera Delgado 8f60cb
    # interrupted in the middle of its execution (e.g., through
Alain Reguera Delgado 8f60cb
    # `Ctrl+C').
Alain Reguera Delgado 8f60cb
    trap cli_terminateScriptExecution 0
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 69f807
    # Initialize command-line interface default configuration values.
Alain Reguera Delgado 69f807
    if [[ -f ${TCAR_SCRIPT_INIT_DIR}/${TCAR_SCRIPT_INIT}.conf ]];then
Alain Reguera Delgado 69f807
        . ${TCAR_SCRIPT_INIT_DIR}/${TCAR_SCRIPT_INIT}.conf
Alain Reguera Delgado ddf7d2
    fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 69f807
    # Verify first argument passed to centos-art.sh script.
Alain Reguera Delgado 69f807
    if [[ ${1} == "${TCAR_SCRIPT_INIT}" ]];then
Alain Reguera Delgado ddf7d2
        cli_getOptions "${@}"
Alain Reguera Delgado 69f807
    else
Alain Reguera Delgado 69f807
        cli_initModule "${@}"
Alain Reguera Delgado ddf7d2
    fi
Alain Reguera Delgado ddf7d2
Alain Reguera Delgado 8f60cb
}