#!/bin/ksh

# Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
#ident  "@(#)postbackout 1.2     05/09/12 SMI"


##############################################################
#
# STEP 1: Reinstall the old application
# This is equivalent to a postinstall for SUNWse6130ui
#
##############################################################

BIN_DIR=/usr/sbin
SMREG=$BIN_DIR/smreg
SMCWEBSERVER=$BIN_DIR/smcwebserver

BASEDIR=`pkgparam SUNWse6130ui BASEDIR`
INSTALLDIR=$BASEDIR/SUNWse6130ui
WEBAPPDIR=$INSTALLDIR/se6130ui

APPNAME=com.sun.netstorage.array.mgmt.se6130ui_3.0

PROCOUT=/tmp/procout.$$

fatal ()
{
    echo "$*" >&2
    exit 3
}

#
# Set path to jar command
#
if [ -x /opt/se6130/java/usr/java/bin/jar ]
then
   JAR_CMD=/opt/se6130/java/usr/java/bin/jar
elif [ -x /opt/se6130/java/usr/j2se/bin/jar ]
then
   JAR_CMD=/opt/se6130/java/usr/j2se/bin/jar
elif [ -x /opt/se6000/java/usr/java/bin/jar ]
then
   JAR_CMD=/opt/se6000/java/usr/java/bin/jar
elif [ -x /opt/se6000/java/usr/j2se/bin/jar ]
then
   JAR_CMD=/opt/se6000/java/usr/j2se/bin/jar
elif [ -x /usr/bin/jar ]
then
   JAR_CMD=/usr/bin/jar
elif [ -x /usr/j2se/bin/jar ]
then
   JAR_CMD=/usr/j2se/bin/jar
elif [ -x /usr/java/bin/jar ]
then
   JAR_CMD=/usr/java/bin/jar
else
   fatal "Failure to find JAR command! Exiting."
fi

# Create the application directory tree in the installation tree
#
echo "Expanding $INSTALLDIR/se6130ui.war into $WEBAPPDIR ..."

/usr/bin/rm -f $PROCOUT

if /usr/bin/mkdir -p $WEBAPPDIR &&
   cd $WEBAPPDIR                &&
   $JAR_CMD xvf $INSTALLDIR/se6130ui.war > $PROCOUT 2>&1
then
   /usr/bin/rm -f $PROCOUT
else
   [ -s $PROCOUT ] && /usr/bin/cat $PROCOUT
   fatal "Failure to create the web application directory!"
fi
    
#
# RCB - Tell user what do to now
#
#echo "\nIf you are manually removing this patch, run the following commands"
#echo "as the root user, after the removal has successfully completed.\n"
#echo "$SMREG remove -a $APPNAME"
#echo "$SMREG add -a $WEBAPPDIR"
#echo "$SMCWEBSERVER restart"
#echo "$SMCWEBSERVER enable\n"

#
# RCB - Not part of an install CD, so perform for them...
#
$SMREG remove -a $APPNAME
$SMREG add -a $WEBAPPDIR
$SMCWEBSERVER restart
$SMCWEBSERVER enable

exit 0
