#!/bin/ksh

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


#
#  This program performs the prepatch activity for the SUNWse6130ui patch.
#

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

PREV_PATCH_ID=118164-05

patchFound=`/usr/bin/showrev -p | /usr/bin/grep "Patch: *$PREV_PATCH_ID"`
if [ -z "$patchFound" ]
then
    echo "ERROR : Unable to install patch."
    echo "Installation of the StorEDGE 6130 Array Host Installation"
    echo "Software for Solaris v1.3 is a PREREQUISITE for this patch."
    echo "Please obtain and install the upgrade software first, then"
    echo "retry to install this patch."
    exit 1
fi

#
# 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


#
# Remove the local web application directory tree
# that was created by the unjar of the war file
#


#
# First, remove all of the files, and save the directories
# to a temporary file to be sorted.
#

/usr/bin/rm -f /tmp/SUNWse6130ui.$$.dirlist
/usr/bin/rm -f /tmp/SUNWse6130ui.$$.rdirlist

echo "0 ../se6130ui" > /tmp/SUNWse6130ui.$$.dirlist
c=1

for i in `$JAR_CMD tf $INSTALLDIR/se6130ui.war`
do
  if [ -f $WEBAPPDIR/$i ]
  then
    /usr/bin/rm $WEBAPPDIR/$i
  elif [ -d $WEBAPPDIR/$i ]
  then
    echo $c $i >> /tmp/SUNWse6130ui.$$.dirlist
    c=`expr $c + 1`
  fi
done

/usr/bin/sort -rn /tmp/SUNWse6130ui.$$.dirlist > /tmp/SUNWse6130ui.$$.rdirlist

#
# Remove all of the empty directories
#
while read dummy i
do
  if [ -d $WEBAPPDIR/$i ]
  then
    if [ -z "`/usr/bin/find $WEBAPPDIR/$i -type file`" ]
    then
      /usr/bin/rmdir $WEBAPPDIR/$i 2>/dev/null
    fi
  fi
done < /tmp/SUNWse6130ui.$$.rdirlist

/usr/bin/rm -f /tmp/SUNWse6130ui.$$.dirlist
/usr/bin/rm -f /tmp/SUNWse6130ui.$$.rdirlist


exit 0
