:

## begin shared

PATH=/bin:/usr/bin:/sbin:/usr/sbin:/etc:$PATH
export PATH
unset SCOMPAT

XACCELHOME=
XARCH=
XLIB=/usr/lib/X11
XBIN=/usr/bin/X11
XACCELVER="6.0"

implementation="`uname -s`"
release="`uname -r`"

case "$implementation" in
"SunOS" )
	XARCH=SOLARIS
	XLIB=/usr/openwin/lib
	XBIN=/usr/openwin/bin
	;;

"Linux" )
	XARCH=LINUX
	XLIB=/usr/X11R6/lib/X11
	XBIN=/usr/X11R6/bin
	;;

"FreeBSD" )
	XARCH=FreeBSD
	XLIB=/usr/X11R6/lib/X11
	XBIN=/usr/X11R6/bin
	;;

"NetBSD" )
	XARCH=NetBSD
	XLIB=/usr/X11R6/lib/X11
	XBIN=/usr/X11R6/bin
	;;

"BSD/OS" )
	XARCH=BSDI
	XLIB=/usr/X11R6/lib/X11
	XBIN=/usr/X11R6/bin
	;;

"BSD/386" )
	XARCH=BSDI
	XLIB=/usr/X11/lib/X11
	XBIN=/usr/X11/bin
	;;

"LynxOS" )
	XARCH=LynxOS
	;;

"AIX" )
	XARCH=AIX
	;;

*)
	case "$release" in
        "5" )
                XARCH=UnixWare
                XLIB=/usr/X/lib/X11
                XBIN=/usr/X/bin
                ;;

	"4.2" | "4.2MP" )
		XARCH=UnixWare
		XLIB=/usr/X/lib
		XBIN=/usr/X/bin
		;;

	"3.2" )
		if [ -f /etc/perms/rts ]
		then	
		        XARCH=SCO
		else
		        XARCH=ISC
		fi
		;;
	esac
	;;
esac

if [ "x$XARCH" = "x" ]
then
	echo "Unknown Architecture ($implementation $release)"
	exit 1
fi

XACCELHOME=$XLIB/AcceleratedX

export XACCELHOME XARCH XBIN XLIB

## end shared

PKGINST=${PKGINST:-accelx}
EXITCODE=0

INSTPATH=`dirname $0`

echo "## Processing $XARCH version (build $PSTAMP)."

PATH=/bin:/usr/bin:/sbin:/usr/sbin:/etc:$PATH

##
## Execute XOS dependent install script first, and then the XARCH dependent
## one. Those will install device drivers and similar things.
##
if [ -f $XACCELHOME/etc/install/Install.sh ]
then
	cd $XACCELHOME/etc/install
	/bin/sh ./Install.sh
	rv=$?
fi

XOS="$XARCH"

if [ -h $XBIN/X ]
then
	cd $XBIN
	XSERVER=`/bin/ls -l $XBIN/X | awk '{ print $11 }'`
	XSRVDIR=`dirname $XSERVER`
	if [ ! -z "$XSRVDIR" -a "$XSRVDIR" != "$XBIN" -a "$XSRVDIR" != "." ]
	then
		echo "## Linking $XBIN/Xaccel to $XSERVER."
		mkdir -p $XSRVDIR 2>/dev/null
		/bin/rm -f $XSERVER 2>/dev/null
		ln -s $XBIN/Xaccel $XSERVER
	else
		if [ -x $XBIN/X -a ! -x $XBIN/X.$XOS ]
		then
			echo "## Saving $XBIN/X to $XBIN/X.$XOS."
			/bin/mv $XBIN/X $XBIN/X.$XOS
		fi

		echo "## Linking $XBIN/Xaccel to $XBIN/X."
		/bin/rm -f $XBIN/X 2>/dev/null
		ln -s $XBIN/Xaccel $XBIN/X
	fi
else
	if [ -x $XBIN/X -a ! -x $XBIN/X.$XOS ]
	then
		echo "## Saving $XBIN/X to $XBIN/X.$XOS."
		/bin/mv $XBIN/X $XBIN/X.$XOS
	fi

	echo "## Linking $XBIN/Xaccel to $XBIN/X."
	/bin/rm -f $XBIN/X 2>/dev/null
	ln -s $XBIN/Xaccel $XBIN/X
