#! /bin/sh

. .config.sh

> .config.inst

[ ! -d $INC_ORG ] && {
	echo FATAL : $INC_ORG does not exist
	exit -1
	}

fgrep __cplusplus $INC_ORG/stdio.h >/dev/null || \
fgrep __BEGIN_DECLS $INC_ORG/stdio.h >/dev/null || {
	echo Your $INC_ORG doesnt seam to be useable with C++
	echo -n should I fix it ?
	read KEY
	if [ $KEY = "Y" ] || [ $KEY = "y" ]
	then
		echo -n "find $INC_ORG -type f -print | " >>.config.inst
		echo "xargs $ONYX_HOME/Config/Fix.C++ " >>.config.inst
		chmod a+x Config/Fix.C++
	fi
	}

[ ! -d $INS_PATH ] && {
	echo FATAL : $INS_PATH does not exist
	exit -1
	}

[ ! -d $GSQL_HOME ] && {
	echo $GSQL_HOME does not exist
	echo -n should I fix it ?
	read KEY
	if [ $KEY = "Y" ] || [ $KEY = "y" ]
	then
		echo mkdir $GSQL_HOME >>.config.inst
		echo mkdir $GSQL_HOME/tmp >>.config.inst
		echo mkdir $GSQL_HOME/bin >>.config.inst
		echo mkdir $GSQL_HOME/spool >>.config.inst
		echo mkdir $GSQL_HOME/database >>.config.inst
	fi
	}

grep "^gsql.*$GSQL_SERV" /etc/services >/dev/null || {
	echo /etc/services doesnt seam to contain gsql-service
	echo -n should I fix it ?
	read KEY
	if [ $KEY = "Y" ] || [ $KEY = "y" ]
	then
		echo fgrep -v gsql /etc/service \>/etc/services~ >>.config.inst
		echo mv /etc/services~ /etc/service >>.config.inst
		echo echo "\"gsqld	$GSQL_SERV/tcp\"" \>\>/etc/services >>.config.inst

		echo fgrep -v gsql /etc/inetd.conf \>/etc/inetd.conf~ >>.config.inst
		echo mv /etc/inetd.conf~ /etc/inetd.conf >>.config.inst
		echo echo "\"gsql    stream  tcp     nowait  root    $INS_PATH/gsqld	gsqld\"" \>\>/etc/inetd.conf >>.config.inst
	fi
	}

[ "$USE_SHQL" != "" ] && [ ! -x "$SHQL_BIN_PATH" ] && {
	echo FATAL : $SHQL_BIN_PATH does not exist
	exit -1
	}

[ "$USE_GAWK" != "" ] && [ ! -x "$GAWK_BIN_PATH" ] && {
	echo FATAL : $GAWK_BIN_PATH does not exist
	exit -1
	}

[ "$USE_INGRES" != "" ] && [ ! -d "$INGRES_HOME" ] && {
	echo FATAL : $INGRES_HOME does not exist
	exit -1
	}

[ "$USE_INFROMIX" != "" ] && [ ! -d "$INFORMIX_HOME" ] && {
	echo FATAL : $INFORMIX_HOME does not exist
	exit -1
	}

[ $DEFAULT_ENGINE != "shql" ] && \
[ $DEFAULT_ENGINE != "gawk" ] && \
[ $DEFAULT_ENGINE != "ingres" ] && \
[ $DEFAULT_ENGINE != "informix" ] && {
	echo FATAL : invalid engine $DEFAULT_ENGINE
	exit -1
	}

if [ -s .config.inst ] 
then
	echo 
	echo Y should run 
	echo "  # sh .config.inst"
	echo as root to make the nessesary fixes
	echo
	echo 
else
	rm .config.inst
fi

exit 0
