|
Alain Reguera Delgado |
8f60cb |
#!/bin/bash
|
|
Alain Reguera Delgado |
daf412 |
######################################################################
|
|
Alain Reguera Delgado |
8f60cb |
#
|
|
Alain Reguera Delgado |
0de111 |
# centos-art.sh -- The CentOS artwork repository automation tool.
|
|
Alain Reguera Delgado |
615395 |
#
|
|
Alain Reguera Delgado |
daf412 |
# Written by:
|
|
Alain Reguera Delgado |
615395 |
# * Alain Reguera Delgado <al@centos.org.cu>, 2009-2013
|
|
Alain Reguera Delgado |
8f60cb |
#
|
|
Alain Reguera Delgado |
daf412 |
# Copyright (C) 2009-2013 The CentOS Artwork SIG
|
|
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 |
daf412 |
######################################################################
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
0de111 |
# Verify absolute path to the working directory. This information is
|
|
Alain Reguera Delgado |
0de111 |
# critical for centos-art.sh script to work.
|
|
Alain Reguera Delgado |
954d94 |
if [[ ! ${TCAR_BASEDIR} ]] || [[ -z ${TCAR_BASEDIR} ]] \
|
|
Alain Reguera Delgado |
954d94 |
|| [[ ! -d ${TCAR_BASEDIR} ]];then
|
|
Alain Reguera Delgado |
daf412 |
printf "Enter repository's absolute path: "
|
|
Alain Reguera Delgado |
954d94 |
read TCAR_BASEDIR
|
|
Alain Reguera Delgado |
daf412 |
declare -xr TCAR_BASEDIR=$(printf ${TCAR_BASEDIR} \
|
|
Alain Reguera Delgado |
daf412 |
| sed -r -e 's,/+,/,g' -e 's,/+$,,')
|
|
Alain Reguera Delgado |
0de111 |
fi
|
|
Alain Reguera Delgado |
0de111 |
|
|
Alain Reguera Delgado |
0de111 |
# Define automation scripts base directory. We need to define it here
|
|
Alain Reguera Delgado |
0de111 |
# in order to reach the configuration file. All other environment
|
|
Alain Reguera Delgado |
0de111 |
# variable definitions must be declared inside the configuration file.
|
|
Alain Reguera Delgado |
954d94 |
if [[ -d ${TCAR_BASEDIR} ]];then
|
|
Alain Reguera Delgado |
954d94 |
declare -xr TCAR_SCRIPT_BASEDIR=${TCAR_BASEDIR}/Automation
|
|
Alain Reguera Delgado |
954d94 |
else
|
|
Alain Reguera Delgado |
954d94 |
exit 1
|
|
Alain Reguera Delgado |
954d94 |
fi
|
|
Alain Reguera Delgado |
0de111 |
|
|
Alain Reguera Delgado |
615395 |
# Initialize default configuration values.
|
|
Alain Reguera Delgado |
954d94 |
if [[ -d ${TCAR_SCRIPT_BASEDIR} ]];then
|
|
Alain Reguera Delgado |
affd55 |
. ${TCAR_SCRIPT_BASEDIR}/centos-art.conf.sh
|
|
Alain Reguera Delgado |
954d94 |
else
|
|
Alain Reguera Delgado |
954d94 |
exit 1
|
|
Alain Reguera Delgado |
954d94 |
fi
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
06ab0f |
# Initialize user-specific configuration values. Users can use this
|
|
Alain Reguera Delgado |
06ab0f |
# file to customize the way centos-art.sh script behaves.
|
|
Alain Reguera Delgado |
615395 |
if [[ -f ${TCAR_USER_CONFIG} ]];then
|
|
Alain Reguera Delgado |
615395 |
. ${TCAR_USER_CONFIG}
|
|
Alain Reguera Delgado |
8f60cb |
fi
|
|
Alain Reguera Delgado |
8f60cb |
|
|
Alain Reguera Delgado |
06ab0f |
# Export script's environment functions.
|
|
Alain Reguera Delgado |
06ab0f |
for SCRIPT_FILE in $(ls ${TCAR_SCRIPT_BASEDIR}/Scripts/*.sh);do
|
|
Alain Reguera Delgado |
06ab0f |
if [[ -x ${SCRIPT_FILE} ]];then
|
|
Alain Reguera Delgado |
06ab0f |
. ${SCRIPT_FILE}
|
|
Alain Reguera Delgado |
06ab0f |
export -f $(grep '^function ' ${SCRIPT_FILE} | cut -d' ' -f2)
|
|
Alain Reguera Delgado |
06ab0f |
else
|
|
Alain Reguera Delgado |
06ab0f |
echo "${SCRIPT_FILE} `gettext "has not execution rights."`"
|
|
Alain Reguera Delgado |
06ab0f |
exit 1
|
|
Alain Reguera Delgado |
06ab0f |
fi
|
|
Alain Reguera Delgado |
06ab0f |
done
|
|
Alain Reguera Delgado |
954d94 |
|
|
Alain Reguera Delgado |
06ab0f |
# Trap signals in order to terminate the script execution correctly
|
|
Alain Reguera Delgado |
06ab0f |
# (e.g., removing all temporal files before leaving). Trapping the
|
|
Alain Reguera Delgado |
06ab0f |
# exit signal seems to be enough by now, since it is always present as
|
|
Alain Reguera Delgado |
06ab0f |
# part of the script execution flow. Each time the centos-art.sh
|
|
Alain Reguera Delgado |
06ab0f |
# script is executed it will inevitably end with an EXIT signal at
|
|
Alain Reguera Delgado |
06ab0f |
# some point of its execution, even if it is interrupted in the middle
|
|
Alain Reguera Delgado |
06ab0f |
# of its execution (e.g., through `Ctrl+C').
|
|
Alain Reguera Delgado |
06ab0f |
trap tcar_terminateScriptExecution 0
|
|
Alain Reguera Delgado |
06ab0f |
|
|
Alain Reguera Delgado |
06ab0f |
# Retrieve module's name using the first argument of centos-art.sh
|
|
Alain Reguera Delgado |
06ab0f |
# script as reference.
|
|
Alain Reguera Delgado |
06ab0f |
if [[ ! ${1} =~ '^-' ]];then
|
|
Alain Reguera Delgado |
06ab0f |
TCAR_MODULE_NAME="${1}"; shift 1
|
|
Alain Reguera Delgado |
06ab0f |
else
|
|
Alain Reguera Delgado |
06ab0f |
TCAR_MODULE_NAME=""
|
|
Alain Reguera Delgado |
06ab0f |
fi
|
|
Alain Reguera Delgado |
06ab0f |
|
|
Alain Reguera Delgado |
06ab0f |
# Initialize centos-art.sh script specific options. The way
|
|
Alain Reguera Delgado |
06ab0f |
# centos-art.sh script retrieve its options isn't as sophisticated
|
|
Alain Reguera Delgado |
06ab0f |
# (e.g., it doesn't provide valid-option verifications) as it is
|
|
Alain Reguera Delgado |
06ab0f |
# provided by getopt command. We cannot use getopt here because it is
|
|
Alain Reguera Delgado |
06ab0f |
# already used when loading module-specific options. Using more than
|
|
Alain Reguera Delgado |
06ab0f |
# one invocation of getopt in the same script is not possible (e.g.,
|
|
Alain Reguera Delgado |
06ab0f |
# one of the invocations may enter in conflict with the other one when
|
|
Alain Reguera Delgado |
06ab0f |
# different option definitions are expected in the command-line.)
|
|
Alain Reguera Delgado |
06ab0f |
while true; do
|
|
Alain Reguera Delgado |
06ab0f |
|
|
Alain Reguera Delgado |
06ab0f |
# Store non-option arguments passed to centos-art.sh script.
|
|
Alain Reguera Delgado |
06ab0f |
if [[ ! ${1} =~ '^-' ]];then
|
|
Alain Reguera Delgado |
06ab0f |
TCAR_SCRIPT_ARGUMENT="${1} ${TCAR_SCRIPT_ARGUMENT}"
|
|
Alain Reguera Delgado |
06ab0f |
shift 1
|
|
Alain Reguera Delgado |
06ab0f |
if [[ $# -gt 0 ]];then
|
|
Alain Reguera Delgado |
06ab0f |
continue
|
|
Alain Reguera Delgado |
06ab0f |
else
|
|
Alain Reguera Delgado |
06ab0f |
break
|
|
Alain Reguera Delgado |
06ab0f |
fi
|
|
Alain Reguera Delgado |
06ab0f |
fi
|
|
Alain Reguera Delgado |
06ab0f |
|
|
Alain Reguera Delgado |
06ab0f |
case "${1}" in
|
|
Alain Reguera Delgado |
06ab0f |
|
|
Alain Reguera Delgado |
90b3f7 |
--help* )
|
|
Alain Reguera Delgado |
90b3f7 |
|
|
Alain Reguera Delgado |
90b3f7 |
if [[ -z ${TCAR_MODULE_NAME} ]];then
|
|
Alain Reguera Delgado |
90b3f7 |
# Print centos-art.sh script's help. Consider that the
|
|
Alain Reguera Delgado |
90b3f7 |
# --help option can receive an argument by using the
|
|
Alain Reguera Delgado |
90b3f7 |
# equal sign (e.g.,
|
|
Alain Reguera Delgado |
90b3f7 |
# --help=tcar_setModuleEnvironment.sh). However, it
|
|
Alain Reguera Delgado |
90b3f7 |
# is not possible to use spaces instead of equal sign
|
|
Alain Reguera Delgado |
90b3f7 |
# because that would confuse other options from being
|
|
Alain Reguera Delgado |
90b3f7 |
# parsed.
|
|
Alain Reguera Delgado |
90b3f7 |
tcar_printHelp "${1}"
|
|
Alain Reguera Delgado |
90b3f7 |
exit 0
|
|
Alain Reguera Delgado |
90b3f7 |
else
|
|
Alain Reguera Delgado |
90b3f7 |
# Store the argument for further processing inside the
|
|
Alain Reguera Delgado |
90b3f7 |
# module environment that will be executed later.
|
|
Alain Reguera Delgado |
90b3f7 |
TCAR_MODULE_ARGUMENT="-g ${1} ${TCAR_MODULE_ARGUMENT}"
|
|
Alain Reguera Delgado |
90b3f7 |
shift 1
|
|
Alain Reguera Delgado |
90b3f7 |
fi
|
|
Alain Reguera Delgado |
90b3f7 |
;;
|
|
Alain Reguera Delgado |
90b3f7 |
|
|
Alain Reguera Delgado |
90b3f7 |
--version )
|
|
Alain Reguera Delgado |
90b3f7 |
|
|
Alain Reguera Delgado |
90b3f7 |
# Print centos-art.sh script's version.
|
|
Alain Reguera Delgado |
90b3f7 |
if [[ -z ${TCAR_MODULE_NAME} ]];then
|
|
Alain Reguera Delgado |
90b3f7 |
tcar_printVersion
|
|
Alain Reguera Delgado |
90b3f7 |
exit 0
|
|
Alain Reguera Delgado |
90b3f7 |
else
|
|
Alain Reguera Delgado |
90b3f7 |
TCAR_MODULE_ARGUMENT="-g ${1} ${TCAR_MODULE_ARGUMENT}"
|
|
Alain Reguera Delgado |
90b3f7 |
shift 1
|
|
Alain Reguera Delgado |
90b3f7 |
fi
|
|
Alain Reguera Delgado |
90b3f7 |
;;
|
|
Alain Reguera Delgado |
90b3f7 |
|
|
Alain Reguera Delgado |
90b3f7 |
--quiet )
|
|
Alain Reguera Delgado |
90b3f7 |
|
|
Alain Reguera Delgado |
90b3f7 |
TCAR_FLAG_QUIET='true'
|
|
Alain Reguera Delgado |
06ab0f |
shift 1
|
|
Alain Reguera Delgado |
90b3f7 |
;;
|
|
Alain Reguera Delgado |
954d94 |
|
|
Alain Reguera Delgado |
90b3f7 |
--yes )
|
|
Alain Reguera Delgado |
90b3f7 |
|
|
Alain Reguera Delgado |
90b3f7 |
TCAR_FLAG_YES='true'
|
|
Alain Reguera Delgado |
06ab0f |
shift 1
|
|
Alain Reguera Delgado |
90b3f7 |
;;
|
|
Alain Reguera Delgado |
954d94 |
|
|
Alain Reguera Delgado |
90b3f7 |
--debug )
|
|
Alain Reguera Delgado |
5824c8 |
|
|
Alain Reguera Delgado |
90b3f7 |
TCAR_FLAG_DEBUG='true'
|
|
Alain Reguera Delgado |
90b3f7 |
shift 1
|
|
Alain Reguera Delgado |
90b3f7 |
;;
|
|
Alain Reguera Delgado |
06ab0f |
|
|
Alain Reguera Delgado |
90b3f7 |
* )
|
|
Alain Reguera Delgado |
06ab0f |
|
|
Alain Reguera Delgado |
90b3f7 |
# Store module-specific option arguments. This is, all
|
|
Alain Reguera Delgado |
90b3f7 |
# arguments not considered part of centos-art.sh script
|
|
Alain Reguera Delgado |
90b3f7 |
# itself. The module-specific option arguments are passed,
|
|
Alain Reguera Delgado |
90b3f7 |
# later, to getopt for option processing, inside the
|
|
Alain Reguera Delgado |
90b3f7 |
# module-specific environments.
|
|
Alain Reguera Delgado |
90b3f7 |
TCAR_MODULE_ARGUMENT="-g ${1} ${TCAR_MODULE_ARGUMENT}"
|
|
Alain Reguera Delgado |
90b3f7 |
shift 1
|
|
Alain Reguera Delgado |
90b3f7 |
if [[ $# -gt 0 ]];then
|
|
Alain Reguera Delgado |
90b3f7 |
continue
|
|
Alain Reguera Delgado |
90b3f7 |
else
|
|
Alain Reguera Delgado |
90b3f7 |
break
|
|
Alain Reguera Delgado |
90b3f7 |
fi
|
|
Alain Reguera Delgado |
90b3f7 |
;;
|
|
Alain Reguera Delgado |
06ab0f |
esac
|
|
Alain Reguera Delgado |
06ab0f |
done
|
|
Alain Reguera Delgado |
06ab0f |
|
|
Alain Reguera Delgado |
06ab0f |
# Initiate module-specific environment.
|
|
Alain Reguera Delgado |
06ab0f |
tcar_setModuleEnvironment -m "${TCAR_MODULE_NAME}" ${TCAR_MODULE_ARGUMENT} ${TCAR_SCRIPT_ARGUMENT}
|
|
Alain Reguera Delgado |
954d94 |
|
|
Alain Reguera Delgado |
06ab0f |
# At this point everything has been done without errors. So, exit
|
|
Alain Reguera Delgado |
06ab0f |
# centos-art.sh script successfully.
|
|
Alain Reguera Delgado |
954d94 |
exit 0
|