:
#
#	postinstall - package Accton's SmartEnabler driver postinstall script
#
#	Assume driver object file and related ID such as Master, System, and 
#	Node file is copied in the /tmp/lsen.  Will only allow driver to be 
#	installed on SVR4.2 system for now
#
#	Copyrighted (c) 1995-1995 Accton Technology Corp. 
#	All rights reserved.
#

NAME=lsen

NODES="lsen"

FAILED=1	# failed error
OK=0		# success

TMP=/tmp/${NAME}.err
ERROR1=" Errors have been written to the file $TMP."

CONFDIF=/etc/conf
CONFBIN=${CONFDIF}/bin
CONFMDEVICE=${CONFDIF}/mdevice.d
CONFSDEVICE=${CONFDIF}/sdevice.d
PACK=${CONFDIF}/pack.d
USRBIN=/usr/bin

NOTOOLS="ERROR: The Installable Driver feature has been removed.
The ${NAME} cannot be installed."

PARTINS="WARNING: Accton SmartEnabler Driver has been partialy installed. 
It is unkown how completely it is installed.  You may continue and 
overlay it with the ${NAME}."

BASE1="ERROR: The ${NAME} is not compatible with this release of the 
UNIX System V operating system and can not be used with this system." 
 

# remove all existing error file

rm -f $TMP >/dev/null 2>&1 


# check for system tools

if [ -x ${CONFBIN}/idcheck -a -x ${CONFBIN}/idbuild -a -x ${CONFBIN}/idinstall ]
then
	:
else
	message ${NOTOOLS}
	exit $FAILED
fi

# verify installation on UNIX System V/386 Release 4

OSVER=`uname -a | cut -d " " -f3 `

case ${OSVER} in

	3.*) 	echo "UNIX System V/386 Release $OSVER"
		;;
	4.*) 	echo "UNIXWARE System V/386 Release $OSVER"
		;;
	*) 	message ${BASE1} ;
		exit ${FAILED} ;;
esac


${CONFBIN}/idcheck -p $NAME > /dev/null 2>&1
RETTP=$?

#
# if RETTP != 0, then an "lsen" driver exists on the system
#

WARN=""

if [ $RETTP != 0 ]
then
	message -c ${PARTINS}
	if [ "$?" != "0" ]
	then
		exit ${FAILED}
	fi

	${CONFBIN}/idinstall -d $NAME	# remove the driver for the system

fi

# we need to create the Master, System, and Node file now

cd /tmp/${NAME}

rm -rf Master System Node

echo "${NAME}\tI\ticSfH\t${NAME}\t0\t0\t1\t2\t-1" > Master

echo "${NAME}\tY\t1\t0\t0\t0\t0x240\t0x240\t0\t0" > System

>Node

nid=""
minor=0

for nid in ${NODES}
do
	echo  "${NAME}\t${nid}\tc\t${minor}" >> Node
	minor=`expr $minor + 1`
done

#
#	Test for operating system and version
#
osver=`uname -v`

case $osver in
1.*)	
	NE2K="ne2k"	
	;;
2.*)
	NE2K="NE2000"
	;;
*)	echo "
Release $osver for this operating system is not supported by this driver."
  	exit 1
	;;
esac

# Build the Space.c file
#

# check for NE2K driver installed or not 

${CONFBIN}/idcheck -p $NE2K > /dev/null 2>&1
RETTP=$?

if [ $RETTP -eq 0 ]
then
	echo "WARNING: Could not find NE2K network driver"
	exit ${FAILED}
fi

# NE2K driver is installed now check for configuration and extract 
# .. I/O address and IRQ
#
#case $osver in
#1.*)	
#	ne2ksdev=`sed -n '4,4p' $CONFSDEVICE/$NE2K`		# first dev
#	;;
#2.*)
#	ne2ksdev=`sed -n '9,9p' $CONFSDEVICE/$NE2K`		# first dev
#	;;
#*)	echo "
#Release $osver for this operating system is not supported by this driver."
#  	exit 1
#	;;
#esac

ne2ksdev=`sed -n '/Y	/p' $CONFSDEVICE/$NE2K`		# first dev
set $ne2ksdev

if [ $1 = "$NE2K" ] 
then
	lirq=$6
	liobase=$7
else

	echo ${NE2KNOTCONFIG}
	exit ${FAILED} 

#	ne2ksdev=`sed -n '5,5p' $CONFSDEVICE/$NE2K`		# second dev
#	set $ne2ksdev
#
#	if [ $2 = "Y" ]
#	then
#		lirq=$6
#		liobase=$7
#	else
#		ne2ksdev=`sed -n '6,6p' $CONFSDEVICE/$NE2K`		
#		set $ne2ksdev
#
#		if [ $2 = "Y" ]
#		then
#			lirq=$6
#			liobase=$7
#		else
#			ne2ksdev=`sed -n '7,7p' $CONFSDEVICE/$NE2K`		
#			set $ne2ksdev
#
#			if [ $2 = "Y" ]
#			then
#				lirq=$6
#				liobase=$7
#			else
#				echo ${NE2KNOTCONFIG}
#				exit ${FAILED} 
#
#			fi
#
#		fi
#
#	fi
#

fi

echo "int miobase = 0x2e8 ;
int mirq = 5 ;
int cor_val = 0x23 ;

int liobase = 0x${liobase} ;
int lirq = ${lirq} ;
" > Space.c


# add the driver into the system now

${CONFBIN}/idinstall -a $NAME 2>>$TMP

# Now put the driver upon top of every one by puting the init order as 
# .. big number.

sed '/lsen/s/0/99/' ${CONFMDEVICE}/${NAME} > ${NAME}.tmp
mv ${NAME}.tmp ${CONFMDEVICE}/${NAME}

if [ $? != 0 ]
then 
	message "The installation connot be completed due to an error in the
	driver installation.  $ERROR1 Please try the installation again.
	If the error occurs again, contact Accton Technology Corp. for help."

	exit ${FAILED}
fi

# at this poin every thing is OK so we just build the new UNIX now

# ${CONFBIN}/idbuild -B 2>>$TMP
${CONFBIN}/idbuild 2>>$TMP

if [ $? != 0 ]
then
	message "The installation cannot be completed due to the error 
	occurs during IDBUILD command."

	exit ${FAILED}
fi

# exit ${OK}
exit 0
