#! /usr/bin/ksh
# Name:         postpatch
# Title:
# Version:
# Revision: 
# Update Date: 
# Programmer:   
# Documents:
#
#Description Post patch installation script
#

if [ $ROOTDIR = "/" ]; then
  BASEDIR=`pkgparam SUNWsmgr2 BASEDIR`
else
  BASEDIR=`pkgparam -R ${ROOTDIR} SUNWsmgr2 BASEDIR`
fi

#remove the leading path if ROOTDIR not other than /
if [ $ROOTDIR = "/" ]; then
  ROOTDIR=""
fi

RUN_LEV=`who -r | awk '{print $3}'`
 
# If RUN_LEV is null set it to unknown - 
RUN_LEV=${RUN_LEV:=unknown}

if [ $RUN_LEV != "2" ] ; then
    #This is a non-jumpstart install
    echo "#! /usr/bin/ksh" > /tmp/inst_SUNWsmgr2
    echo "" >> /tmp/inst_SUNWsmgr2
    echo "JAVAPATH=${PKG_INSTALL_ROOT}/usr/opt/SUNWsmgr2/jre/bin/java" >> /tmp/inst_SUNWsmgr2
    echo "" >> /tmp/inst_SUNWsmgr2
    echo "PKG_INSTALL_ROOT=${PKG_INSTALL_ROOT}" >> /tmp/inst_SUNWsmgr2
    cat $BASEDIR/SUNWsmgr2/bin2/SANbox_Manager >> /tmp/inst_SUNWsmgr2
    cp /tmp/inst_SUNWsmgr2 $BASEDIR/SUNWsmgr2/bin2/SANbox_Manager
    rm /tmp/inst_SUNWsmgr2

    removef SUNWsmgr2 ${PKG_INSTALL_ROOT}/usr/opt/SUNWsmgr2/bin2/SANbox_Manager
    installf SUNWsmgr2 ${PKG_INSTALL_ROOT}/usr/opt/SUNWsmgr2/bin2/SANbox_Manager e 0755 root bin
    chmod 755 ${PKG_INSTALL_ROOT}/usr/opt/SUNWsmgr2/bin2/SANbox_Manager
    echo "#! /usr/bin/ksh" > /tmp/inst_sfv
    echo "" >> /tmp/inst_sfv
    echo "JAVAPATH=${PKG_INSTALL_ROOT}/usr/opt/SUNWsmgr2/jre/bin/java" >> /tmp/inst_sfv
    echo "" >> /tmp/inst_sfv
    echo "PKG_INSTALL_ROOT=${PKG_INSTALL_ROOT}" >> /tmp/inst_sfv
    cat $BASEDIR/SUNWsmgr2/bin2/SANsurferFabricView >> /tmp/inst_sfv
    cp /tmp/inst_sfv $BASEDIR/SUNWsmgr2/bin2/SANsurferFabricView
    rm /tmp/inst_sfv

    echo "perfmon.installDir=${BASEDIR}/SUNWsmgr2/bin2" >> /tmp/inst_localp
    cat $BASEDIR/SUNWsmgr2/bin2/local.properties >> /tmp/inst_localp
    cp /tmp/inst_localp $BASEDIR/SUNWsmgr2/bin2/local.properties
    rm /tmp/inst_localp

    removef SUNWsmgr2 ${PKG_INSTALL_ROOT}/usr/opt/SUNWsmgr2/bin2/SANsurferFabricView
    installf SUNWsmgr2 ${PKG_INSTALL_ROOT}/usr/opt/SUNWsmgr2/bin2/SANsurferFabricView e 0755 root bin
    chmod 755  ${PKG_INSTALL_ROOT}/usr/opt/SUNWsmgr2/bin2/SANsurferFabricView 
    echo "Now you can start the GUI by typing :
    ${PKG_INSTALL_ROOT}/usr/opt/SUNWsmgr2/bin2/SANbox_Manager"
else
    #This appears to be a jumpstart install
    echo "#! /usr/bin/ksh" > /tmp/inst_SUNWsmgr2
    echo "" >> /tmp/inst_SUNWsmgr2
    echo "JAVAPATH=/usr/opt/SUNWsmgr2/jre/bin/java" >> /tmp/inst_SUNWsmgr2
    echo "" >> /tmp/inst_SUNWsmgr2
    echo "PKG_INSTALL_ROOT=" >> /tmp/inst_SUNWsmgr2
    cat $BASEDIR/SUNWsmgr2/bin2/SANbox_Manager >> /tmp/inst_SUNWsmgr2
    cp /tmp/inst_SUNWsmgr2 $BASEDIR/SUNWsmgr2/bin2/SANbox_Manager
    rm /tmp/inst_SUNWsmgr2

    echo "perfmon.installDir=${BASEDIR}/SUNWsmgr2/bin2" >> /tmp/inst_localp
    cat $BASEDIR/SUNWsmgr2/bin2/local.properties >> /tmp/inst_localp
    cp /tmp/inst_localp $BASEDIR/SUNWsmgr2/bin2/local.properties
    rm /tmp/inst_localp

    removef SUNWsmgr2 $BASEDIR/usr/opt/SUNWsmgr2/bin2/SANbox_Manager
    installf SUNWsmgr2 $BASEDIR/usr/opt/SUNWsmgr2/bin2/SANbox_Manager e 0755 root bin
    chmod 755 $BASEDIR/usr/opt/SUNWsmgr2/bin2/SANbox_Manager 

    #This appears to be a jumpstart install
    echo "#! /usr/bin/ksh" > /tmp/inst_sfv
    echo "" >> /tmp/inst_sfv
    echo "JAVAPATH=/usr/opt/SUNWsmgr2/jre/bin/java" >> /tmp/inst_sfv
    echo "" >> /tmp/inst_sfv
    echo "PKG_INSTALL_ROOT=" >> /tmp/inst_sfv
    cat $BASEDIR/SUNWsmgr2/bin2/SANsurferFabricView >> /tmp/inst_sfv
    cp /tmp/inst_sfv $BASEDIR/SUNWsmgr2/bin2/SANsurferFabricView
    rm /tmp/inst_sfv

    removef SUNWsmgr2 $BASEDIR/usr/opt/SUNWsmgr2/bin2/SANsurferFabricView
    installf SUNWsmgr2 $BASEDIR/usr/opt/SUNWsmgr2/bin2/SANsurferFabricView e 0755 root bin
    chmod 755 $BASEDIR/usr/opt/SUNWsmgr2/bin2/SANsurferFabricView 
    echo "It appears that you may have done a jumpstart install.
    Please inspect the /usr/opt/SUNWsmgr2/bin2/SANbox_Manager script before running."
fi
