#!/bin/bash
#
# IBM Omni driver
# Copyright (c) International Business Machines Corp., 2000
#
# This library is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# This library 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#

# Set up our variables
DO_INSTALL=n
DO_COMPILE=n
DO_TEST=n
ARGS="--install --compile --test"

# Loop through all our arguments and set the corresponding variable
until [ -z "$1" ]
do
	case "$1" in
	--install)
		DO_INSTALL=y
	;;
	--compile)
		DO_COMPILE=y
	;;
	--test)
		DO_TEST=y
	;;
	*)
		echo "Error: Argument not understood '$1'.  Please use one of '${ARGS}'"
		exit 1
	;;
	esac

	shift
done

if [ ${DO_INSTALL} = "n" -a ${DO_COMPILE} = "n" -a ${DO_TEST} = "n" ]; then
	echo "No argument was set.  Please set one of '${ARGS}'"
	exit 1
fi

if [ ${DO_INSTALL} = "y" ]; then
	# Install Omni's foomatic XML files
	find /usr/share/foomatic/db/source/ -name \*[Oo]mni\* -exec rm {} \;

	if [ ! -d /home/Omni/new/Foomatic/foomatic-db/db/source/ ]; then
		if [ ! make generateFoomaticData3 ]; then
			exit
		fi
	fi

	cp -rf /home/Omni/new/Foomatic/foomatic-db/db/source/ /usr/share/foomatic/db/
fi

if [ ${DO_COMPILE} = "y" ]; then
	# Compile the foomatic XML files into PPD files
	RESULT_FILE=`pwd`/errors1
	cd /tmp
	rm -rf ppd
	foomatic-compiledb 2>&1 | tee ${RESULT_FILE}
fi

if [ ${DO_TEST} = "y" ]; then
	# Check the results
	RESULT_FILE=`pwd`/errors2
	> ${RESULT_FILE}
	cd /tmp/ppd
	for i in *omni*
	do
		if cupstestppd ${i} > result 2>&1; then
			true
		else
			cat result
			cat result >> ${RESULT_FILE}
		fi
	done

	rm result
fi
