#!/bin/sh
#
# Night Light IRC Proxy
# Deinstallation script for FreeBSD ports
# Written by Jonas Kvinge
#
# Last modified: Jonas Kvinge (03.09.2006)
#

BINFILE=ircproxyd
PIDFILE="/var/run/ircproxyd.pid"
EUSER="ircproxy"
EGROUP="ircproxy"

if [ "$2" = "DEINSTALL" ]; then

  #grep -q "^[^#]*${PKG_PREFIX}/sbin/ircproxy\.sh" /etc/crontab >/dev/null 2>&1
  #if [ $? -eq 0 ]; then
  #  sed -i -e "s:^[^#]*${PKG_PREFIX}/sbin/ircproxy\.sh::" /etc/crontab
  #  sed -i -e '/^$/d' /etc/crontab
  #  rm -f /etc/crontab-e
  #fi

  if [ -f $PIDFILE ] && [ -r $PIDFILE ] ; then
    PID=`cat "$PIDFILE"`
    ps -p "$PID" >/dev/null 2>&1
    if [ $? -eq 0 ]; then
      for count in 1 2 3 4 5 6 7 8 9 10; do
        if [ $count -ge 5 ]; then
          kill -KILL "$PID" || break
          break
        fi
        kill -TERM "$PID" || break
        sleep 2
        ps -p "$PID" >/dev/null 2>&1
        if [ ! $? -eq 0 ]; then
          break;
        fi
      done
    fi
  fi
fi

if [ "$2" = "POST-DEINSTALL" ]; then

  pw group show ${EGROUP} >/dev/null 2>&1
  if [ $? -eq 0 ] ; then
    pw groupdel -n "$EGROUP"
  fi
  pw user show ${EUSER} >/dev/null 2>&1
  if [ $? -eq 0 ] ; then
    pw userdel -n "$EUSER"
  fi
fi

exit 0


syntax highlighted by Code2HTML, v. 0.9.1