#



slow_quit(){
	echo "Just in case you have a slow download link, this script will"
	echo "sleep for 60 seconds, to give you a chance to make "
	echo "a copy of any downloaded files in /var/run before they are"
	echo "auto-deleted"
	echo "For extra time, suspend (^Z) this script"
	echo ""
	sleep 60
	echo ""
	echo "Now quitting with failure status"
	exit 1
}


# I dont know where this gets set, but I think it does in some situations. Otherwise, 
#  fall back to PKG_INSTALL_ROOT
if [ "$PKG_ROOT_DIR" = "" ] ; then
	PKG_ROOT_DIR="$PKG_INSTALL_ROOT"
fi
# and just in case, be reaaally paranoid.
if [ "$PKG_ROOT_DIR" = "" ] ; then
	PKG_ROOT_DIR="/"
fi


# first, check for required libm patch for x86.
# Check for others further down

if [ `uname -p` = 'i386' ] ; then


	case `uname -r` in
		5.8)
		PATCHNUM=112757
		;;
		5.9)
		PATCHNUM=111728
		# technically, this should check for "at least rev 03",
		# but I dont want to deal with that level of complication
		;;
	esac


	if [ "$PATCHNUM" = "" ] ; then
		exit 0
	fi

	# MUST HAVE this patch, or we wont be able to run.
	pkgparam -R $PKG_ROOT_DIR -v SUNWlibms | grep $PATCHNUM > /dev/null

	if [ $? -ne 0 ] ; then
		echo ""
		echo ""
		echo ERROR: you must install patch $PATCHNUM
		echo '(A patch for /usr/lib/libm.so)'
		echo Many CSW packages depend on libm.so, which must be
		echo patched, or it will not link together with our packages
		echo ""
	
		slow_quit
	fi

fi   #  END of i386 specific section



# Solaris 8 specifically needs a pkgadd patch
case `uname -r` in
	5.8)
	if [ `uname -p` = 'sparc' ] ; then
		PATCHNUM=110934
	else
		PATCHNUM=110935
	fi

	PATCHREV=13
	;;
	*)

	# we're fine. just quit cleanly
	exit 0
	;;
esac

patchid=`pkgparam -R $PKG_ROOT_DIR -v SUNWcsu | grep PATCH_INFO_${PATCHNUM}|nawk -F= '{print $1}'`
patchid=`echo $patchid  | fmt -1 |sort | tail -1`
if [ "$patchid" = "" ] ; then
	echo "Cannot continue. You need patch $PATCHNUM installed"
	slow_quit
fi

patchrev=`echo $patchid | nawk -F- '{print $2}'`


if [ "$patchrev" -lt "$PATCHREV" ] ; then
	echo "Cannot continue. You need a more recent version of "
	echo "patch $PATCHNUM installed"
	slow_quit
fi


exit 0


