#!/bin/sh
#
#	request: SunPC 4.1 package add request script.
#
#       Copyright (c) 1994, Sun Microsystems, Inc.  All Rights Reserved
#
#	This file is intended to run before the package add actually
#	begins. We are going to check for existing instances of SunPC
#	packages and fail if they are. All instances of SunPC need to
#	be removed so that we can assure all patches are removed.
#
#	Also, before we inform user to remove the packages, we copy the
#	contents of /opt/SUNWsunpc/dos to /usr/tmp. postinstall will look
#	and see if this directory exists and copy it back into the 4.1 
#	package install area. This allows 4.0 and 4.0.1 users who are
#	running with DOS 4.0.1 to boot normally without loosing their
#	dos external command area.
#
# set -x

# The save area used to copy out the DOS4 files from a previous SunPC 4.X package.
DOS_SAVE_AREA="/usr/tmp/dos_save"

# The amount of space required, 1.2 Megabytea
TMPREQD=1200

/usr/bin/pkginfo -q SUNWsunpc
PKGSTATUS=$?

if [ "$PKGSTATUS" -eq "0" ]
then

	echo " "

	#
	# Rerun pkginfo to get the installation base directory.
	#

	PKGTEXT=`/usr/bin/pkginfo -l SUNWsunpc`
	OLDBASEDIR=`/usr/bin/echo "$PKGTEXT" | /usr/bin/grep BASEDIR | /bin/awk -F" " '{ print $2 }'`
	OLDBASEVER=`/usr/bin/echo "$PKGTEXT" | /usr/bin/grep VERSION | /bin/awk -F" " '{ print $2 }'`

	#
	# Now Save the users dos 4.0.1 area.
	#

	if [ $OLDBASEVER = "4.1" ]
	then

		if [ ! -d $DOS_SAVE_AREA ]
		then

			# Check for minimum amount of space in /usr/tmp.
			DF=`/bin/df -k /usr/tmp`
			TMPAVAIL=`echo $DF | /bin/awk -F" " '{ print $(NF - 2) }'`
			if [ "$TMPAVAIL" -lt "$TMPREQD" ]
			then
				echo "  There is not enough space in directory /usr/tmp to save your DOS 4.1 files."
				echo "  "$TMPAVAIL" Kbytes are available, "$TMPREQD" Kbytes are required."
				exit 1
			fi

			echo "  Running: /usr/bin/cp -p -r $OLDBASEDIR/SUNWsunpc/dos6 $DOS_SAVE_AREA"
			mkdir $DOS_SAVE_AREA
			/usr/bin/cp -p -r $OLDBASEDIR/SUNWsunpc/dos6 $DOS_SAVE_AREA
			/usr/bin/cp -p -r $OLDBASEDIR/SUNWsunpc/defaults $DOS_SAVE_AREA
			echo "  DOS6.2.2 area saved"
			echo " "
		fi

	fi

	#
	# Last step -- tell user that the SUNWsunpc package needs to be removed.
	#
	echo "  --------------------------------------------------------------"
	echo "  All instances of existing SunPC package(s) need to be removed."
	echo "  As root, run:"
	echo " "
	echo "                   /usr/sbin/pkgrm SUNWsunpc.*"
	echo " "
	echo "  Please make sure that you specify 'SUNWsunpc.*'"
	echo "  --------------------------------------------------------------"
	echo "  "

fi

exit 0

