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
#
de3499
# Copyright (C) 2009, 2010, 2011, 2012 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.
34452e
    if [[ ! $0 =~ "^/[[:alnum:]/_-]+${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
79573d
    # Determine which is the absolute path the script has been
79573d
    # executed from. This information will be used to construct the
79573d
    # working copy absolute path and will easy the procedure to follow
79573d
    # when a new absolute path should be defined for the working copy.
79573d
    local TCAR_WORKDIR=$(echo "$0" | sed -r 's!^(.+)/trunk.*!\1!')
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
}