#! /bin/sh

### BEGIN INIT INFO
# Provides:          pkspxy
# Required-Start:    $local_fs $remote_fs $network $time
# Required-Stop:     $local_fs $remote_fs $network $time
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: PGP Public Key Server Proxy Daemon
# Description:       pkspxy implements a caching proxy to be used between any
#                    program which speaks the HKP protocol for PGP public key
#                    exchange, and any HKP-capable key server.
### END INIT INFO

PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/pkspxy
NAME=pkspxy
DESC="PGP key server proxy"
PIDFILE=/var/run/$NAME.pid
CONFIGFILE=/etc/pkspxy.conf

OFFLINE="-o"

test -f $DAEMON || exit 0

set -e

case "$1" in
  start)
	echo -n "Starting $DESC: "
	start-stop-daemon --start --quiet --chuid pkspxy --pidfile $PIDFILE \
	    --exec $DAEMON -- $OFFLINE -F $CONFIGFILE > $PIDFILE
	echo "$NAME."
	;;
  stop)
	echo -n "Stopping $DESC: "
	start-stop-daemon --stop --oknodo --quiet --pidfile $PIDFILE \
	    --exec $DAEMON
	rm -f $PIDFILE
	echo "$NAME."
	;;
  restart|force-reload)
	sh $0 stop
	sh $0 start
	;;
  *)
	N=/etc/init.d/$NAME
	echo "Usage: $N {start|stop|restart|force-reload}" >&2
	exit 1
	;;
esac

exit 0
