#!/bin/sh
#
# This script does the following.
#
# * Checks if the PID file exists. If it does, it kills the
#   process and removes the PID file.
#
# * Checks if the 'www' user exists. If it does, then it displays
#   a message.
#
# $FreeBSD: ports/www/tomcat41/files/pkg-deinstall.in,v 1.1 2006/02/07 08:50:08 lawrance Exp $
#

USER=www
PID_FILE=/var/run/tomcat41.pid

# Make sure we're in the right stage of the process
if [ "$2" = "DEINSTALL" ]; then

	# Kill the process if it is still running
	if [ -s ${PID_FILE} ]; then
		PID=`cat ${PID_FILE}`
		echo -n ">> Killing Jakarta Tomcat process (${PID})..."
		/bin/kill ${PID} > /dev/null 2> /dev/null
		if [ $? -eq 0 ]; then
			echo " [ DONE ]"
		else
			echo " [ FAILED ]"
		fi
		echo -n ">> Removing PID file (${PID_FILE})..."
		rm ${PID_FILE} > /dev/null 2> /dev/null
		if [ $? -eq 0 ]; then
			echo " [ DONE ]"
		else
			echo " [ FAILED ]"
		fi
	fi
fi

if [ "$2" = "POST-DEINSTALL" ]; then
	# If the user exists, then display a message
	if pw usershow "${USER}" 2>/dev/null 1>&2; then
		echo "To delete the ${USER} user permanently, use 'pw userdel ${USER}'"
	fi
fi

exit 0
