Blame Automation/centos-art.sh

Alain Reguera Delgado 8f60cb
#!/bin/bash
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# centos-art.sh -- The CentOS Artwork Repository automation tool.
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 8f60cb
# ----------------------------------------------------------------------
Alain Reguera Delgado 8f60cb
# $Id$
Alain Reguera Delgado 8f60cb
# ----------------------------------------------------------------------
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
# Initialize relative path (from repository first directory level on)
Alain Reguera Delgado 8f60cb
# used to store bash scripts.
Alain Reguera Delgado 8f60cb
TCAR_BASHSCRIPTS='Scripts/Bash'
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
# Verify the working copy absolute path using the command path. It is
Alain Reguera Delgado 8f60cb
# not possible to consider relative paths here because we are using a
Alain Reguera Delgado 8f60cb
# symbolic link to create the connection between the centos-art.sh
Alain Reguera Delgado 8f60cb
# script and the centos-art command. The link location is stored
Alain Reguera Delgado 8f60cb
# inside ~/bin directory which is outside the repository directory
Alain Reguera Delgado 8f60cb
# structure. So we cannot use the command path as reference to define
Alain Reguera Delgado 8f60cb
# the repository working directory each time we run the command.
Alain Reguera Delgado 8f60cb
# Instead, in order to get the correct working directory path, it is
Alain Reguera Delgado 8f60cb
# required to finish the script execution when the absolute path
Alain Reguera Delgado 8f60cb
# points to the ~/bin directory and print an error message explaining
Alain Reguera Delgado 8f60cb
# the issue. This message cannot be translated to other languages
Alain Reguera Delgado 8f60cb
# because the TEXTDOMAINDIR variable hasn't been defined yet (it
Alain Reguera Delgado 8f60cb
# requires the working copy directory path to be defined first).
Alain Reguera Delgado 8f60cb
if [[ ! $TCAR_WORKDIR ]] || [[ $TCAR_WORKDIR == '' ]] ;then
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    if [[ $0 =~ "^${HOME}/bin" ]];then
Alain Reguera Delgado 8f60cb
        echo "To run centos-art correctly, you need to prepare your workstation first."
Alain Reguera Delgado 8f60cb
        exit 1
Alain Reguera Delgado 8f60cb
    fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
# Initialize absolute path to the working copy. Take care that, in
Alain Reguera Delgado 8f60cb
# some cases, you might execute centos-art.sh script from a path
Alain Reguera Delgado 8f60cb
# different to that set in TCAR_WORKDIR variable inside your
Alain Reguera Delgado 8f60cb
# ~/.bash_profile (e.g., you are changing your working copy from one
Alain Reguera Delgado 8f60cb
# location to another). In these cases, the last path must be used as
Alain Reguera Delgado 8f60cb
# reference whenever it doesn't point to user's bin directory. This is
Alain Reguera Delgado 8f60cb
# another reason to provide the centos-art.sh absolute path when you
Alain Reguera Delgado 8f60cb
# execute the prepare function.
Alain Reguera Delgado 8f60cb
if [[ ! $TCAR_WORKDIR =~ "^$(dirname $0)" ]] \
Alain Reguera Delgado 8f60cb
    && [[ ! $(dirname $0) =~ "^${HOME}/bin" ]];then
Alain Reguera Delgado 8f60cb
    TCAR_WORKDIR=$(dirname $0 | sed "s,/${TCAR_BASHSCRIPTS},,")
Alain Reguera Delgado 8f60cb
fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
# Redefine the working copy absolute path considering the (Subversion)
Alain Reguera Delgado 8f60cb
# previous directory structures used in the repository.
Alain Reguera Delgado 8f60cb
if [[ -d ${TCAR_WORKDIR}/trunk ]];then
Alain Reguera Delgado 8f60cb
    TCAR_WORKDIR=${TCAR_WORKDIR}/trunk
Alain Reguera Delgado 8f60cb
fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
# Initialize repository brand information.
Alain Reguera Delgado 8f60cb
if [[ ! $TCAR_BRAND ]] || [[ $TCAR_BRAND == "" ]];then
Alain Reguera Delgado 8f60cb
    TCAR_BRAND='centos'
Alain Reguera Delgado 8f60cb
fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
# Initialize script-specific configuration variables.
Alain Reguera Delgado 8f60cb
declare -xr CLI_NAME="${TCAR_BRAND}-art"
Alain Reguera Delgado 8f60cb
declare -xr CLI_VERSION='0.4'
Alain Reguera Delgado 8f60cb
declare -xr CLI_LANG_LC=$(echo ${LANG} | cut -d'.' -f1)
Alain Reguera Delgado 8f60cb
declare -xr CLI_LANG_LL=$(echo ${CLI_LANG_LC} | cut -d'_' -f1)
Alain Reguera Delgado 8f60cb
declare -xr CLI_LANG_CC=$(echo ${CLI_LANG_LC} | cut -d'_' -f2)
Alain Reguera Delgado 8f60cb
declare -xr CLI_BASEDIR="${TCAR_WORKDIR}/${TCAR_BASHSCRIPTS}"
Alain Reguera Delgado 8f60cb
declare -xr CLI_FUNCDIR="${CLI_BASEDIR}/Functions"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
# Initialize internationalization through GNU gettext.
Alain Reguera Delgado 8f60cb
. gettext.sh
Alain Reguera Delgado 8f60cb
declare -xr TEXTDOMAIN=${CLI_NAME}.sh
Alain Reguera Delgado 8f60cb
declare -xr TEXTDOMAINDIR=${TCAR_WORKDIR}/Locales/${TCAR_BASHSCRIPTS}
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
# Initialize absolute path to temporal directory.
Alain Reguera Delgado 8f60cb
declare -xr TMPDIR="$(mktemp -p /tmp -d ${CLI_NAME}.sh-XXXXXX)"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
# Initialize command-line interface.
Alain Reguera Delgado 8f60cb
if [[ -x ${CLI_FUNCDIR}/Commons/cli.sh ]];then
Alain Reguera Delgado 8f60cb
    . ${CLI_FUNCDIR}/Commons/cli.sh; export -f 'cli'; cli "$@"
Alain Reguera Delgado 8f60cb
fi