#!/bin/sh
#
# Copyright 1990,91,92,93,94  by Thomas Roell, Germany.
# Copyright 1993,94           by X Inside Inc, USA.
# All Rights Reserved.
#

## begin shared

unset SCOMPAT

XACCELHOME=
XARCH=
XOS=
XLIB=/usr/lib/X11
XBIN=/usr/bin/X11
XACCELEXEC=Xaccel

if [ -x /bin/uname ]
then
	implementation="`/bin/uname -s`"
	release="`/bin/uname -r`"
else
	implementation="`/usr/bin/uname -s`"
	release="`/usr/bin/uname -r`"
fi

case "$implementation" in
"SINIX-D" | "SINIX-Z" )
	XARCH=SVR4
	XOS=SINIX
	;;

"SunOS" )
	XARCH=SVR4
	XOS=SOLARIS
	XLIB=/usr/openwin/lib
	XBIN=/usr/openwin/bin
	;;

"Linux" )
	XARCH=LINUX
	XOS=LINUX
	if [ -f /lib/libc.so.5 ]
	then
	   XACCELEXEC=Xaccel-elf
	else
	   XACCELEXEC=Xaccel-aout
	fi
	;;

"FreeBSD" )
	XARCH=FreeBSD
	XOS=FreeBSD
	;;

"NetBSD" )
	XARCH=NetBSD
	XOS=NetBSD
	;;

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

*)
	case "$release" in
	"4.2" | "4.2MP" )
		XARCH=SVR4
		XOS=SVR4.2
		XLIB=/usr/X/lib
		XBIN=/usr/X/bin
		;;

	"4.0" | "4.1" )
		XARCH=SVR4
		XOS=SVR4
		;;

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

if [ ! -d $XBIN -o ! -d $XLIB ]
then
	if [ -d /usr/X11R6/lib/X11 ]
	then
		XLIB=/usr/X11R6/lib/X11
		XBIN=/usr/X11R6/bin
	elif [ -d /usr/X11R5/lib/X11 ]
	then
		XLIB=/usr/X11R5/lib/X11
		XBIN=/usr/X11R5/bin
	elif [ -d /usr/X386/lib/X11 ]
	then
		XLIB=/usr/X386/lib/X11
		XBIN=/usr/X386/bin
	else
		echo "Unkown Directory Structure"
		exit -1
	fi
fi

if [ "x$XARCH" = "$XARCH" ]
then
	echo "Unkown Architecture"
	exit -1
fi

XACCELHOME=$XLIB/AcceleratedX

export XACCELHOME XACCELEXEC XARCH XBIN XLIB XOS

## end shared


if [ ! -d $XACCELHOME/arch/$XARCH ]
then
	echo "Support for $XARCH not installed"
	exit -2
fi

#
# Find the right default Xaccel binary and the corresponding default
# Xaccel.ini file. If there is no /etc/Xaccel.ini and no
# $HOME/.Xaccel.ini, then call Xsetup.
#

if [ -r $XACCELHOME/arch/$XARCH/$XOS/Xaccel.ini ]
then
	XACCELINI=arch/$XARCH/$XOS/Xaccel.ini
else
	XACCELINI=arch/$XARCH/Xaccel.ini
fi

if [ -x $XACCELHOME/arch/$XARCH/$XACCELEXEC ]
then
	XACCELBIN=$XACCELHOME/arch/$XARCH/$XACCELEXEC
elif [ -x $XACCELHOME/arch/$XARCH/$XACCELEXEC.demo ]
then
	XACCELBIN=$XACCELHOME/arch/$XARCH/$XACCELEXEC.demo
else
	echo "No Accelerated-X binary found"
	exit -1
fi

export XACCELINI XACCELBIN

if [ "`basename $0`" = "Xsetup" ]
then
	exec $XACCELBIN -setup

else
	if [ ! -r /etc/Xaccel.ini -a ! -r $HOME/.Xaccel.ini ]
	then
		$XACCELBIN -setup
	fi

	exec $XACCELBIN $*
fi