#! /bin/sh
### BEGIN INIT INFO
# Provides:          upsd
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
### END INIT INFO
#
# This file was automatically customized by debmake on Thu, 12 Dec 1996 21:31:08 -0800
#
# Written by Miquel van Smoorenburg <miquels@drinkel.ow.org>.
# Modified for Debian GNU/Linux by Ian Murdock <imurdock@gnu.ai.mit.edu>.
# Modified for Debian by Christoph Lameter <clameter@debian.org>
# Modified again for Debian by Nick Estes <debian@nickstoys.com>.

[ -e /dev/tts/0 ] && PORT=/dev/tts/0 || PORT=/dev/ttyS0
[ -r /etc/default/upsd ] && . /etc/default/upsd

PATH=/bin:/usr/bin:/sbin:/usr/sbin
DAEMON=/sbin/upsd

FLAGS="defaults 50"

test -f $DAEMON || exit 0

case "$1" in
  start)
    echo -n "Starting ups monitor: upsd"
    start-stop-daemon --start --quiet --exec $DAEMON -- $PORT
    echo .
    ;;
  stop)
    echo -n "Stoping ups monitor: upsd"
    start-stop-daemon --stop --quiet --exec $DAEMON
    echo .
    ;;
  restart|force-reload)
    echo -n "Restarting ups monitor: upsd"
    start-stop-daemon --stop --quiet --exec $DAEMON
    start-stop-daemon --start --quiet --exec $DAEMON -- $PORT
    echo .
    ;;
  poweroff)
    upsd -i-1 $PORT
    case "$?" in
      101 | 102)
	sleep 60
	upsd -k $PORT
        ;;
      *)
        ;;
    esac
    ;;
  *)
    echo "Usage: /etc/init.d/$0 {start|stop|poweroff}"
    exit 1
    ;;
esac

exit 0
