Blame Scripts/Bash/centos-art.sh

878a2b
#!/bin/bash
878a2b
#
878a2b
# centos-art.sh -- The CentOS Artwork Repository automation tool.
878a2b
#
e6bbbf
# Copyright (C) 2009-2013 The CentOS Project
878a2b
#
878a2b
# This program is free software; you can redistribute it and/or modify
878a2b
# it under the terms of the GNU General Public License as published by
03486a
# the Free Software Foundation; either version 2 of the License, or (at
03486a
# your option) any later version.
878a2b
#
878a2b
# This program is distributed in the hope that it will be useful, but
878a2b
# WITHOUT ANY WARRANTY; without even the implied warranty of
878a2b
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
878a2b
# General Public License for more details.
878a2b
#
878a2b
# You should have received a copy of the GNU General Public License
878a2b
# along with this program; if not, write to the Free Software
878a2b
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
878a2b
#
878a2b
# ----------------------------------------------------------------------
878a2b
# $Id$
878a2b
# ----------------------------------------------------------------------
878a2b
3b9515
# Initialize relative path (from repository first directory level on)
3b9515
# used to store bash scripts.
3b9515
TCAR_BASHSCRIPTS='Scripts/Bash'
3b9515
3b9515
# Verify the working copy absolute path using the command path. It is
3b9515
# not possible to consider relative paths here because we are using a
3b9515
# symbolic link to create the connection between the centos-art.sh
3b9515
# script and the centos-art command. The link location is stored
3b9515
# inside ~/bin directory which is outside the repository directory
3b9515
# structure. So we cannot use the command path as reference to define
3b9515
# the repository working directory each time we run the command.
3b9515
# Instead, in order to get the correct working directory path, it is
3b9515
# required to finish the script execution when the absolute path
3b9515
# points to the ~/bin directory and print an error message explaining
3b9515
# the issue. This message cannot be translated to other languages
3b9515
# because the TEXTDOMAINDIR variable hasn't been defined yet (it
3b9515
# requires the working copy directory path to be defined first).
3b9515
if [[ ! $TCAR_WORKDIR ]] || [[ $TCAR_WORKDIR == '' ]] ;then
3b9515
3b9515
    if [[ $0 =~ "^${HOME}/bin" ]];then
3b9515
        echo "To run centos-art correctly, you need to prepare your workstation first."
3b9515
        exit 1
3b9515
    fi
3b9515
d97f4e
fi
d97f4e
123ee8
# Initialize absolute path to the working copy. Take care that, in
123ee8
# some cases, you might execute centos-art.sh script from a path
123ee8
# different to that set in TCAR_WORKDIR variable inside your
123ee8
# ~/.bash_profile (e.g., you are changing your working copy from one
123ee8
# location to another). In these cases, the last path must be used as
123ee8
# reference whenever it doesn't point to user's bin directory. This is
123ee8
# another reason to provide the centos-art.sh absolute path when you
123ee8
# execute the prepare function.
123ee8
if [[ ! $TCAR_WORKDIR =~ "^$(dirname $0)" ]] \
123ee8
    && [[ ! $(dirname $0) =~ "^${HOME}/bin" ]];then
123ee8
    TCAR_WORKDIR=$(dirname $0 | sed "s,/${TCAR_BASHSCRIPTS},,")
123ee8
fi
e6bbbf
3b9515
# Redefine the working copy absolute path considering the (Subversion)
3b9515
# previous directory structures used in the repository.
819c26
if [[ -d ${TCAR_WORKDIR}/trunk ]];then
819c26
    TCAR_WORKDIR=${TCAR_WORKDIR}/trunk
819c26
fi
819c26
2ab0b2
# Initialize repository brand information.
123ee8
if [[ ! $TCAR_BRAND ]] || [[ $TCAR_BRAND == "" ]];then
2ab0b2
    TCAR_BRAND='centos'
2ab0b2
fi
2ab0b2
218057
# Initialize script-specific configuration variables.
2ab0b2
declare -xr CLI_NAME="${TCAR_BRAND}-art"
3b9515
declare -xr CLI_VERSION='0.4'
218057
declare -xr CLI_LANG_LC=$(echo ${LANG} | cut -d'.' -f1)
218057
declare -xr CLI_LANG_LL=$(echo ${CLI_LANG_LC} | cut -d'_' -f1)
218057
declare -xr CLI_LANG_CC=$(echo ${CLI_LANG_LC} | cut -d'_' -f2)
3b9515
declare -xr CLI_BASEDIR="${TCAR_WORKDIR}/${TCAR_BASHSCRIPTS}"
2a2d9c
declare -xr CLI_FUNCDIR="${CLI_BASEDIR}/Functions"
878a2b
819c26
# Initialize internationalization through GNU gettext.
8f84ba
. gettext.sh
1d56ce
declare -xr TEXTDOMAIN=${CLI_NAME}.sh
3b9515
declare -xr TEXTDOMAINDIR=${TCAR_WORKDIR}/Locales/${TCAR_BASHSCRIPTS}
8f84ba
218057
# Initialize absolute path to temporal directory.
218057
declare -xr TMPDIR="$(mktemp -p /tmp -d ${CLI_NAME}.sh-XXXXXX)"
218057
878a2b
# Initialize command-line interface.
8d8a61
if [[ -x ${CLI_FUNCDIR}/Commons/cli.sh ]];then
8d8a61
    . ${CLI_FUNCDIR}/Commons/cli.sh; export -f 'cli'; cli "$@"
f97c6b
fi