From a117358cffbf36943fb22123e72b60f334896536 Mon Sep 17 00:00:00 2001 From: Alain Reguera Delgado Date: Dec 10 2013 19:58:48 +0000 Subject: Redesign initialization script. - Previously, automation scripts were initiated by executing the centos-art.sh script. The name of this script diverges from tcar, The CentOS Artwork Repository abbreviation, that is being used to name variables inside the script and function files related to it. This update renames the initialization script from centos-art.sh to tcar.sh in order to retain the name relation as much as possible. - Previously, definition of global variables, related to script initialization, were stored in the centos-art.conf.sh file. Configuration options are no longer managed inside automation scripts. Instad, they are moved to configuration files that are read by automation scripts at demand. In order for users to customize these configuration options, the configuration file is stored in ${HOME}/.tcar.conf file when the workplace is prepared by automation scripts. This update moves global variable definitions from centos-art.conf.sh file to tcar.sh file and removes centos-art.conf.sh file. - Previously, automation scripts were conceived to work as integral part of the repository itself. It was difficult to produce final content for a directory structures outside The CentOS Artwork Repository itself. This update changes path information inside the initialization script to consider the tcar.sh script a standalone application that you install in your workstation (e.g., using an rpm package) and can execute over arbitrary number of places in your workstation in order to produce final content inside them. - The script version was set to 0.8 internally. --- diff --git a/centos-art.conf.sh b/centos-art.conf.sh deleted file mode 100755 index 4766add..0000000 --- a/centos-art.conf.sh +++ /dev/null @@ -1,136 +0,0 @@ -#!/bin/bash -###################################################################### -# -# centos-art.conf.sh -- This file provides default configuration -# values to centos-art.sh script. -# -# Written by: -# * Alain Reguera Delgado , 2009-2013 -# -# Copyright (C) 2009-2013 The CentOS Artwork SIG -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or (at -# your option) any later version. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -# -###################################################################### - -###################################################################### -# Script's identity configuration variables. -###################################################################### - -# Set the script name. -declare -xr TCAR_SCRIPT_NAME="centos-art.sh" - -# Set the script version. You can use this number as pattern -# to identify the relation between the centos-artwork repository -# and the script. Both repository and script version must be the same. -# This way we can say that specific functionalities inside the script -# will work as expected when run over the repository directory structure. -declare -xr TCAR_SCRIPT_VERSION='0.6' - -# Set the script command name. -declare -xr TCAR_SCRIPT_COMMAND="centos-art" - -###################################################################### -# Script's path configuration variables. -###################################################################### - -# Set the script modules directory. -declare -xr TCAR_SCRIPT_MODULES_BASEDIR=${TCAR_SCRIPT_BASEDIR}/Modules - -# Set the script temporal directory. -declare -xr TCAR_SCRIPT_TEMPDIR=$(mktemp -p /tmp -d ${TCAR_SCRIPT_NAME}-XXXXXX) - -###################################################################### -# Internationalization configuration variables and functions. -###################################################################### - -# Set the script language information using the LC format. This format -# shows both language and country information (e.g., `es_ES'). -declare -xr TCAR_SCRIPT_LANG_LC=$(echo ${LANG} | cut -d'.' -f1) - -# Set the script language information using the LL format. This format -# shows only the language information (e.g., `es'). -declare -xr TCAR_SCRIPT_LANG_LL=$(echo ${TCAR_SCRIPT_LANG_LC} | cut -d'_' -f1) - -# Set the script language information using the CC format. This format -# shows only the country information (e.g., `ES'). -declare -xr TCAR_SCRIPT_LANG_CC=$(echo ${TCAR_SCRIPT_LANG_LC} | cut -d'_' -f2) - -# Set function environments required by GNU gettext system. -. gettext.sh - -# Set the script text domain. This information is used by gettext -# system to retrieve translated strings from machine object (MO) files -# with this name. This variable is reset each time a new module is -# loaded, so the correct files can be used. -declare -x TEXTDOMAIN="${TCAR_SCRIPT_NAME}" - -# Set the script text domain directory. This information is used by -# gettext system to know where the machine objects are stored in. This -# variable is reset each time a new module is loaded, so the correct -# files can be used. -declare -x TEXTDOMAINDIR=${TCAR_SCRIPT_BASEDIR}/Locales - -###################################################################### -# Module-specific configuration variables. -###################################################################### - -# Set absolute path to documentation search path. This is the location -# where final documentation formats (e.g., man pages) will be saved -# in. -declare -x TCAR_SCRIPT_DIR_MANUALS=${TCAR_SCRIPT_BASEDIR}/Manuals/Final - -###################################################################### -# User-related configuration variables. -###################################################################### - -# Set file path to your preferred text editor. The editor you specify -# will be use when you need to write commit messages and anything that -# requires text edition. -declare -x TCAR_USER_EDITOR=/usr/bin/vim - -# Set user-specific configuration file used by centos-art.sh script to -# determine where to retrieve user-specific configuration values. -# User-specific configuration files let you customize the way -# centos-art.sh behaves in a multi-user environment. This variable -# must be read-only. -declare -xr TCAR_USER_CONFIG=${HOME}/.${TCAR_SCRIPT_COMMAND}.conf.sh - -###################################################################### -# Flag-related configuration variables. -###################################################################### - -# Set filter flag (-f|--filter). This flag is mainly used to reduce -# the number of files to process and is interpreted as egrep-posix -# regular expression. By default, when this flag is not provided, all -# paths in the working copy will match, except files inside hidden -# directories like `.svn' and `.git' that will be omitted. -declare -x TCAR_FLAG_FILTER='[[:alnum:]_/-]+' - -# Set verbosity flag (-q|--quiet). This flag controls whether -# centos-art.sh script prints messages or not. By default, all -# messages are suppressed except those directed to standard error. -declare -x TCAR_FLAG_QUIET='false' - -# Set affirmative flag (-y|--yes). This flag controls whether -# centos-art.sh script does or does not pass confirmation request -# points. By default, it doesn't. -declare -x TCAR_FLAG_YES='false' - -# Set debugger flag (-d|--debug). This flag controls whether -# centos-art.sh script does or does not print debugging information. -# The centos-art.sh script prints debug information to standard -# output. -declare -x TCAR_FLAG_DEBUG='false' diff --git a/centos-art.sh b/centos-art.sh deleted file mode 100755 index db6f16b..0000000 --- a/centos-art.sh +++ /dev/null @@ -1,183 +0,0 @@ -#!/bin/bash -###################################################################### -# -# centos-art.sh -- The CentOS artwork repository automation tool. -# -# Written by: -# * Alain Reguera Delgado , 2009-2013 -# -# Copyright (C) 2009-2013 The CentOS Artwork SIG -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or (at -# your option) any later version. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -# -###################################################################### - -# Verify absolute path to the working directory. This information is -# critical for centos-art.sh script to work. -if [[ ! ${TCAR_BASEDIR} ]] || [[ -z ${TCAR_BASEDIR} ]] \ - || [[ ! -d ${TCAR_BASEDIR} ]];then - printf "Enter repository's absolute path: " - read TCAR_BASEDIR - declare -xr TCAR_BASEDIR=$(printf ${TCAR_BASEDIR} \ - | sed -r -e 's,/+,/,g' -e 's,/+$,,') -fi - -# Define automation scripts base directory. We need to define it here -# in order to reach the configuration file. All other environment -# variable definitions must be declared inside the configuration file. -if [[ -d ${TCAR_BASEDIR} ]];then - declare -xr TCAR_SCRIPT_BASEDIR=${TCAR_BASEDIR}/Automation -else - exit 1 -fi - -# Initialize default configuration values. -if [[ -d ${TCAR_SCRIPT_BASEDIR} ]];then - . ${TCAR_SCRIPT_BASEDIR}/centos-art.conf.sh -else - exit 1 -fi - -# Initialize user-specific configuration values. Users can use this -# file to customize the way centos-art.sh script behaves. -if [[ -f ${TCAR_USER_CONFIG} ]];then - . ${TCAR_USER_CONFIG} -fi - -# Export script's environment functions. -for SCRIPT_FILE in $(ls ${TCAR_SCRIPT_BASEDIR}/Scripts/*.sh);do - if [[ -x ${SCRIPT_FILE} ]];then - . ${SCRIPT_FILE} - export -f $(grep '^function ' ${SCRIPT_FILE} | cut -d' ' -f2) - else - echo "${SCRIPT_FILE} `gettext "has not execution rights."`" - exit 1 - fi -done - -# Trap signals in order to terminate the script execution correctly -# (e.g., removing all temporal files before leaving). Trapping the -# exit signal seems to be enough by now, since it is always present as -# part of the script execution flow. Each time the centos-art.sh -# script is executed it will inevitably end with an EXIT signal at -# some point of its execution, even if it is interrupted in the middle -# of its execution (e.g., through `Ctrl+C'). -trap tcar_terminateScriptExecution 0 - -# Retrieve module's name using the first argument of centos-art.sh -# script as reference. -if [[ ! ${1} =~ '^-' ]];then - TCAR_MODULE_NAME="${1}"; shift 1 -else - TCAR_MODULE_NAME="" -fi - -# Initialize centos-art.sh script specific options. The way -# centos-art.sh script retrieve its options isn't as sophisticated -# (e.g., it doesn't provide valid-option verifications) as it is -# provided by getopt command. We cannot use getopt here because it is -# already used when loading module-specific options. Using more than -# one invocation of getopt in the same script is not possible (e.g., -# one of the invocations may enter in conflict with the other one when -# different option definitions are expected in the command-line.) -while true; do - - # Store non-option arguments passed to centos-art.sh script. - if [[ ! ${1} =~ '^-' ]];then - TCAR_SCRIPT_ARGUMENT="${1} ${TCAR_SCRIPT_ARGUMENT}" - shift 1 - if [[ $# -gt 0 ]];then - continue - else - break - fi - fi - - case "${1}" in - - --help* ) - - if [[ -z ${TCAR_MODULE_NAME} ]];then - # Print centos-art.sh script's help. Consider that the - # --help option can receive an argument by using the - # equal sign (e.g., - # --help=tcar_setModuleEnvironment.sh). However, it - # is not possible to use spaces instead of equal sign - # because that would confuse other options from being - # parsed. - tcar_printHelp "${1}" - exit 0 - else - # Store the argument for further processing inside the - # module environment that will be executed later. - TCAR_MODULE_ARGUMENT="-g ${1} ${TCAR_MODULE_ARGUMENT}" - shift 1 - fi - ;; - - --version ) - - # Print centos-art.sh script's version. - if [[ -z ${TCAR_MODULE_NAME} ]];then - tcar_printVersion - exit 0 - else - TCAR_MODULE_ARGUMENT="-g ${1} ${TCAR_MODULE_ARGUMENT}" - shift 1 - fi - ;; - - --quiet ) - - TCAR_FLAG_QUIET='true' - shift 1 - ;; - - --yes ) - - TCAR_FLAG_YES='true' - shift 1 - ;; - - --debug ) - - TCAR_FLAG_DEBUG='true' - shift 1 - ;; - - * ) - - # Store module-specific option arguments. This is, all - # arguments not considered part of centos-art.sh script - # itself. The module-specific option arguments are passed, - # later, to getopt for option processing, inside the - # module-specific environments. - TCAR_MODULE_ARGUMENT="-g ${1} ${TCAR_MODULE_ARGUMENT}" - shift 1 - if [[ $# -gt 0 ]];then - continue - else - break - fi - ;; - esac -done - -# Initiate module-specific environment. -tcar_setModuleEnvironment -m "${TCAR_MODULE_NAME}" ${TCAR_MODULE_ARGUMENT} ${TCAR_SCRIPT_ARGUMENT} - -# At this point everything has been done without errors. So, exit -# centos-art.sh script successfully. -exit 0 diff --git a/tcar.sh b/tcar.sh new file mode 100755 index 0000000..16b4532 --- /dev/null +++ b/tcar.sh @@ -0,0 +1,264 @@ +#!/bin/bash +###################################################################### +# +# tcar.sh -- The CentOS Artwork Repository automation tool. +# +# Written by: +# * Alain Reguera Delgado , 2009-2013 +# +# Copyright (C) 2009-2013 The CentOS Artwork SIG +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +###################################################################### + +###################################################################### +# Identity +###################################################################### + +declare -xr TCAR_SCRIPT_NAME="tcar.sh" +declare -xr TCAR_SCRIPT_VERSION='0.8' +declare -xr TCAR_SCRIPT_COMMAND="tcar" + +###################################################################### +# Paths +###################################################################### + +# Base directory where repository files are installed in. +declare -xr TCAR_BASEDIR=/usr/share/tcar + +# Base directory where final content is produced. This value should be +# customized later by the user. +declare -xr TCAR_WORKDIR=/tmp + +# Base directory where repository automation scripts are installed in. +declare -xr TCAR_SCRIPT_BASEDIR=${TCAR_BASEDIR}/scripts + +# Base directory where automation script modules are installed in. +declare -xr TCAR_SCRIPT_MODULES_BASEDIR=${TCAR_SCRIPT_BASEDIR}/modules + +# Directory to store temporal files. +declare -xr TCAR_SCRIPT_TEMPDIR=$(mktemp -p /tmp -d ${TCAR_SCRIPT_NAME}-XXXXXX) + +# Configuration files in order of reading preference. The last file in +# the list overlaps options set in previous files in the list. Use +# colon character to separate files in the list. +declare -xr TCAR_SCRIPT_CONFIG=${HOME}/.tcar.conf + +# Base directory where man pages are searched at. +declare -x TCAR_SCRIPT_MANUALS=/usr/share/man + +# Default text editor. +declare -x TCAR_SCRIPT_EDITOR=/usr/bin/vim + +###################################################################### +# Internationalization +###################################################################### + +# Set the script language information using the LC format. This format +# shows both language and country information (e.g., `es_ES'). +declare -xr TCAR_SCRIPT_LANG_LC=$(echo ${LANG} | cut -d'.' -f1) + +# Set the script language information using the LL format. This format +# shows only the language information (e.g., `es'). +declare -xr TCAR_SCRIPT_LANG_LL=$(echo ${TCAR_SCRIPT_LANG_LC} | cut -d'_' -f1) + +# Set the script language information using the CC format. This format +# shows only the country information (e.g., `ES'). +declare -xr TCAR_SCRIPT_LANG_CC=$(echo ${TCAR_SCRIPT_LANG_LC} | cut -d'_' -f2) + +# Set function environments required by GNU gettext system. +. gettext.sh + +# Set the script text domain. This information is used by gettext +# system to retrieve translated strings from machine object (MO) files +# with this name. This variable is reset each time a new module is +# loaded, so the correct files can be used. +declare -x TEXTDOMAIN="${TCAR_SCRIPT_NAME}" + +# Set the script text domain directory. This information is used by +# gettext system to know where the machine objects are stored in. This +# variable is reset each time a new module is loaded, so the correct +# files can be used. +declare -x TEXTDOMAINDIR=/usr/share/locale + +###################################################################### +# Global Flags +###################################################################### + +# Set filter flag (-f|--filter). This flag is mainly used to reduce +# the number of files to process and is interpreted as egrep-posix +# regular expression. By default, when this flag is not provided, all +# paths in the working copy will match, except files inside hidden +# directories like `.svn' and `.git' that will be omitted. +declare -x TCAR_FLAG_FILTER='[[:alnum:]_/-]+' + +# Set verbosity flag (-q|--quiet). This flag controls whether +# tcar.sh script prints messages or not. By default, all +# messages are suppressed except those directed to standard error. +declare -x TCAR_FLAG_QUIET='false' + +# Set affirmative flag (-y|--yes). This flag controls whether +# tcar.sh script does or does not pass confirmation request +# points. By default, it doesn't. +declare -x TCAR_FLAG_YES='false' + +# Set debugger flag (-d|--debug). This flag controls whether +# tcar.sh script does or does not print debugging information. +# The tcar.sh script prints debug information to standard +# output. +declare -x TCAR_FLAG_DEBUG='false' + +###################################################################### +# Global Functions +###################################################################### + +# Export script's environment functions. +for SCRIPT_FILE in $(ls ${TCAR_SCRIPT_BASEDIR}/Scripts/*.sh);do + if [[ -x ${SCRIPT_FILE} ]];then + . ${SCRIPT_FILE} + export -f $(grep '^function ' ${SCRIPT_FILE} | cut -d' ' -f2) + else + echo "${SCRIPT_FILE} `gettext "has not execution rights."`" + exit 1 + fi +done + +###################################################################### +# Signals +###################################################################### + +# Trap signals in order to terminate the script execution correctly +# (e.g., removing all temporal files before leaving). Trapping the +# exit signal seems to be enough by now, since it is always present as +# part of the script execution flow. Each time the tcar.sh +# script is executed it will inevitably end with an EXIT signal at +# some point of its execution, even if it is interrupted in the middle +# of its execution (e.g., through `Ctrl+C'). +trap tcar_terminateScriptExecution 0 + +###################################################################### +# Parse Command-line Arguments +###################################################################### + +declare -x TCAR_MODULE_NAME='' +declare -x TCAR_MODULE_ARGUMENT='' +declare -x TCAR_SCRIPT_ARGUMENT='' + +# Retrieve module's name using the first argument of tcar.sh +# script as reference. +if [[ ! ${1} =~ '^-' ]];then + TCAR_MODULE_NAME="${1}"; shift 1 +else + TCAR_MODULE_NAME="" +fi + +# Initialize tcar.sh script specific options. The way tcar.sh script +# retrieves its options isn't as sophisticated (e.g., it doesn't +# provide valid-option verifications) as it is provided by getopt +# command. I cannot use getopt here because it is already used when +# loading module-specific options. Using more than one invocation of +# getopt in the same script is not possible (e.g., one of the +# invocations may enter in conflict with the other one when different +# option definitions are expected in the command-line.) +while true; do + + # Store non-option arguments passed to tcar.sh script. + if [[ ! ${1} =~ '^-' ]];then + TCAR_SCRIPT_ARGUMENT="${1} ${TCAR_SCRIPT_ARGUMENT}" + shift 1 + if [[ $# -gt 0 ]];then + continue + else + break + fi + fi + + case "${1}" in + + --help* ) + + if [[ -z ${TCAR_MODULE_NAME} ]];then + # Print tcar.sh script's help. Consider that the + # --help option can receive an argument by using the + # equal sign (e.g., + # --help=tcar_setModuleEnvironment.sh). However, it + # is not possible to use spaces instead of equal sign + # because that would confuse other options from being + # parsed. + tcar_printHelp "${1}" + exit 0 + else + # Store the argument for further processing inside the + # module environment that will be executed later. + TCAR_MODULE_ARGUMENT="-g ${1} ${TCAR_MODULE_ARGUMENT}" + shift 1 + fi + ;; + + --version ) + + # Print tcar.sh script's version. + if [[ -z ${TCAR_MODULE_NAME} ]];then + tcar_printVersion + exit 0 + else + TCAR_MODULE_ARGUMENT="-g ${1} ${TCAR_MODULE_ARGUMENT}" + shift 1 + fi + ;; + + --quiet ) + + TCAR_FLAG_QUIET='true' + shift 1 + ;; + + --yes ) + + TCAR_FLAG_YES='true' + shift 1 + ;; + + --debug ) + + TCAR_FLAG_DEBUG='true' + shift 1 + ;; + + * ) + + # Store module-specific option arguments. This is, all + # arguments not considered part of tcar.sh script + # itself. The module-specific option arguments are passed, + # later, to getopt for option processing, inside the + # module-specific environments. + TCAR_MODULE_ARGUMENT="-g ${1} ${TCAR_MODULE_ARGUMENT}" + shift 1 + if [[ $# -gt 0 ]];then + continue + else + break + fi + ;; + esac +done + +# Initiate module-specific environment. +tcar_setModuleEnvironment -m "${TCAR_MODULE_NAME}" ${TCAR_MODULE_ARGUMENT} ${TCAR_SCRIPT_ARGUMENT} + +# At this point everything has been done without errors. So, exit +# tcar.sh script successfully. +exit 0