Blame Automation/Modules/Prepare/Scripts/prepare_updateEnvironment.sh

Alain Reguera Delgado 8f60cb
#!/bin/bash
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# prepare_updateEnvironment.sh -- This function updates the
Alain Reguera Delgado 8f60cb
# `~/.bash_profile' file to provide default configuration values to
Alain Reguera Delgado 8f60cb
# centos-art.sh script. Those values which aren't set by this function
Alain Reguera Delgado 8f60cb
# are already set in the `bash_profile.conf' template file we use as
Alain Reguera Delgado 8f60cb
# reference to create the `~/.bash_profile' file.
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
function prepare_updateEnvironment {
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Verify that centos-art.sh script is run using an absolute path.
Alain Reguera Delgado 8f60cb
    # We use this information to determine the exact working copy
Alain Reguera Delgado 8f60cb
    # location to use, later when `bash_profile' file is created.
Alain Reguera Delgado 8f60cb
    if [[ ! $0 =~ "^${HOME}/.+/${CLI_NAME}.sh$" ]];then
Alain Reguera Delgado 8f60cb
        cli_printMessage "`gettext "To set environment variables you should run centos-art.sh using its abosolute path."`" --as-error-line
Alain Reguera Delgado 8f60cb
    fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    local PROFILE=bash_profile
Alain Reguera Delgado 8f60cb
    local SOURCE=${PREPARE_CONFIG_DIR}/${PROFILE}.conf
Alain Reguera Delgado 8f60cb
    local TARGET=${HOME}/.${PROFILE}
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Determine the repository absolute path using the script absolute
Alain Reguera Delgado 8f60cb
    # path the script has been executed from. Be careful when you use
Alain Reguera Delgado 8f60cb
    # the centos-art command. It points to ~/bin directory which is
Alain Reguera Delgado 8f60cb
    # not (and must not be) the repository working copy absolute path.
Alain Reguera Delgado 8f60cb
    if [[ $TCAR_WORKDIR =~ "^${HOME}/bin" ]];then
Alain Reguera Delgado 8f60cb
        cli_printMessage "`eval_gettext "The repository working directory cannot be $HOME/bin"`" --as-error-line
Alain Reguera Delgado 8f60cb
    else
Alain Reguera Delgado 8f60cb
        local TCAR_WORKDIR=$(dirname "$0" | sed "s,/${TCAR_BASHSCRIPTS},,")
Alain Reguera Delgado 8f60cb
    fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Determine which is the brand information that will be used as
Alain Reguera Delgado 8f60cb
    # repository brand information. By default we are using `centos'
Alain Reguera Delgado 8f60cb
    # and shouldn't be change to anything else, at least if you
Alain Reguera Delgado 8f60cb
    # pretend to produce content for The CentOS Project.
Alain Reguera Delgado 8f60cb
    local TCAR_BRAND='centos'
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Print action message.
Alain Reguera Delgado 8f60cb
    cli_printMessage "${TARGET}" --as-updating-line
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Copy default configuration file to its final destination. Note
Alain Reguera Delgado 8f60cb
    # that we are not making a link here in order for different users
Alain Reguera Delgado 8f60cb
    # to be able of using different values in their own environments.
Alain Reguera Delgado 8f60cb
    cp -f $SOURCE $TARGET
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Update bash_profile file with default values.
Alain Reguera Delgado 8f60cb
    sed -i -r \
Alain Reguera Delgado 8f60cb
        -e "s,^(TCAR_WORKDIR=).*,\1${TCAR_WORKDIR}," \
Alain Reguera Delgado 8f60cb
        -e "s,^(TCAR_BRAND=).*,\1${TCAR_BRAND}," \
Alain Reguera Delgado 8f60cb
        ${TARGET}
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
}