#! /bin/sh
#
#	Based on skeleton file by Miquel van Smoorenburg <miquels@cistron.nl>.
#	Modified for Debian by Ian Murdock <imurdock@gnu.ai.mit.edu>.
#

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/gpsd
NAME=gpsd
DESC="GPS daemon"
USER=gpsd

test -x $DAEMON || exit 0

# Include gpsd defaults if available
if [ -f /etc/default/gpsd ] ; then
	. /etc/default/gpsd
fi

set -e

case "$1" in
  start)
	if [ "x$START_DAEMON" = "xtrue" ] ; then
		echo -n "Starting $DESC: "
		start-stop-daemon --start --quiet \
			--chuid $USER --exec $DAEMON -- $DAEMON_OPTS || true
		echo "$NAME."
	else
		echo "$NAME is configured not to start automatically."
		echo "  To change this, run 'dpkg-reconfigure gpsd'."
	fi		
	;;
  stop)
	echo -n "Stopping $DESC: "
	start-stop-daemon --stop --quiet --oknodo \
		--exec $DAEMON
	echo "$NAME."
	;;
  reload|force-reload)
	echo "$DESC: Resetting connection to GPS device."
	start-stop-daemon --stop --signal 1 --quiet \
		--exec $DAEMON
	;;
  restart)
	if [ "x$START_DAEMON" = "xtrue" ] ; then
		echo -n "Restarting $DESC: "
		start-stop-daemon --stop --quiet --oknodo \
			--exec $DAEMON
		sleep 1
		start-stop-daemon --start --quiet \
			--chuid $USER --exec $DAEMON -- $DAEMON_OPTS || true
		echo "$NAME."
	else
		echo "$NAME is configured not to start automatically."
		echo "  To change this, run 'dpkg-reconfigure gpsd'."
	fi		
	;;
  *)
	N=/etc/init.d/$NAME
	echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
	exit 1
	;;
esac

exit 0