fi

##
## Now install the main manual page, whereever it will fit.
##

XFILES=/tmp/Xfiles

if [ -d /usr/share/man/cat1 ]
then
	if [ "$XARCH" = "BSDI" ]
	then
		cp $XACCELHOME/man/cat1/Xaccel.1 /usr/share/man/cat1/Xaccel.0
		echo "/usr/share/man/cat1/Xaccel.0 f 444 bin bin" >>$XFILES
	else
		cp $XACCELHOME/man/cat1/Xaccel.1 /usr/share/man/cat1
		echo "/usr/share/man/cat1/Xaccel.1 f 444 bin bin" >>$XFILES
	fi
fi

if [ -d /usr/flib/books/man/cat1 ]
then
	cp $XACCELHOME/man/cat1/Xaccel.1 /usr/flib/books/man/cat1/Xaccel.1
	echo "/usr/flib/books/man/cat1/Xaccel.1 f 444 bin bin" >>$XFILES
fi

if [ -d /usr/openwin/share/man ]
then
	if [ ! -d /usr/openwin/share/man/cat1 ]
	then
		mkdir /usr/openwin/share/man/cat1
	fi
	cp $XACCELHOME/man/cat1/Xaccel.1 /usr/openwin/share/man/cat1/Xaccel.1
	echo "/usr/openwin/share/man/cat1/Xaccel.1 f 444 bin bin" >>$XFILES
fi

if [ -d /usr/catman/u_man/man1 ]
then
	cp $XACCELHOME/man/cat1/Xaccel.1 /usr/catman/u_man/man1/Xaccel.1
	echo "/usr/catman/u_man/man1/Xaccel.1 f 444 bin bin" >>$XFILES
fi

if [ -d /usr/man/cat.X ]
then
	cp $XACCELHOME/man/cat1/Xaccel.1 /usr/man/cat.X/Xaccel.X
	echo "/usr/man/cat.X/Xaccel.X f 444 bin bin" >>$XFILES
fi

if [ -d /usr/man/cat1 ]
then
	cp $XACCELHOME/man/cat1/Xaccel.1 /usr/man/cat1/Xaccel.1
	echo "/usr/man/cat1/Xaccel.1 f 444 bin bin" >>$XFILES
fi

if [ -d /usr/X11R6/man/man1 ]
then
	cp $XACCELHOME/man/cat1/Xaccel.1 /usr/X11R6/man/man1/Xaccel.1
	echo "/usr/X11R6/man/man1/Xaccel.1 f 444 bin bin" >>$XFILES
fi

## now fixup Solaris's Xservers file Xsun -> X for CDE
##

if [ "$XARCH" = "SOLARIS" ]
then
	# first see if there is a /etc/dt/config/Xservers file
	#  if so, We'll need to edit it, else we'll create a new one based
	#  on /usr/dt/config/Xservers
	#  - 1/25/99 we'll also check, and update the 
	#    /usr/dt/lib/bindings/xmbind.alias for Xi Graphics, Inc.

	CDE_CONF_XS="/etc/dt/config/Xservers"
	CDE_INST_XS="/usr/dt/config/Xservers"
	TMP_XS="/tmp/cde.Xservers.$$"

	XIGVENDOR="\"Xi Graphics, Inc.\""
	XMBINDINGSFILE=/usr/dt/lib/bindings/xmbind.alias

	# if there is no CDE_INST_XS, then we won't worry about CDE
	if [ -s "$CDE_INST_XS" ]
	then	

		if [ -f "$CDE_CONF_XS" ]
		then	# it already exists, make a backup
			#  for the edit later on
			cp -f $CDE_CONF_XS ${CDE_CONF_XS}.xigsav
			cp -f $CDE_CONF_XS $TMP_XS
		else	# doesn't exist... create dir structure, add to XFILES
			mkdir /etc/dt 2>/dev/null; chmod 755 /etc/dt
			mkdir /etc/dt/config 2>/dev/null; chmod 755 /etc/dt/config
			cp -f $CDE_INST_XS $TMP_XS
			echo "$CDE_CONF_XS f 444 bin bin" >>$XFILES
		fi	

		cat $TMP_XS |sed -e 's;Xsun;X;g' >$TMP_XS.new
		# now make sure that $TMP_XS.new seems ok...
		if [ -s $TMP_XS.new ]
		then	# exists - len greater than 0
			cp -f $TMP_XS.new $CDE_CONF_XS
			chmod 444 $CDE_CONF_XS
			chown bin $CDE_CONF_XS
			chgrp bin $CDE_CONF_XS
		else
			rm -f $CDE_CONF_XS
			echo "Error modifying $TMP_XS, CDE configuration not changed."
		fi
	fi
	

	## now the motif bindings - we suggest 'sun_at'

	if [ -f "$XMBINDINGSFILE" ]
	then
		if [ ! -f "$XMBINDINGSFILE.xigsav" ]
		then	# back it up
			cp -f "$XMBINDINGSFILE" "$XMBINDINGSFILE.xigsav"
		fi

		if fgrep "$XIGVENDOR" $XMBINDINGSFILE >/dev/null 2>&1
		then
			:
		else
			echo "$XIGVENDOR\t\t\t\tsun_at" >>$XMBINDINGSFILE
		fi
	fi
fi
		

##
## Get the OS specific installtion files right
##

echo "## Updating system information."

if [ -s "$XFILES" ]
then
	cat $XFILES | installf $PKGINST - >/dev/null 2>&1
	installf -f $PKGINST
	#	/bin/rm -f /tmp/??accelx $INSTPATH/decode.* >/dev/null 2>&1 &
fi

##
## Now, tell user about the Xsiteinfo configuration.
##
##

if [ -x /usr/bin/mail ]
then
    MAILPROGRAM=/usr/bin/mail
elif [ -x /bin/mail ]
then
    MAILPROGRAM=/bin/mail
else
    MAILPROGRAM=mail
fi

MAILTARGET=`grep 'BugReportEmail' $XACCELHOME/etc/Xsiteinfo`
MESSAGE=/tmp/$$message
cat >$MESSAGE <<EOF
Accelerated-X $XACCELVER has been successfully been installed on your
machine. The original X-Server (if present) has been saved to
$XBIN/X.$XOS.

By default Accelerated-X is configured for a standard VGA running
at 640x480. To configure the X-Server for your specific graphics
hardware, switch to text mode (i.e. disable the graphics login)
and run $XBIN/Xsetup.

For late documentation updates, please refer the README file in
$XACCELHOME/etc.

*** IMPORTANT NOTICE ***

	If the Accelerated-X Server fails, it will attempt
	to write a stack-trace and mail it.  The email address
	is currently set to:

		$MAILTARGET

	You may change this by editing 'BugReportEmail' in the
	file \$XACCELHOME/etc/Xsiteinfo .  We like reports to
	be sent to 'bugs@xig.com'.

EOF

echo "Subject: Installation of Accelerated-X $XACCELVER, $XARCH version" | \
cat - $MESSAGE | $MAILPROGRAM root >/dev/null 2>&1
cat $MESSAGE
rm $MESSAGE 2>&1 >/dev/null

XSETUP="$XBIN/Xsetup"

if [ "$XARCH" != "SOLARIS" ]
then
	$XSETUP
	rv=$?

	## see if there was an error...
	if [ $rv -ne 0 -a $rv -ne 1 ]
	then	# some error
		cat -<<EOF

Xsetup exited in error with status $rv.  Please run $XSETUP 
manually as root to properly license and configure the Accelerated-X X
server.  If you have problems running Xsetup, please contact Xi
Graphics technical support.

EOF

		echo "Press RETURN to continue."
		read junk
	fi

else
	cat -<<EOF

NOTICE:
After installation is complete, please run $XSETUP 
manually as root to properly license and configure the Accelerated-X X
server.  If you have problems running Xsetup, please contact Xi
Graphics technical support.

EOF


fi

exit $EXITCODE





