Blame Scripts/Bash/Functions/Prepare/prepare_updateEnvironment.sh

de3499
#!/bin/bash
de3499
#
de3499
# prepare_updateEnvironment.sh -- This function updates the
79573d
# `~/.bash_profile' file to provide default configuration values to
79573d
# centos-art.sh script. Those values which aren't set by this function
79573d
# are already set in the `bash_profile.conf' template file we use as
79573d
# reference to create the `~/.bash_profile' file.
de3499
#
e6bbbf
# Copyright (C) 2009-2013 The CentOS Project
de3499
#
de3499
# This program is free software; you can redistribute it and/or modify
de3499
# it under the terms of the GNU General Public License as published by
de3499
# the Free Software Foundation; either version 2 of the License, or (at
de3499
# your option) any later version.
de3499
#
de3499
# This program is distributed in the hope that it will be useful, but
de3499
# WITHOUT ANY WARRANTY; without even the implied warranty of
de3499
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
de3499
# General Public License for more details.
de3499
#
de3499
# You should have received a copy of the GNU General Public License
de3499
# along with this program; if not, write to the Free Software
de3499
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
de3499
#
de3499
# ----------------------------------------------------------------------
1da4b2
# $Id$
de3499
# ----------------------------------------------------------------------
de3499
de3499
function prepare_updateEnvironment {
de3499
34452e
    # Verify that centos-art.sh script is run using an absolute path.
34452e
    # We use this information to determine the exact working copy
34452e
    # location to use, later when `bash_profile' file is created.
3b9515
    if [[ ! $0 =~ "^${HOME}/.+/${CLI_NAME}.sh$" ]];then
34452e
        cli_printMessage "`gettext "To set environment variables you should run centos-art.sh using its abosolute path."`" --as-error-line
34452e
    fi
34452e
79573d
    local PROFILE=bash_profile
79573d
    local SOURCE=${PREPARE_CONFIG_DIR}/${PROFILE}.conf
79573d
    local TARGET=${HOME}/.${PROFILE}
79573d
3b9515
    # Determine the repository absolute path using the script absolute
3b9515
    # path the script has been executed from. Be careful when you use
3b9515
    # the centos-art command. It points to ~/bin directory which is
3b9515
    # not (and must not be) the repository working copy absolute path.
3b9515
    if [[ $TCAR_WORKDIR =~ "^${HOME}/bin" ]];then
3b9515
        cli_printMessage "`eval_gettext "The repository working directory cannot be $HOME/bin"`" --as-error-line
3b9515
    else
123ee8
        local TCAR_WORKDIR=$(dirname "$0" | sed "s,/${TCAR_BASHSCRIPTS},,")
3b9515
    fi
79573d
79573d
    # Determine which is the brand information that will be used as
79573d
    # repository brand information. By default we are using `centos'
79573d
    # and shouldn't be change to anything else, at least if you
79573d
    # pretend to produce content for The CentOS Project.
79573d
    local TCAR_BRAND='centos'
de3499
de3499
    # Print action message.
79573d
    cli_printMessage "${TARGET}" --as-updating-line
de3499
de3499
    # Copy default configuration file to its final destination. Note
de3499
    # that we are not making a link here in order for different users
de3499
    # to be able of using different values in their own environments.
de3499
    cp -f $SOURCE $TARGET
de3499
79573d
    # Update bash_profile file with default values.
79573d
    sed -i -r \
79573d
        -e "s,^(TCAR_WORKDIR=).*,\1${TCAR_WORKDIR}," \
79573d
        -e "s,^(TCAR_BRAND=).*,\1${TCAR_BRAND}," \
79573d
        ${TARGET}
e5b220
de3499
}