
#-----------------------------------------------------------------------
# Copyright (C) 2000-2001, Jean-Sebastien Morisset <jsmoriss@mvlan.net>
#-----------------------------------------------------------------------
# $Id: read_config.sh,v 1.10 2001/11/19 19:25:55 jsmoriss Exp $
#-----------------------------------------------------------------------
#  $RCSfile: read_config.sh,v $
#   $Author: jsmoriss $
# $Revision: 1.10 $
#     $Date: 2001/11/19 19:25:55 $
#   $Locker:  $ 
#     $Name:  $
#-----------------------------------------------------------------------
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by 
# the Free Software Foundation <http://www.gnu.org/copyleft/gpl.txt>.
# 
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License (LICENSE file in archive) for more details.
#
#-----------------------------------------------------------------------
# README
#-----------------------------------------------------------------------
#
# A bourne shell function used by rcf; a very secure, fast, and complete
# firewall for linux <http://jsmoriss.mvlan.net/linux/rcf.html>.
#
#-----------------------------------------------------------------------
# FUNCTION
#-----------------------------------------------------------------------

Read_Config () {
	if [ ! -s "$CONF" ]
	then
		if [ ! -r "$CONF" ]
		then
			echo "The $CONF configuration file is missing. A new one will be"
			echo "created. Please edit this file and re-run the firewall script."
		else
			echo "The $CONF configuration file is being updated."
			echo "Please edit this file and re-run the firewall script."
		fi
	
		# This is the first time we run this script (no config file yet).
		# Write a new configuration file (below) and exit immediately.
		#
		[ "$UPDATE_CONFIG" != "yes" ] && UPDATE_CONFIG="yes"
	
		# Setup initial variables for new configuration file.
		#
		Set_Default_Vars
	else
		echo "Reading $CONF Configuration..."

		# Get the configuration file version number.
		#
		CONF_VERSION="`sed -n -e 's/# Firewall v\(.*\) Config.*$/\1/p' $CONF`"

		# convert lower case variables to upper case and change dash & colon
		# characters into underscore. Variables are set in a way not to over-
		# ride existing values.
		#
		eval : `grep -v "^ *$\|^ *#" $CONF | \
			sed -n -e 's/^ *\([^ #]*\) *= *\"*\([^\\"#]*\).*$/\1=\2/;h;s/\(.*\)=.*/\1/;y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/;s/[:-]/_/g;G;s/\(.*\)\n.*=\(.*\)/\${\1=\"\2\"}/p;'`

		# If we haven't asked to update it, and the version number differs, 
		# then display a warning about the mismatch.
		#
		if [ ! "$UPDATE_CONFIG" -a "$CONF_VERSION" != "${PKG_VERSION}" ]
		then
			Sed_Cat <<EOF

Version mismatch between script and configuration file! You must execute
`Sed_Basename $0` with the --update-config parameter to fix this problem. Since all 
variables and options are backwards compatible, the script will continue.
EOF
			echo ""
			echo -n "Pausing for $ERROR_PAUSE secs..."; sleep $ERROR_PAUSE; echo ""
			echo ""
		fi

		# Only execute if the configuration file isn't of the same version
		# OR this is a development version (PROJECT_MATURITY is not "s").
		#
		[ "$CONF_VERSION" != "${PKG_VERSION}" -o "${PROJECT_MATURITY}" != "s" ] && Convert_Options
	fi
}

