#!/bin/bash
#
# xpilot-server	: start or stop the xpilot server
#
#		Written by Miquel van Smoorenburg <miquels@cistron.nl>.
#		Modified for Debian GNU/Linux
#		by Ian Murdock <imurdock@gnu.ai.mit.edu>.
#		Modified for Debian GNU/Linux xpilot-server package
#		by Matt Kern <matt.kern@pobox.com>
#

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

test -x /usr/games/start-xpilots || exit 0

set -e

source /etc/xpilots.conf

case "$1" in
  start)
	echo "$AUTOSTART" |grep -iq yes || exit 0
	test -f "$DEFAULTMAP" || exit 0

	echo -n "Starting xpilot server: "
	start-stop-daemon --start --quiet --pidfile /var/run/xpilots.pid \
		--oknodo --exec /usr/games/start-xpilots
	echo "xpilots."
	;;
  stop)
	echo -n "Stopping xpilot server: "
	start-stop-daemon --stop --quiet --pidfile /var/run/xpilots.pid \
		--oknodo --exec /usr/games/xpilots
	echo "xpilots."
	;;
  restart|force-reload)
	echo -n "Restarting xpilot server: "
	start-stop-daemon --stop --quiet --oknodo --pidfile \
		/var/run/xpilots.pid --exec /usr/games/xpilots
	sleep 1

	echo "$AUTOSTART" |grep -iq yes || exit 0
	test -f "$DEFAULTMAP" || exit 0

	start-stop-daemon --start --quiet --oknodo --pidfile \
		/var/run/xpilots.pid --exec /usr/games/start-xpilots
	echo "xpilots."
	;;
  *)
	N=/etc/init.d/xpilot-server
	echo "Usage: $N {start|stop|restart|force-reload}" >&2
	exit 1
	;;
esac

exit 0
