#
# postinstall
#
#	Post installation script for the SunPC installation. The main purpose
#	of this script is to check for a saved DOS 4.0.1 area. If package add
#	was run without removing the previous package, the preinstall script
#	will save the /opt/SUNWsunpc/dos directory in /usr. Its now our
#	job to restore this into the newly installed package directory so that 
#	users with a 4.0.1 environment will not be advertly affected by the DOS
#	6.22 upgrade (until they choose to upgrade).  
#
# The save area used to save DOS4 files from a previous SunPC 4.X package.
#	
#	For SunPC 4.2 the request script save the whole DOS area of
#	previous version SunPC. Now this script restore the DOS.
DOS4_SAVE_AREA="/usr/tmp/dos4.0.1"
DOS_SAVE_AREA="/usr/tmp/dos_save"

# The amount of space required, 10 Megabytes
TMPREQD=10000

	if [ -d $DOS4_SAVE_AREA ]
	then

		# Check for minimum amount of space in $BASEDIR/SUNWsunpc.
		DF=`/bin/df -k $BASEDIR/SUNWsunpc`
		TMPAVAIL=`echo $DF | /bin/awk -F" " '{ print $(NF - 2) }'`
		if [ "$TMPAVAIL" -lt "$TMPREQD" ]
		then
			echo "  There is not enough space in $BASEDIR/SUNWsunpc to restore the DOS 4.0.1 files."
			echo "  "$TMPAVAIL" Kbytes are available, "$TMPREQD" Kbytes are required."
			echo "  after package add completes, clear some disk space and"
			echo "  cp -r $DOS4_SAVE_AREA $BASEDIR/SUNWsunpc/dos"
			exit 0
		fi

		/usr/bin/cp -p -r $DOS4_SAVE_AREA $BASEDIR/SUNWsunpc/dos
		/usr/bin/rm -rf $DOS4_SAVE_AREA
		echo "  The DOS 4.0.1 files have been restored."
	fi

        if [ -d $DOS_SAVE_AREA ]
        then

                # Check for minimum amount of space in $BASEDIR/SUNWsunpc.
                DF=`/bin/df -k $BASEDIR/SUNWsunpc`
                TMPAVAIL=`echo $DF | /bin/awk -F" " '{ print $(NF - 2) }'`
                if [ "$TMPAVAIL" -lt "$TMPREQD" ]
                then
                        echo "  There is not enough space in $BASEDIR/SUNWsunpc
to restore the DOS files."  
                        echo "  "$TMPAVAIL" Kbytes are available, "$TMPREQD" Kbytes are required."
                        echo "  after package add completes, clear some disk space and"
                        echo "  cp -r $DOS4_SAVE_AREA $BASEDIR/SUNWsunpc/dos"
                        exit 0   
                fi
#                /usr/bin/cp -p -r $DOS_SAVE_AREA/defaults/C.6.22.sunpc3 $BASEDIR/SUNWsunpc/defaults/C.6.22.sunpc3
#		/usr/bin/cp -p -r $DOS_SAVE_AREA/defaults/6.22/dos $BASEDIR/SUNWsunpc/defaults/6.22/dos
#		/usr/bin/cp -p -r $DOS_SAVE_AREA/defaults/6.22/command.com $BASEDIR/SUNWsunpc/defaults/6.22/command.com
		/usr/bin/cp -p -r $DOS_SAVE_AREA/dos6/msdos $BASEDIR/SUNWsunpc/dos6/msdos
		/usr/bin/chgrp -fR bin $BASEDIR/SUNWsunpc/dos6/msdos
#		/usr/bin/chgrp -fR bin $BASEDIR/SUNWsunpc/defaults/6.22/dos
#		/usr/bin/chgrp -fR bin $BASEDIR/SUNWsunpc/defaults/6.22/command.com
                /usr/bin/rm -rf $DOS_SAVE_AREA
                echo "  The DOS files have been restored."
        fi
if [ -d /usr/dos_temp ]
then
                /usr/bin/rm -rf /usr/dos_temp
fi
exit 0
