Blame Scripts/CentOS-Art/Functions/cli_getConfigValue.sh

94ab9a
#!/bin/bash
94ab9a
#
94ab9a
# cli_getConfigValue.sh -- This function retrives configuration values
94ab9a
# from configuration files. As arguments, the configuration file
94ab9a
# absolute path, the configuration section name, and the configuration
94ab9a
# variable name must be provided.
94ab9a
#
2fe9b7
# Copyright (C) 2009, 2010, 2011 The CentOS Project
94ab9a
#
94ab9a
# This program is free software; you can redistribute it and/or modify
94ab9a
# it under the terms of the GNU General Public License as published by
2fe9b7
# the Free Software Foundation; either version 2 of the License, or (at
2fe9b7
# your option) any later version.
94ab9a
#
94ab9a
# This program is distributed in the hope that it will be useful, but
94ab9a
# WITHOUT ANY WARRANTY; without even the implied warranty of
94ab9a
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
94ab9a
# General Public License for more details.
94ab9a
#
94ab9a
# You should have received a copy of the GNU General Public License
94ab9a
# along with this program; if not, write to the Free Software
94ab9a
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
94ab9a
#
94ab9a
# ----------------------------------------------------------------------
94ab9a
# $Id$
94ab9a
# ----------------------------------------------------------------------
94ab9a
    
94ab9a
function cli_getConfigValue {
94ab9a
94ab9a
    # Initialize absolute path to configuration file.
94ab9a
    local CONFIG_ABSPATH="$1"
94ab9a
94ab9a
    # Initialize configuration section name where the variable value
94ab9a
    # we want to to retrive is set in.
94ab9a
    local CONFIG_SECTION="$2"
94ab9a
94ab9a
    # Initialize variable name we want to retrive value from.
94ab9a
    local CONFIG_VARNAME="$3"
94ab9a
94ab9a
    # Retrive configuration lines from configuration file.
94ab9a
    local CONFIG_LINES=$(cli_getConfigLines \
94ab9a
        "$CONFIG_ABSPATH" "$CONFIG_SECTION" "$CONFIG_VARNAME")
94ab9a
94ab9a
    # Parse configuration lines to retrive the values of variable
94ab9a
    # names.
94ab9a
    local CONFIG_VARVALUE=$(echo $CONFIG_LINES \
94ab9a
        | gawk 'BEGIN { FS="=" } { print $2 }' \
94ab9a
        | sed -r 's/^"(.*)"$/\1/')
94ab9a
94ab9a
    # Output values related to variable name.
94ab9a
    echo "$CONFIG_VARVALUE"
94ab9a
94ab9a
}