|
Alain Reguera Delgado |
66223d |
#!/bin/bash
|
|
Alain Reguera Delgado |
66223d |
######################################################################
|
|
Alain Reguera Delgado |
66223d |
#
|
|
Alain Reguera Delgado |
66223d |
# tcar.sh -- The CentOS Artwork Repository automation tool.
|
|
Alain Reguera Delgado |
66223d |
#
|
|
Alain Reguera Delgado |
66223d |
# Written by:
|
|
Alain Reguera Delgado |
66223d |
# * Alain Reguera Delgado <al@centos.org.cu>, 2009-2013
|
|
Alain Reguera Delgado |
66223d |
#
|
|
Alain Reguera Delgado |
66223d |
# Copyright (C) 2009-2013 The CentOS Artwork SIG
|
|
Alain Reguera Delgado |
66223d |
#
|
|
Alain Reguera Delgado |
66223d |
# This program is free software; you can redistribute it and/or modify
|
|
Alain Reguera Delgado |
66223d |
# it under the terms of the GNU General Public License as published by
|
|
Alain Reguera Delgado |
66223d |
# the Free Software Foundation; either version 2 of the License, or (at
|
|
Alain Reguera Delgado |
66223d |
# your option) any later version.
|
|
Alain Reguera Delgado |
66223d |
#
|
|
Alain Reguera Delgado |
66223d |
# This program is distributed in the hope that it will be useful, but
|
|
Alain Reguera Delgado |
66223d |
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Alain Reguera Delgado |
66223d |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Alain Reguera Delgado |
66223d |
# General Public License for more details.
|
|
Alain Reguera Delgado |
66223d |
#
|
|
Alain Reguera Delgado |
66223d |
# You should have received a copy of the GNU General Public License
|
|
Alain Reguera Delgado |
66223d |
# along with this program; if not, write to the Free Software
|
|
Alain Reguera Delgado |
66223d |
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
Alain Reguera Delgado |
66223d |
#
|
|
Alain Reguera Delgado |
66223d |
######################################################################
|
|
Alain Reguera Delgado |
66223d |
|
|
Alain Reguera Delgado |
66223d |
######################################################################
|
|
Alain Reguera Delgado |
66223d |
# Identity
|
|
Alain Reguera Delgado |
66223d |
######################################################################
|
|
Alain Reguera Delgado |
66223d |
|
|
Alain Reguera Delgado |
bbb179 |
declare -xr TCAR_SCRIPT_PACKAGE="tcar"
|
|
Alain Reguera Delgado |
6d9448 |
declare -xr TCAR_SCRIPT_VERSION="$(rpm -q --qf "%{VERSION}" ${TCAR_SCRIPT_PACKAGE})"
|
|
Alain Reguera Delgado |
66223d |
|
|
Alain Reguera Delgado |
66223d |
######################################################################
|
|
Alain Reguera Delgado |
66223d |
# Paths
|
|
Alain Reguera Delgado |
66223d |
######################################################################
|
|
Alain Reguera Delgado |
66223d |
|
|
Alain Reguera Delgado |
66223d |
# Base directory where repository files are installed in.
|
|
Alain Reguera Delgado |
610d0b |
declare -xr TCAR_BASEDIR=/usr/share/tcar/Scripts
|
|
Alain Reguera Delgado |
66223d |
|
|
Alain Reguera Delgado |
66223d |
# Base directory where final content is produced. This value should be
|
|
Alain Reguera Delgado |
66223d |
# customized later by the user.
|
|
Alain Reguera Delgado |
66223d |
declare -xr TCAR_WORKDIR=/tmp
|
|
Alain Reguera Delgado |
66223d |
|
|
Alain Reguera Delgado |
66223d |
# Directory to store temporal files.
|
|
Alain Reguera Delgado |
bbb179 |
declare -xr TCAR_SCRIPT_TEMPDIR=$(mktemp -p /tmp -d ${TCAR_SCRIPT_PACKAGE}-XXXXXX)
|
|
Alain Reguera Delgado |
66223d |
|
|
Alain Reguera Delgado |
66223d |
# Configuration files in order of reading preference. The last file in
|
|
Alain Reguera Delgado |
66223d |
# the list overlaps options set in previous files in the list. Use
|
|
Alain Reguera Delgado |
66223d |
# colon character to separate files in the list.
|
|
Alain Reguera Delgado |
66223d |
declare -xr TCAR_SCRIPT_CONFIG=${HOME}/.tcar.conf
|
|
Alain Reguera Delgado |
66223d |
|
|
Alain Reguera Delgado |
66223d |
# Base directory where man pages are searched at.
|
|
Alain Reguera Delgado |
1e179f |
declare -xr TCAR_SCRIPT_MANUALS=/usr/share/man
|
|
Alain Reguera Delgado |
1e179f |
|
|
Alain Reguera Delgado |
1e179f |
# Base directory where automation script modules are installed in.
|
|
Alain Reguera Delgado |
610d0b |
declare -xr TCAR_SCRIPT_MODULES_BASEDIR=${TCAR_BASEDIR}/Modules
|
|
Alain Reguera Delgado |
66223d |
|
|
Alain Reguera Delgado |
66223d |
# Default text editor.
|
|
Alain Reguera Delgado |
66223d |
declare -x TCAR_SCRIPT_EDITOR=/usr/bin/vim
|
|
Alain Reguera Delgado |
66223d |
|
|
Alain Reguera Delgado |
66223d |
######################################################################
|
|
Alain Reguera Delgado |
66223d |
# 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 |
# Set the script text domain. This information is used by gettext
|
|
Alain Reguera Delgado |
66223d |
# system to retrieve translated strings from machine object (MO) files
|
|
Alain Reguera Delgado |
66223d |
# with this name. This variable is reset each time a new module is
|
|
Alain Reguera Delgado |
66223d |
# loaded, so the correct files can be used.
|
|
Alain Reguera Delgado |
bbb179 |
declare -x TEXTDOMAIN="${TCAR_SCRIPT_PACKAGE}"
|
|
Alain Reguera Delgado |
66223d |
|
|
Alain Reguera Delgado |
66223d |
# Set the script text domain directory. This information is used by
|
|
Alain Reguera Delgado |
66223d |
# gettext system to know where the machine objects are stored in. This
|
|
Alain Reguera Delgado |
66223d |
# variable is reset each time a new module is loaded, so the correct
|
|
Alain Reguera Delgado |
66223d |
# files can be used.
|
|
Alain Reguera Delgado |
66223d |
declare -x TEXTDOMAINDIR=/usr/share/locale
|
|
Alain Reguera Delgado |
66223d |
|
|
Alain Reguera Delgado |
66223d |
######################################################################
|
|
Alain Reguera Delgado |
66223d |
# Global Flags
|
|
Alain Reguera Delgado |
66223d |
######################################################################
|
|
Alain Reguera Delgado |
66223d |
|
|
Alain Reguera Delgado |
66223d |
# Set filter flag (-f|--filter). This flag is mainly used to reduce
|
|
Alain Reguera Delgado |
66223d |
# the number of files to process and is interpreted as egrep-posix
|
|
Alain Reguera Delgado |
66223d |
# regular expression. By default, when this flag is not provided, all
|
|
Alain Reguera Delgado |
66223d |
# paths in the working copy will match, except files inside hidden
|
|
Alain Reguera Delgado |
66223d |
# directories like `.svn' and `.git' that will be omitted.
|
|
Alain Reguera Delgado |
66223d |
declare -x TCAR_FLAG_FILTER='[[:alnum:]_/-]+'
|
|
Alain Reguera Delgado |
66223d |
|
|
Alain Reguera Delgado |
66223d |
# Set verbosity flag (-q|--quiet). This flag controls whether
|
|
Alain Reguera Delgado |
66223d |
# tcar.sh script prints messages or not. By default, all
|
|
Alain Reguera Delgado |
66223d |
# messages are suppressed except those directed to standard error.
|
|
Alain Reguera Delgado |
66223d |
declare -x TCAR_FLAG_QUIET='false'
|
|
Alain Reguera Delgado |
66223d |
|
|
Alain Reguera Delgado |
66223d |
# Set affirmative flag (-y|--yes). This flag controls whether
|
|
Alain Reguera Delgado |
66223d |
# tcar.sh script does or does not pass confirmation request
|
|
Alain Reguera Delgado |
66223d |
# points. By default, it doesn't.
|
|
Alain Reguera Delgado |
66223d |
declare -x TCAR_FLAG_YES='false'
|
|
Alain Reguera Delgado |
66223d |
|
|
Alain Reguera Delgado |
66223d |
# Set debugger flag (-d|--debug). This flag controls whether
|
|
Alain Reguera Delgado |
66223d |
# tcar.sh script does or does not print debugging information.
|
|
Alain Reguera Delgado |
66223d |
# The tcar.sh script prints debug information to standard
|
|
Alain Reguera Delgado |
66223d |
# output.
|
|
Alain Reguera Delgado |
66223d |
declare -x TCAR_FLAG_DEBUG='false'
|
|
Alain Reguera Delgado |
66223d |
|
|
Alain Reguera Delgado |
66223d |
######################################################################
|
|
Alain Reguera Delgado |
66223d |
# Global Functions
|
|
Alain Reguera Delgado |
66223d |
######################################################################
|
|
Alain Reguera Delgado |
66223d |
|
|
Alain Reguera Delgado |
66223d |
# Export script's environment functions.
|
|
Alain Reguera Delgado |
66223d |
for SCRIPT_FILE in $(ls ${TCAR_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 |
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 |
66223d |
# command. I cannot use getopt here because it is already used 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 |
66223d |
--help* )
|
|
Alain Reguera Delgado |
66223d |
|
|
Alain Reguera Delgado |
66223d |
if [[ -z ${TCAR_MODULE_NAME} ]];then
|
|
Alain Reguera Delgado |
66223d |
# Print tcar.sh script's help. Consider that the
|
|
Alain Reguera Delgado |
66223d |
# --help option can receive an argument by using the
|
|
Alain Reguera Delgado |
66223d |
# equal sign (e.g.,
|
|
Alain Reguera Delgado |
66223d |
# --help=tcar_setModuleEnvironment.sh). However, it
|
|
Alain Reguera Delgado |
66223d |
# is not possible to use spaces instead of equal sign
|
|
Alain Reguera Delgado |
66223d |
# because that would confuse other options from being
|
|
Alain Reguera Delgado |
66223d |
# parsed.
|
|
Alain Reguera Delgado |
66223d |
tcar_printHelp "${1}"
|
|
Alain Reguera Delgado |
66223d |
exit 0
|
|
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 |
# Print tcar.sh script's version.
|
|
Alain Reguera Delgado |
66223d |
if [[ -z ${TCAR_MODULE_NAME} ]];then
|
|
Alain Reguera Delgado |
66223d |
tcar_printVersion
|
|
Alain Reguera Delgado |
66223d |
exit 0
|
|
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
|