#
# ident "$Id$ SMI"
# 
# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#

PATH=/bin:/usr/bin:/sbin:/usr/sbin
set -u

# Trigger stop command just in case the web server is still running
PROCESS_PIDFILE="/var/opt/SUNWut/tmp/utwebadmin.pid"
if [ -f "${PROCESS_PIDFILE}" ]; then
    PID=`cat ${PROCESS_PIDFILE}`
    if [ -n "`/bin/ps -deaf | awk '{print $2}' | grep $PID`" ]; then
        kill -9 $PID >/dev/null 2>&1
    fi
    rm -f ${PROCESS_PIDFILE}
fi

# Remove temporary files from etc, log and work directory
LOG_FILES="/var/opt/SUNWut/log/utwebadmin.log*"
SERVER_FILE="/etc/opt/SUNWut/webadmin/server.xml"
WEB_FILE="/etc/opt/SUNWut/webadmin/web.xml"
KEYSTORE_FILE="/etc/opt/SUNWut/webadmin/keystore"
WORK_DIR="/var/opt/SUNWut/webadmin"

rm -f ${LOG_FILES}
if [ -f "${SERVER_FILE}" ]; then
  rm -f ${SERVER_FILE}
fi
if [ -f "${WEB_FILE}" ]; then
  rm -f ${WEB_FILE}
fi
if [ -f "${KEYSTORE_FILE}" ]; then
  rm -f ${KEYSTORE_FILE}
fi

if [ -d "${WORK_DIR}" ]; then
  rm -rf ${WORK_DIR}/*
fi

OS=`uname -s`
#
# For Linux only.  We need to remove the links to init.d files using
# chkconfig.  
if [ $OS = "Linux" ]; then
    INITFILE="utwadmin"
    chkconfig --del $INITFILE > /dev/null

    #
    # On SuSE/JDS, chkconfig (based on insserv) does not remove Kill links in
    # lower runlevels.  They must be removed manually.
    #
    if [ -f /etc/SuSE-release ]; then
	# we are installing on either SuSE or JDS
	ETCINIT=/etc/rc.d
        rm -f $ETCINIT/rc4.d/K??$INITFILE
	rm -f $ETCINIT/rc3.d/K??$INITFILE
	rm -f $ETCINIT/rc2.d/K??$INITFILE
	rm -f $ETCINIT/rc1.d/K??$INITFILE
    fi
fi
 
exit 0
