#! /bin/sh 
#

PATH="/usr/bin:/usr/sbin:${PATH}"
export PATH
EXIT=0

ARCH="`uname -p`"

DEVLINKTB=${ROOTDIR}/etc/devlink.tab

TMP=/tmp/$$

# Script to check that the system is at a quiet state and warn the installer
# about memory requirements.  
#
# Check what the run level is.  If run level is not "1" then print message.
# Message will not be displayed for diskless client configurations.

PKG_INSTALL_ROOT=$ROOTDIR
if test $PKG_INSTALL_ROOT = "/"
then
	who -r > /tmp/run$$
	awk '{if (int($3) > 1){
       		print ("\n \n")
        	print ("If possible, perform patch installation in single user mode.")
        	print ("If this can not be done, we recommend having the system in as")
        	print ("quiet a state as possible: no users logged on, no user jobs")
        	print ("running.")} }' /tmp/run$$

fi 

#
# Check if NewsPrint 2.5 is installed.  If it is, print message
# informing user that patch 102113 is required.
#

vers=`pkgparam -R $ROOTDIR SUNWsteNP VERSION 2>/dev/null`
if test $vers
then
	if test $vers = "2.5"
	then
		echo "Systems running NeWSprint 2.5 should also apply"
		echo "the NeWSprint patch 102113 if you are printing on"
		echo "a NeWSprint printer.  Patch 102113 prevents a hang"
		echo "from occurring when printing."
	fi
fi
echo
#
# rem_devlink - removes an entry from ${DEVLINKTB}
#
rem_devlink()
{
        PATTERN="$1"
        LINK="$2"
        PLINK="`echo $LINK | sed 's/[$*^|\]/\\\&/g'`"
        grep -v "^$PATTERN	$PLINK$" ${DEVLINKTB} >$TMP.devlink
        cp $TMP.devlink ${DEVLINKTB}
        rm -f $TMP.devlink
}

#
# remove devlink from Solaris 7
#
# The blank space between the [] is a space and a TAB.
# Each \ must be preceeded with two additional \\.
#
# While the devlink.tab file has a single tab character separating
# the fields, the regexp will match any amount of space/TAB whitespace
# between them in case the user has edited the file.
#
nexus1="^type=ddi_nexus;minor=initpcmcia[ 	]*pcmcia/\\\N0$"
nexus2="^type=ddi_nexus;minor=probepcmcia[ 	]*pcmcia/probe_\\\N0$"

if [ -f "$DEVLINKTB" -a `grep -c "$nexus1" "$DEVLINKTB"` != 0 ]
then
   rem_devlink 'type=ddi_nexus;minor=initpcmcia' 'pcmcia/\N0'
fi

if [ -f "$DEVLINKTB" -a `grep -c "$nexus2" "$DEVLINKTB"` != 0 ]
then
   rem_devlink 'type=ddi_nexus;minor=probepcmcia' 'pcmcia/probe_\N0'
fi

#
# Asks user is they would like to continue.  It will timeout in
# SLEEP_TIME and installation will continue if no response is given.
#

SLEEP_TIME=60
times_up()
{
   exit 0
}

trap 'times_up' ALRM
( sleep $SLEEP_TIME ; kill -ALRM $$ ) &
child_pid=$!

# Set up signal trap before reading user's response.  This command
# will trap a cntl-C that is issued by the user and abort the
# installation It will also kill the child process that was created
# by the timesup() function.  The INT symbolic name translates into
# signal 2.

abrt_install()
{
  kill -9 $child_pid
}


trap 'abrt_install; exit 1' INT

echo "Do you wish to continue this installation {yes or no} [yes]? \\c"
echo "\n(by default, installation will continue in $SLEEP_TIME seconds)"

read Response
while [ 1 ]
do
        case $Response in
                n | no | N | NO | No)
                        kill -9 $child_pid
                        exit 1 ;;
                "" | y | yes | Y | Yes | YES)
                        kill -9 $child_pid
                        exit 0 ;;
                *)  echo "yes or no please. \\c"
                        read Response ;;
        esac
done

exit ${EXIT}

