#!/bin/sh
#
#
# Copyright 2000 Xi Graphics
#
# Install - Find installation dir/process for this OS and exec/chain 
#	install it.
#
# $XiGId: Install.toplev,v 1.6 2000/10/31 03:36:36 jon Exp $
#
#########################################################################
# set -x			# uncomment for debuging

# remove stuff that will probably only confuse things.
unset ENV
unset START	

### Off we go.  We can't be fancy since we can't assume that we're running
###  on something reasonably smart like ksh or bash.

# messages
INST_ABORT="### Installation aborted."

if [ -z "$INSTALL_PATH" ]
then
	PATH=/bin:/usr/bin:/sbin:/usr/sbin:/etc
else
	PATH="$INSTALL_PATH"
fi

CURDIR="`pwd`"		# get current location

SYSTYPE=""				# Type of OS

### Check platform - see if we have it...
# get the OS type

SYSTYPE="`uname -s`"

if [ -z "$SYSTYPE" ]
then	# Eh?
	echo "ERROR: Couldn't determine System type with 'uname -s'"
	echo "$INST_ABORT"
	
	exit 1
fi

# Check to see if this is BSD/OS, if so - rename to BSD_OS for obvious reasons.

if [ "$SYSTYPE" = 'BSD/OS' ]
then
	SYSTYPE="BSD_OS"
fi

INSTALLDIR=""

# determine install directory based on SYSTYPE - for LFB toplev only

case $SYSTYPE in
	BSD_OS)
		INSTALLDIR="bsdi"
		;;
	FreeBSD)
		INSTALLDIR="freebsd"
		;;
	SunOS)
		INSTALLDIR="solaris"
		;;
	UnixWare)
		INSTALLDIR="unixware"
		;;
	Linux)
		INSTALLDIR="linux"
		;;
	*)
		echo "### Unrecognized System Type: $SYSTYPE."
		echo "$INST_ABORT"
		exit 1
		;;
esac

# handle XiG installer OS's first
case $SYSTYPE in
        BSD_OS|FreeBSD|Linux)
	# XiG installer

		INSTALLBS="$CURDIR/$INSTALLDIR"


		if [ ! -f "$INSTALLBS/Install" ]
		then
			echo "### Cannot find install program: $INSTALLBS/Install, for OS: $SYSTYPE"
			echo "$INST_ABORT"
			exit 1
		fi

		# now fire it off...	

		cd $INSTALLBS
		exec ./Install $*

		# if we're here, there was a problem
		echo "### Could not exec $INSTALLBS/Install: status: $?"
		echo "$INST_ABORT"
		exit 1
		;;

	## now check out the others (solaris and unixware)
	SunOS|UnixWare)
		# Here, both OS's use the pkgadd facility...

		# make sure it's there...
		if [ -d $CURDIR/$INSTALLDIR/accelx ]
		then
			:
		else
			echo "## Could not find the $CURDIR/$INSTALLDIR/accelx directory,"
			echo "##  please contact Xi Graphics support."
			echo "$INST_ABORT"
			exit 1
		fi



		# first see if a version is already installed, if so
		#  remove it.

		if pkginfo accelx >/dev/null 2>&1
		then # it's already installed.
			echo "## Install has detected that 'accelx' is already installed."
			echo "##  This package will now be removed, and the new package"
			echo "##  will be installed."

			echo "pkgrm accelx"
			pkgrm accelx
		fi

		# check again to insure that removal succeeded, if not, we'll
		#  assume that pkgrm explained why.

		if pkginfo accelx >/dev/null 2>&1
		then	# it's still there
			echo "$INST_ABORT"
			exit 1
		fi

		# should be ready to install at this point.

		cd $INSTALLDIR

		# existence checked above.
		echo "pkgadd -d $CURDIR/$INSTALLDIR accelx"
		pkgadd -d $CURDIR/$INSTALLDIR accelx		
		rv=$?

		# Now run Xsetup if pkgadd succeeded

		if [ $rv -eq 0 ]
		then	# Start it
			if [ "$SYSTYPE" = "SunOS" ]
			then	# unixware's postinstall can start 
				#  interactive progs, solaris apparently
				#  cannot.
				/usr/openwin/bin/Xsetup
			fi
		fi
		;;

	*)
		# Windows95, for example ;-)
		echo "## No support for $SYSTYPE on this media."
		echo "$INST_ABORT"
		;;

esac

exit 0





