#!/bin/sh

if [ ${II2BUILDSTAMP} -lt 1223415500 ]
then
	echo "### You need at least i-Installer 2.91 to install this package. Bailing out..." >&2
	exit 1
fi

PROGNAME=`"${II2RESOURCES}/basename" "$0"`

echo "### ${PROGNAME}: Started..."

source "${II2RESOURCES}/ii2shfuncs.sh" || \
	{ echo "### ${PROGNAME}: Cannot load ${II2RESOURCES}/ii2shfuncs.sh. Bailing out..." ; \
	  exit 1; }

ii2checksanity
ii2calledfrom

if [ -x "${II2INSTALLDIR}"/bin/gs ]
then
	FOUNDGS=`"${II2INSTALLDIR}"/bin/gs --version`
	MYGS=`cat "${II2PKGDIR}"/gs.version`
	if [ "${MYGS}" != "${FOUNDGS}" ]
	then
		INFO="There is already a ghostscript and it is version ${FOUNDGS}. Are you sure you want to overwrite?"
		ANSWER=`"${II2RESOURCES}/doalerter" -s "${II2DOSERVER}" -V -t Alert -T "Overwrite?" -I "${INFO}" -1 "Proceed" -3 "Quit"`
		if [ "${ANSWER}" == "Quit" ]
		then
			echo "### ${PROGNAME}: Aborting installation..." >&2
			exit 1
		fi
	fi
fi

ii2runphase remove

PKGBASE=`basename "${II2PKGDIR}" .ii2`
if [ "${PKGBASE}" == "ghostscript-6" ]
then
	rm -f "${II2INSTALLDIR}/.ghostscript-7"
	rm -f "${II2INSTALLDIR}/.ghostscript-7.ii2"
	rm -f "${II2INSTALLDIR}/.ghostscript-8"
	rm -f "${II2INSTALLDIR}/.ghostscript-8.ii2"
elif [ "${PKGBASE}" == "ghostscript-7" ]
then
	rm -f "${II2INSTALLDIR}/.ghostscript-6"
	rm -f "${II2INSTALLDIR}/.ghostscript-6.ii2"
	rm -f "${II2INSTALLDIR}/.ghostscript-8"
	rm -f "${II2INSTALLDIR}/.ghostscript-8.ii2"
elif [ "${PKGBASE}" == "ghostscript-8" ]
then
	rm -f "${II2INSTALLDIR}/.ghostscript-7"
	rm -f "${II2INSTALLDIR}/.ghostscript-7.ii2"
	rm -f "${II2INSTALLDIR}/.ghostscript-6"
	rm -f "${II2INSTALLDIR}/.ghostscript-6.ii2"
fi

echo "### ${PROGNAME}: Finished."

exit 0

# $Id: ghostscript-8.prepare 118 2008-10-04 09:51:34Z gctwnl $
