# Eric H. Herrin II
# University of Kentucky Mathematical Sciences
# eric@ms.uky.edu, !cbosgd!ukma!eric
#
# Install script for System V Pty driver
MODULE=pty
# put the module in the appropriate place
cp ${MODULE}.o /etc/lddrv/${MODULE}.o
# add the entry to the /etc/master file
/etc/masterupd -a char open release close read write ioctl ${MODULE}
# get the assigned device number
MODULEDEVNO=`/etc/masterupd -c ${MODULE}`
if [  ! ${MODULEDEVNO} ]
then 
	echo "${MODULEDEVNO} cannot be added to the /etc/master file"
	exit 1
fi
# NOTE!!!!!!!!!!!!!!
# To change the number of ptys, change the value in number-ptys.h.
# VVVVVVV
PTYCNT=`grep NUMBER_OF_PTYS number-ptys.h | \
sed -e "s/#define//" -e "s/NUMBER_OF_PTYS//" -e "s/ //g"`
echo "PTYCNT=$PTYCNT" > Remove
cat Remove.orig >> Remove
# make the pty device files
echo "Making pty pseudo device files"
cnt=0
for x in p q r s t u v w x y z
do
	for y in 0 1 2 3 4 5 6 7 8 9 a b c d e f
	do
		i=$x$y
		if [ $cnt -ge ${PTYCNT} ] 
		then 
			break
		fi
		/etc/mknod /dev/pty$i c ${MODULEDEVNO}\
 `expr $cnt + $PTYCNT`
		/etc/mknod /dev/tty$i c ${MODULEDEVNO} $cnt
		chown root /dev/tty$i /dev/pty$i
		chgrp root /dev/tty$i /dev/pty$i
		chmod 0666 /dev/tty$i /dev/pty$i
		cnt=`expr $cnt + 1`
	done
done

echo "Putting entry into InstDrv"
# put an entry in /etc/lddrv/InstDrv for ${MODULE}
V=`cat Version`
echo "Name=${MODULE} driver: Version ${V}" 	>> /etc/lddrv/InstDrv
echo "File=${MODULE}"     			>> /etc/lddrv/InstDrv
echo "Comment=Pseudo tty driver (ptys!!)" 	>> /etc/lddrv/InstDrv
cd /etc/lddrv
# allocate and load the module
echo "Allocating pty module with lddrv"
./lddrv -av -o ${MODULE}.o ${MODULE} > /dev/null 2>&1
if [ $? -eq 0 ]
then
	echo "Driver ${MODULE} successfully loaded"
else
	echo "Error: Driver ${MODULE} failed loading stage"
	exit 1
fi

# load the ${MODULE} at boot time
echo ${MODULE} >> /etc/lddrv/drivers

echo "Pseudo tty drivers are now installed"
exit 0
