|
Alain Reguera Delgado |
66223d |
#!/bin/bash
|
|
Alain Reguera Delgado |
66223d |
######################################################################
|
|
Alain Reguera Delgado |
66223d |
#
|
|
Alain Reguera Delgado |
b33753 |
# tcar - The CentOS Artwork Repository automation tool.
|
|
Alain Reguera Delgado |
b33753 |
# Copyright © 2014 The CentOS Artwork SIG
|
|
Alain Reguera Delgado |
66223d |
#
|
|
Alain Reguera Delgado |
b33753 |
# This program is free software; you can redistribute it and/or
|
|
Alain Reguera Delgado |
b33753 |
# modify it under the terms of the GNU General Public License as
|
|
Alain Reguera Delgado |
b33753 |
# published by the Free Software Foundation; either version 2 of the
|
|
Alain Reguera Delgado |
b33753 |
# License, or (at your option) any later version.
|
|
Alain Reguera Delgado |
66223d |
#
|
|
Alain Reguera Delgado |
b33753 |
# This program is distributed in the hope that it will be useful,
|
|
Alain Reguera Delgado |
b33753 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Alain Reguera Delgado |
b33753 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Alain Reguera Delgado |
b33753 |
# General Public License for more details.
|
|
Alain Reguera Delgado |
66223d |
#
|
|
Alain Reguera Delgado |
b33753 |
# You should have received a copy of the GNU General Public License
|
|
Alain Reguera Delgado |
b33753 |
# along with this program; if not, write to the Free Software
|
|
Alain Reguera Delgado |
b33753 |
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
Alain Reguera Delgado |
66223d |
#
|
|
Alain Reguera Delgado |
b33753 |
# Alain Reguera Delgado <al@centos.org.cu>
|
|
Alain Reguera Delgado |
b33753 |
# 39 Street No. 4426 Cienfuegos, Cuba.
|
|
Alain Reguera Delgado |
66223d |
#
|
|
Alain Reguera Delgado |
66223d |
######################################################################
|
|
Alain Reguera Delgado |
66223d |
|
|
Alain Reguera Delgado |
b33753 |
declare -xr TCAR_SCRIPT_NAME="tcar"
|
|
Alain Reguera Delgado |
b33753 |
declare -xr TCAR_SCRIPT_VERSION="0.9"
|
|
Alain Reguera Delgado |
66223d |
|
|
Alain Reguera Delgado |
66223d |
######################################################################
|
|
Alain Reguera Delgado |
b33753 |
# Script Internationalization
|
|
Alain Reguera Delgado |
66223d |
######################################################################
|
|
Alain Reguera Delgado |
66223d |
|
|
Alain Reguera Delgado |
66223d |
# Set the script language information using the LC format. This format
|
|
Alain Reguera Delgado |
66223d |
# shows both language and country information (e.g., `es_ES').
|
|
Alain Reguera Delgado |
66223d |
declare -xr TCAR_SCRIPT_LANG_LC=$(echo ${LANG} | cut -d'.' -f1)
|
|
Alain Reguera Delgado |
66223d |
|
|
Alain Reguera Delgado |
66223d |
# Set the script language information using the LL format. This format
|
|
Alain Reguera Delgado |
66223d |
# shows only the language information (e.g., `es').
|
|
Alain Reguera Delgado |
66223d |
declare -xr TCAR_SCRIPT_LANG_LL=$(echo ${TCAR_SCRIPT_LANG_LC} | cut -d'_' -f1)
|
|
Alain Reguera Delgado |
66223d |
|
|
Alain Reguera Delgado |
66223d |
# Set the script language information using the CC format. This format
|
|
Alain Reguera Delgado |
66223d |
# shows only the country information (e.g., `ES').
|
|
Alain Reguera Delgado |
66223d |
declare -xr TCAR_SCRIPT_LANG_CC=$(echo ${TCAR_SCRIPT_LANG_LC} | cut -d'_' -f2)
|
|
Alain Reguera Delgado |
66223d |
|
|
Alain Reguera Delgado |
66223d |
# Set function environments required by GNU gettext system.
|
|
Alain Reguera Delgado |
66223d |
. gettext.sh
|
|
Alain Reguera Delgado |
66223d |
|
|
Alain Reguera Delgado |
66223d |
######################################################################
|
|
Alain Reguera Delgado |
b33753 |
# Script Configuration Files (redefine global variables)
|
|
Alain Reguera Delgado |
66223d |
######################################################################
|
|
Alain Reguera Delgado |
66223d |
|
|
Alain Reguera Delgado |
b33753 |
declare -xr TCAR_SCRIPT_CONFIGS="/etc/tcar/tcar.conf ${HOME}/.tcar.conf"
|
|
Alain Reguera Delgado |
b33753 |
for TCAR_SCRIPT_CONFIG in ${TCAR_SCRIPT_CONFIGS};do
|
|
Alain Reguera Delgado |
b33753 |
if [[ -f ${TCAR_SCRIPT_CONFIG} ]];then
|
|
Alain Reguera Delgado |
b33753 |
. ${TCAR_SCRIPT_CONFIG}
|
|
Alain Reguera Delgado |
b33753 |
fi
|
|
Alain Reguera Delgado |
b33753 |
done
|
|
Alain Reguera Delgado |
66223d |
|
|
Alain Reguera Delgado |
66223d |
######################################################################
|
|
Alain Reguera Delgado |
b33753 |
# Script Global Functions
|
|
Alain Reguera Delgado |
66223d |
######################################################################
|
|
Alain Reguera Delgado |
66223d |
|
|
Alain Reguera Delgado |
66223d |
# Export script's environment functions.
|
|
Alain Reguera Delgado |
9866fc |
for SCRIPT_FILE in $(ls ${TCAR_SCRIPT_BASEDIR}/tcar_*.sh);do
|
|
Alain Reguera Delgado |
66223d |
if [[ -x ${SCRIPT_FILE} ]];then
|
|
Alain Reguera Delgado |
66223d |
. ${SCRIPT_FILE}
|
|
Alain Reguera Delgado |
66223d |
export -f $(grep '^function ' ${SCRIPT_FILE} | cut -d' ' -f2)
|
|
Alain Reguera Delgado |
66223d |
else
|
|
Alain Reguera Delgado |
66223d |
echo "${SCRIPT_FILE} `gettext "has not execution rights."`"
|
|
Alain Reguera Delgado |
66223d |
exit 1
|
|
Alain Reguera Delgado |
66223d |
fi
|
|
Alain Reguera Delgado |
66223d |
done
|
|
Alain Reguera Delgado |
66223d |
|
|
Alain Reguera Delgado |
66223d |
######################################################################
|
|
Alain Reguera Delgado |
66223d |
# Signals
|
|
Alain Reguera Delgado |
66223d |
######################################################################
|
|
Alain Reguera Delgado |
66223d |
|
|
Alain Reguera Delgado |
66223d |
# Trap signals in order to terminate the script execution correctly
|
|
Alain Reguera Delgado |
66223d |
# (e.g., removing all temporal files before leaving). Trapping the
|
|
Alain Reguera Delgado |
66223d |
# exit signal seems to be enough by now, since it is always present as
|
|
Alain Reguera Delgado |
66223d |
# part of the script execution flow. Each time the tcar.sh
|
|
Alain Reguera Delgado |
66223d |
# script is executed it will inevitably end with an EXIT signal at
|
|
Alain Reguera Delgado |
66223d |
# some point of its execution, even if it is interrupted in the middle
|
|
Alain Reguera Delgado |
66223d |
# of its execution (e.g., through `Ctrl+C').
|
|
Alain Reguera Delgado |
66223d |
trap tcar_terminateScriptExecution 0
|
|
Alain Reguera Delgado |
66223d |
|
|
Alain Reguera Delgado |
66223d |
######################################################################
|
|
Alain Reguera Delgado |
b33753 |
# Default Action
|
|
Alain Reguera Delgado |
b33753 |
######################################################################
|
|
Alain Reguera Delgado |
b33753 |
|
|
Alain Reguera Delgado |
b33753 |
if [[ $# -eq 0 ]];then
|
|
Alain Reguera Delgado |
b33753 |
tcar_printUsage
|
|
Alain Reguera Delgado |
b33753 |
fi
|
|
Alain Reguera Delgado |
b33753 |
|
|
Alain Reguera Delgado |
b33753 |
######################################################################
|
|
Alain Reguera Delgado |
66223d |
# Parse Command-line Arguments
|
|
Alain Reguera Delgado |
66223d |
######################################################################
|
|
Alain Reguera Delgado |
66223d |
|
|
Alain Reguera Delgado |
66223d |
declare -x TCAR_MODULE_NAME=''
|
|
Alain Reguera Delgado |
66223d |
declare -x TCAR_MODULE_ARGUMENT=''
|
|
Alain Reguera Delgado |
66223d |
declare -x TCAR_SCRIPT_ARGUMENT=''
|
|
Alain Reguera Delgado |
66223d |
|
|
Alain Reguera Delgado |
66223d |
# Retrieve module's name using the first argument of tcar.sh
|
|
Alain Reguera Delgado |
66223d |
# script as reference.
|
|
Alain Reguera Delgado |
66223d |
if [[ ! ${1} =~ '^-' ]];then
|
|
Alain Reguera Delgado |
66223d |
TCAR_MODULE_NAME="${1}"; shift 1
|
|
Alain Reguera Delgado |
66223d |
else
|
|
Alain Reguera Delgado |
66223d |
TCAR_MODULE_NAME=""
|
|
Alain Reguera Delgado |
66223d |
fi
|
|
Alain Reguera Delgado |
66223d |
|
|
Alain Reguera Delgado |
66223d |
# Initialize tcar.sh script specific options. The way tcar.sh script
|
|
Alain Reguera Delgado |
66223d |
# retrieves its options isn't as sophisticated (e.g., it doesn't
|
|
Alain Reguera Delgado |
66223d |
# provide valid-option verifications) as it is provided by getopt
|
|
Alain Reguera Delgado |
b33753 |
# command. I cannot use getopt here because it is used already when
|
|
Alain Reguera Delgado |
66223d |
# loading module-specific options. Using more than one invocation of
|
|
Alain Reguera Delgado |
66223d |
# getopt in the same script is not possible (e.g., one of the
|
|
Alain Reguera Delgado |
66223d |
# invocations may enter in conflict with the other one when different
|
|
Alain Reguera Delgado |
66223d |
# option definitions are expected in the command-line.)
|
|
Alain Reguera Delgado |
66223d |
while true; do
|
|
Alain Reguera Delgado |
66223d |
|
|
Alain Reguera Delgado |
66223d |
# Store non-option arguments passed to tcar.sh script.
|
|
Alain Reguera Delgado |
66223d |
if [[ ! ${1} =~ '^-' ]];then
|
|
Alain Reguera Delgado |
66223d |
TCAR_SCRIPT_ARGUMENT="${1} ${TCAR_SCRIPT_ARGUMENT}"
|
|
Alain Reguera Delgado |
66223d |
shift 1
|
|
Alain Reguera Delgado |
66223d |
if [[ $# -gt 0 ]];then
|
|
Alain Reguera Delgado |
66223d |
continue
|
|
Alain Reguera Delgado |
66223d |
else
|
|
Alain Reguera Delgado |
66223d |
break
|
|
Alain Reguera Delgado |
66223d |
fi
|
|
Alain Reguera Delgado |
66223d |
fi
|
|
Alain Reguera Delgado |
66223d |
|
|
Alain Reguera Delgado |
66223d |
case "${1}" in
|
|
Alain Reguera Delgado |
66223d |
|
|
Alain Reguera Delgado |
b33753 |
--help )
|
|
Alain Reguera Delgado |
66223d |
|
|
Alain Reguera Delgado |
66223d |
if [[ -z ${TCAR_MODULE_NAME} ]];then
|
|
Alain Reguera Delgado |
ddb01a |
tcar_printHelp
|
|
Alain Reguera Delgado |
66223d |
else
|
|
Alain Reguera Delgado |
66223d |
# Store the argument for further processing inside the
|
|
Alain Reguera Delgado |
66223d |
# module environment that will be executed later.
|
|
Alain Reguera Delgado |
66223d |
TCAR_MODULE_ARGUMENT="-g ${1} ${TCAR_MODULE_ARGUMENT}"
|
|
Alain Reguera Delgado |
66223d |
shift 1
|
|
Alain Reguera Delgado |
66223d |
fi
|
|
Alain Reguera Delgado |
66223d |
;;
|
|
Alain Reguera Delgado |
66223d |
|
|
Alain Reguera Delgado |
66223d |
--version )
|
|
Alain Reguera Delgado |
66223d |
|
|
Alain Reguera Delgado |
66223d |
if [[ -z ${TCAR_MODULE_NAME} ]];then
|
|
Alain Reguera Delgado |
66223d |
tcar_printVersion
|
|
Alain Reguera Delgado |
66223d |
else
|
|
Alain Reguera Delgado |
66223d |
TCAR_MODULE_ARGUMENT="-g ${1} ${TCAR_MODULE_ARGUMENT}"
|
|
Alain Reguera Delgado |
66223d |
shift 1
|
|
Alain Reguera Delgado |
66223d |
fi
|
|
Alain Reguera Delgado |
66223d |
;;
|
|
Alain Reguera Delgado |
66223d |
|
|
Alain Reguera Delgado |
66223d |
--quiet )
|
|
Alain Reguera Delgado |
66223d |
|
|
Alain Reguera Delgado |
66223d |
TCAR_FLAG_QUIET='true'
|
|
Alain Reguera Delgado |
66223d |
shift 1
|
|
Alain Reguera Delgado |
66223d |
;;
|
|
Alain Reguera Delgado |
66223d |
|
|
Alain Reguera Delgado |
66223d |
--yes )
|
|
Alain Reguera Delgado |
66223d |
|
|
Alain Reguera Delgado |
66223d |
TCAR_FLAG_YES='true'
|
|
Alain Reguera Delgado |
66223d |
shift 1
|
|
Alain Reguera Delgado |
66223d |
;;
|
|
Alain Reguera Delgado |
66223d |
|
|
Alain Reguera Delgado |
66223d |
--debug )
|
|
Alain Reguera Delgado |
66223d |
|
|
Alain Reguera Delgado |
66223d |
TCAR_FLAG_DEBUG='true'
|
|
Alain Reguera Delgado |
66223d |
shift 1
|
|
Alain Reguera Delgado |
66223d |
;;
|
|
Alain Reguera Delgado |
66223d |
|
|
Alain Reguera Delgado |
66223d |
* )
|
|
Alain Reguera Delgado |
66223d |
|
|
Alain Reguera Delgado |
66223d |
# Store module-specific option arguments. This is, all
|
|
Alain Reguera Delgado |
66223d |
# arguments not considered part of tcar.sh script
|
|
Alain Reguera Delgado |
66223d |
# itself. The module-specific option arguments are passed,
|
|
Alain Reguera Delgado |
66223d |
# later, to getopt for option processing, inside the
|
|
Alain Reguera Delgado |
66223d |
# module-specific environments.
|
|
Alain Reguera Delgado |
66223d |
TCAR_MODULE_ARGUMENT="-g ${1} ${TCAR_MODULE_ARGUMENT}"
|
|
Alain Reguera Delgado |
66223d |
shift 1
|
|
Alain Reguera Delgado |
66223d |
if [[ $# -gt 0 ]];then
|
|
Alain Reguera Delgado |
66223d |
continue
|
|
Alain Reguera Delgado |
66223d |
else
|
|
Alain Reguera Delgado |
66223d |
break
|
|
Alain Reguera Delgado |
66223d |
fi
|
|
Alain Reguera Delgado |
66223d |
;;
|
|
Alain Reguera Delgado |
66223d |
esac
|
|
Alain Reguera Delgado |
66223d |
done
|
|
Alain Reguera Delgado |
66223d |
|
|
Alain Reguera Delgado |
66223d |
# Initiate module-specific environment.
|
|
Alain Reguera Delgado |
66223d |
tcar_setModuleEnvironment -m "${TCAR_MODULE_NAME}" ${TCAR_MODULE_ARGUMENT} ${TCAR_SCRIPT_ARGUMENT}
|
|
Alain Reguera Delgado |
66223d |
|
|
Alain Reguera Delgado |
66223d |
# At this point everything has been done without errors. So, exit
|
|
Alain Reguera Delgado |
66223d |
# tcar.sh script successfully.
|
|
Alain Reguera Delgado |
66223d |
exit 0
|