LOGDIR=/var/sadm/patch/117367-02
LOG=$LOGDIR/postbackout.log

# check for root
user=`/bin/id | /usr/bin/grep root | /usr/bin/wc -l`
if [ $user -eq 0 ]; then
	msg="You must be root to execute this script."
	echo "$msg"
        exit 1
fi

/bin/mkdir -p $LOGDIR

ESM_BASE=`/usr/bin/pkgparam SUNWstm ESM_BASE`
if [ $? -ne 0 ]; then
    echo "Could not determine ESM location." | /bin/tee -a $LOG
    exit 1
fi
SM_BASE=/usr/share/webconsole
SM_ETC=/etc/opt/webconsole
US_BASE=/usr/sbin

## UI changes ##
# expand the esm.war file
JAVA_HOME=`/usr/bin/grep java.home $SM_ETC/webconsole | /bin/sed -e 's/java.home=//'`
JAR=$JAVA_HOME/bin/jar
if [ ! -x $JAR ] ; then
    if [ ! -x $JAR ] ; then
        echo "Could not find jar tool." | /bin/tee -a $LOG
        exit 1
    fi
fi
cd $SM_BASE/esm
$JAVA_HOME/bin/jar -xf esm.war >> $LOG

# copy old component files back over to smc (see tr_mgmt_bin/postinstall)
/bin/cp $ESM_BASE/sssm/util/cre/components/esm-common.jar $SM_BASE/esm/WEB-INF/lib
/bin/cp $ESM_BASE/sssm/util/cre/components/esm-jade.car $SM_BASE/esm/WEB-INF/lib/esm-jade.jar
/bin/cp $ESM_BASE/sssm/util/cre/components/services-api.jar $SM_BASE/esm/WEB-INF/lib
/bin/cp $ESM_BASE/sssm/util/cre/components/switch.jar $SM_BASE/esm/WEB-INF/lib
/bin/cp $ESM_BASE/sssm/util/cre/components/discovery-impl.jar $SM_BASE/esm/WEB-INF/lib
/bin/cp $ESM_BASE/sssm/util/cre/components/serack.jar $SM_BASE/esm/WEB-INF/lib

# re-register esm app (otherwise topo page may not display)
SMREG=$US_BASE/smreg
if [ -f "$SMREG" ]; then
    $SMREG add -a /usr/share/webconsole/esm >> $LOG 2>&1
fi

## end UI changes ##

# restart if not adding patches with esmpatch
if [ "$ESM_CONTEXT" != "patch" ]; then
    $ESM_BASE/bin/esmcontrol -m start >> $LOG 2>&1

    echo "For all changes to go into effect, the web console will need to be" | /bin/tee -a $LOG
    echo "restarted.  Please run the command:" | /bin/tee -a $LOG
    echo | /bin/tee -a $LOG
    echo "\t/usr/sbin/smcwebserver restart" | /bin/tee -a $LOG
    echo | /bin/tee -a $LOG
    echo "to restart the web console." | /bin/tee -a $LOG
fi
