#
#  (C) Copyright PTI, 1994
# This source file is the property of PTI.
# It may not be copied or distributed in any isomorphic form
# without an appropriate prior licensing arrangement with 
# PTI.
#
# Shell script to install UNIX driver
#

TMPFILE=/tmp/tmp$$
MDEVICE=/etc/conf/cf.d/mdevice
SCODRIVER=Driver.sco
ATTDRIVER=Driver.att
SCOPACK=/etc/conf/pack.d/wd0
SCOHDSPACE=/etc/conf/pack.d/hd/space.c
ATTPACK=/etc/conf/pack.d/hd


strings - /bin/pwd | grep 'SCO' > /dev/null 2>&1
if [ $? = 0 ]
then
	UNIXID=SCO
fi

strings - /bin/pwd | grep 'UNIX System V/386' > /dev/null 2>&1
if [ $? = 0 ]
then
	UNIXID="AT&T"
fi

if [ "$UNIXID" != "SCO" -a "$UNIXID" != "AT&T" ]
then
	echo "Only SCO UNIX and AT&T UNIX are supported now!\n"
	exit 1
fi

echo "\nInstalling driver on your $UNIXID unix ...\n"

while [ 1 ]
do
	echo "\nWill the controller be in TURBO or FAST mode"
	echo " (T/F)? (default=T)\c"
	read ANS
	if [ "$ANS" = "" -o "$ANS" = "T" -o "$ANS" = "t" ]
	then
		TURBOMODE=1
		break
	fi
	if [ "$ANS" = "F" -o "$ANS" = "f" ]
	then
		TURBOMODE=0
		break
	fi

done
# mdevice, just modify the SVR4.0
if [ "$UNIXID" = "AT&T" ]
then 
	sed -e '/^hd/s/[ 	]hd/	pti/g' $MDEVICE > $TMPFILE
fi
cp $TMPFILE $MDEVICE 2> /dev/null

#
# /etc/conf/pack.d/xxx/Driver.o 
# /etc/conf/pack.d/xxx/space.c
#
if [ $UNIXID = SCO ]
then
	THISDRIVER=$SCODRIVER
	THISPACK=$SCOPACK
else
	THISDRIVER=$ATTDRIVER
	THISPACK=$ATTPACK
fi
	
if [ ! -f ${THISPACK}/Driver.ptibak ]
then
	cp ${THISPACK}/Driver.o  ${THISPACK}/Driver.ptibak  2> /dev/null
fi
cp $THISDRIVER	${THISPACK}/Driver.o  2> /dev/null
echo "
	int	pti_turbo_mode = ${TURBOMODE};
" > ${THISPACK}/space.c

/etc/conf/bin/idbuild
if [ $? != 0 ]
then
	exit 1
fi
cp ptisetmode /bin  2> /dev/null
chmod 0500 /bin/ptisetmode
chown root /bin/ptisetmode
chgrp sys /bin/ptisetmode

rm $TMPFILE > /dev/null 2>&1
sync
sync
exit 0
