#!/usr/bin/ksh
#set -x

PKGNAME="SUNWssmi"

if [ -r /etc/opt/$PKGNAME/ENV ]
then
   if [ `grep "^PATCH_LEVEL=" /etc/opt/$PKGNAME/ENV` ] && [ -z `showrev -p | grep $PKGNAME` ]
   then
      echo "This installation of $PKGNAME has been patched with an earlier"
      echo "patchrelease which is noncompatible with SUN's installpatch."
      echo "Please backout that patch with the older patchtools that came"
      echo "with the earlier patch, and then apply this patchpackage."
      exit 1
   fi
else
   echo "$PKGNAME environment file is missing. This indicates a errorcondition"
   echo "in $PKGNAME, but it won't affect the installation of this patch but"
   echo "not being able to check this file for the entry:"
   echo ""
   echo "PATCH_LEVEL=<some patch no.>"
   echo ""
   echo "Continue patching anyway (yes/no)? \c"
   ans="dummy"
   read ans

   ans=`echo $ans | tr '[a-z]' '[A-Z]'`

   if [ "$ans" != "YES" -a "$ans" != "Y" ]
   then
      echo "Patching aborted by user."
      exit 1
   else
      echo "Continuing on users behalf."
   fi
fi

if [ -z "`ps -edaf | grep [b]oks`" ]
then
   echo ""
   echo "$PKGNAME seems to be installed, but is not running."
   echo "This might be a problem if manual maintenence has been done."
   echo "Continue patching anyway (yes/no)? \c"
   ans="dummy"
   read ans

   ans=`echo $ans | tr '[a-z]' '[A-Z]'`

   if [ "$ans" != "YES" -a "$ans" != "Y" ]
   then
      echo "Patching aborted by user."
      exit 1
   else
      echo "Continuing on users behalf."
      echo "You have to restart $PKGNAME manually."
   fi
else
   echo "$PKGNAME is up and running. Proceeding with patch."
   echo "Stopping $PKGNAME (this is normal procedure)."  

   /opt/$PKGNAME/sbin/Boot -k && sleep 30
   touch /tmp/$PKGNAME_RESTART.$PPID
fi

echo "========================================================================="
echo
