#!/bin/sh

test -f /tmp/_StorADE_DEBUG_ && set -x

PKGINST=118222

METHOD=patchrm
STORADE="Storage_A.D.E_2.4"
WEBCONS="Java Web Console"
HIGHLIGHT="----------------------------------------------------------------------"

# Skip Java Web Console start/restart when this file exists. The master install
# or uninstall script will handle the start of the web console.
SKIP_WEB_START=/tmp/.StorADE_Skip_Web_Start

reconfigWebConsole () {
   SMCBASEDIR=`pkgparam SUNWmcon BASEDIR 2>/dev/null`
   if [ $? -eq 0 ] ; then
      test "$SMCBASEDIR" = "/" && SMCBASEDIR=""

      echo ""
      echo "$PKGINST: Checking the status of the $WEBCONS."
      state=`$SMCBASEDIR/usr/sadm/bin/smcwebserver status -p | grep running | cut -d"=" -f2`
      if [ "$state" = "yes" ]; then
         echo ""
         echo "$PKGINST: Stopping the $WEBCONS before reregistration."
         $SMCBASEDIR/usr/sadm/bin/smcwebserver stop
         status=$?
         if [ $status -ne 0 ] ; then
            echo $HIGHLIGHT
            echo "$PKGINST Warning: '$SMCBASEDIR/usr/sadm/bin/smcwebserver stop' exited with"
            echo "'$status' status. Reregistration of $PKGINST will attempt to continue."
            echo $HIGHLIGHT
         fi
      elif [ "$state" = "no" ]; then
         continue
      else
         echo $HIGHLIGHT
         echo "$PKGINST Warning: An unrecognized status of '$state' was returned from"
         echo "'$SMCBASEDIR/usr/sadm/bin/smcwebserver status -p'. Reregistration of $PKGINST"
         echo "will attempt to continue."
         echo $HIGHLIGHT
      fi

      echo ""
      echo "$PKGINST: Unregistering $STORADE from the $WEBCONS."
      $SMCBASEDIR/usr/sadm/bin/smreg remove -a $STORADE
      status=$?
      if [ $status -ne 0 ] ; then
         echo $HIGHLIGHT
         echo "$PKGINST Warning: Unregistration from the $WEBCONS failed."
         echo "'$SMCBASEDIR/usr/sadm/bin/smreg remove -a $STORADE' exited with '$status'"
         echo "status. Please correct this problem and rerun any of the following"
         echo "commands that fail manually once the $PKGINST $METHOD completes."
         echo $HIGHLIGHT
      fi

      echo ""
      echo "$PKGINST: Reregistering $STORADE with the $WEBCONS."
      $SMCBASEDIR/usr/sadm/bin/smreg add -a /usr/share/webconsole/storade
      status=$?
      if [ $status -ne 0 ] ; then
         echo $HIGHLIGHT
         echo "$PKGINST Warning: Reregistration with the $WEBCONS failed."
         echo "'$SMCBASEDIR/usr/sadm/bin/smreg add -a /usr/share/webconsole/storade' exited"
         echo "with '$status' status. Please correct this problem and rerun this"
         echo "command manually once the $PKGINST $METHOD completes."
         echo $HIGHLIGHT
      fi

      test -f $SKIP_WEB_START && return

      if [ "$state" = yes ] ; then
         echo ""
         echo "$PKGINST: Starting the $WEBCONS after reregistration."
        /usr/bin/env LC_ALL=C $SMCBASEDIR/usr/sadm/bin/smcwebserver start
         status=$?
         if [ $status -ne 0 ] ; then
            echo $HIGHLIGHT
            echo "$PKGINST Warning: '/usr/bin/env LC_ALL=C $SMCBASEDIR/usr/sadm/bin/smcwebserver start'"
            echo "exited with '$status' status. Please correct this problem and rerun"
            echo "this command manually once the $PKGINST $METHOD completes. You will"
            echo "not be able to access the $WEBCONS until this has been done."
            echo $HIGHLIGHT
         fi
      else
         echo $HIGHLIGHT
         echo "$PKGINST Warning: The $WEBCONS was not running at $METHOD"
         echo "start so it will not be automatically started. Run the command"
         echo "'/usr/bin/env LC_ALL=C $SMCBASEDIR/usr/sadm/bin/smcwebserver start' manually"
         echo "to start it once the $PKGINST $METHOD is complete. You will not be"
         echo "able to access the $WEBCONS until this has been done."
         echo $HIGHLIGHT
      fi
   fi
}

reconfigWebConsole
exit
