|
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 |
615395 |
local CLI_FUNCTION_NAME=''
|
|
Alain Reguera Delgado |
615395 |
local CLI_FUNCTION_DIR=''
|
|
Alain Reguera Delgado |
615395 |
local CLI_FUNCTION_FILE=''
|
|
Alain Reguera Delgado |
615395 |
local CLI_FUNCTION=''
|
|
Alain Reguera Delgado |
615395 |
local CLI_FUNCTIONS=$(ls ${TCAR_CLI_INIT_DIR}/${TCAR_CLI_INIT_FUNCTION}_*.sh)
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
# Initialize list of common functionalities to load.
|
|
Alain Reguera Delgado |
615395 |
for CLI_FUNCTION in ${CLI_FUNCTIONS};do
|
|
Alain Reguera Delgado |
615395 |
if [[ -x ${CLI_FUNCTION} ]];then
|
|
Alain Reguera Delgado |
615395 |
. ${CLI_FUNCTION}
|
|
Alain Reguera Delgado |
615395 |
export -f $(grep '^function ' ${CLI_FUNCTION} | cut -d' ' -f2)
|
|
Alain Reguera Delgado |
8f60cb |
else
|
|
Alain Reguera Delgado |
615395 |
echo "${CLI_FUNCTION} `gettext "has not execution rights."`"
|
|
Alain Reguera Delgado |
8f60cb |
exit
|
|
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 |
615395 |
# Initialize variable holding arguments passed to centos-art.sh
|
|
Alain Reguera Delgado |
615395 |
# command-line interface.
|
|
Alain Reguera Delgado |
615395 |
local CLI_FUNCTION_ARGUMENTS=''
|
|
Alain Reguera Delgado |
615395 |
|
|
Alain Reguera Delgado |
615395 |
# Redefine arguments using current positional parameters.
|
|
Alain Reguera Delgado |
615395 |
cli_setArguments "${@}"
|
|
Alain Reguera Delgado |
615395 |
|
|
Alain Reguera Delgado |
615395 |
# Redefine positional parameters using arguments variable.
|
|
Alain Reguera Delgado |
615395 |
eval set -- "${CLI_FUNCTION_ARGUMENTS}"
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
# Check function name. The function name is critical for
|
|
Alain Reguera Delgado |
8f60cb |
# centos-art.sh script to do something coherent. If it is not
|
|
Alain Reguera Delgado |
8f60cb |
# provided, execute the help functionality and end script
|
|
Alain Reguera Delgado |
8f60cb |
# execution.
|
|
Alain Reguera Delgado |
615395 |
if [[ ! "${1}" ]] || [[ ! "${1}" =~ '^[[:alpha:]]' ]];then
|
|
Alain Reguera Delgado |
8f60cb |
cli_runFnEnvironment help --read --format="texinfo" tcar-fs:::
|
|
Alain Reguera Delgado |
8f60cb |
exit
|
|
Alain Reguera Delgado |
8f60cb |
fi
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
615395 |
# Define function name (CLI_FUNCTION_NAME) using the first argument in
|
|
Alain Reguera Delgado |
8f60cb |
# the command-line.
|
|
Alain Reguera Delgado |
615395 |
CLI_FUNCTION_NAME=$(cli_getRepoName ${1} -f | cut -d '-' -f1)
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
# Define function directory.
|
|
Alain Reguera Delgado |
615395 |
CLI_FUNCTION_DIR=$(cli_getRepoName ${CLI_FUNCTION_NAME} -d)
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
# Define function file name.
|
|
Alain Reguera Delgado |
615395 |
CLI_FUNCTION_FILE=${TCAR_CLI_MODSDIR}/${CLI_FUNCTION_DIR}/${CLI_FUNCTION_NAME}.sh
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
# Check function script execution rights.
|
|
Alain Reguera Delgado |
615395 |
cli_checkFiles -x ${CLI_FUNCTION_FILE}
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
# Remove the first argument passed to centos-art.sh command-line
|
|
Alain Reguera Delgado |
8f60cb |
# in order to build optional arguments inside functionalities. We
|
|
Alain Reguera Delgado |
8f60cb |
# start counting from second argument (inclusive) on.
|
|
Alain Reguera Delgado |
8f60cb |
shift 1
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
615395 |
# Process all arguments currently available in this function
|
|
Alain Reguera Delgado |
615395 |
# environment. If either ARGSS or ARGSL local variables have been
|
|
Alain Reguera Delgado |
615395 |
# defined, argument processing goes through getopt for validation.
|
|
Alain Reguera Delgado |
615395 |
cli_setArguments "${@}"
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
# Define default text editors used by centos-art.sh script.
|
|
Alain Reguera Delgado |
615395 |
if [[ ! "${TCAR_USER_EDITOR}" =~ '/usr/bin/(vim|emacs|nano)' ]];then
|
|
Alain Reguera Delgado |
615395 |
TCAR_USER_EDITOR='/usr/bin/vim'
|
|
Alain Reguera Delgado |
8f60cb |
fi
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
# Check text editor execution rights.
|
|
Alain Reguera Delgado |
615395 |
cli_checkFiles -x ${TCAR_USER_EDITOR}
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
# Go for function initialization. Keep the cli_exportFunctions
|
|
Alain Reguera Delgado |
8f60cb |
# function calling after all variables and arguments definitions.
|
|
Alain Reguera Delgado |
615395 |
cli_exportFunctions "${CLI_FUNCTION_DIR}/${CLI_FUNCTION_NAME}"
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
# Execute function.
|
|
Alain Reguera Delgado |
615395 |
${CLI_FUNCTION_NAME}
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
8f60cb |
}
|