#!/bin/sh
### BEGIN INIT INFO
# Provides:          bopm
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start or stop SAUCE
### END INIT INFO

PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/bopm
NAME=bopm
DESC="Blitzed Open Proxy Monitor"

# defaults - DON'T CHANGE, edit /etc/default/bopm instead!
START_BOPM=false

# source /etc/default/bopm
test -f /etc/default/bopm && . /etc/default/bopm

# if /var/run/bopm doesn't exist yet create it
test -d /var/run/bopm || mkdir /var/run/bopm && chown irc:root /var/run/bopm

if [ "$START_BOPM" = "false" ] ; then
	echo "$DESC: disabled, see /etc/default/bopm"
	exit 0
fi

get_confname() {
  CONFNAME=$(echo $1|sed -e 's#.*/\([a-zA-Z0-9]*\)\.conf$#\1#')
}

test -f $DAEMON || exit 0

set -e

case "$1" in
  start)
	echo -n "Starting $DESC: $NAME"
	for i in /etc/bopm/*.conf; do
		get_confname $i
		start-stop-daemon --start --quiet -c irc \
			--pidfile /var/run/bopm/$CONFNAME.pid \
			-b -o --exec $DAEMON -- -c $CONFNAME
		echo -n "."
	done
	echo
	;;
  stop)
	echo -n "Stopping $DESC: $NAME"
	for i in /etc/bopm/*.conf; do
		get_confname $i
		start-stop-daemon --oknodo --stop --quiet \
			--pidfile /var/run/bopm/$CONFNAME.pid --exec $DAEMON
		echo -n "."
	done
	echo
	;;
  restart|force-reload)
	$0 stop
	sleep 1
	$0 start
	;;
  *)
	N=/etc/init.d/$NAME
	echo "Usage: $N {start|stop|restart|force-reload}" >&2
	exit 1
	;;
esac

exit 0

# vim:set filetype=sh:

