#/bin/sh

. /lib/lsb/init-functions

NAME=gpsd
DAEMON=/usr/sbin/$NAME
PIDFILE=/var/run/$NAME.pid
SOCK=/var/run/$NAME.sock
[ -r /etc/sysconfig/$NAME ] && . /etc/sysconfig/$NAME

if [ -z "$GPSD_SOCKET" ] && [ -z "$DEVICES" ]; then
        GPSD_SOCKET=/var/run/gpsd.sock
fi

if [ -n "$GPSD_SOCKET" ]; then
        GPSD_OPTIONS="$GPSD_OPTIONS -F $GPSD_SOCKET"
fi

start() {
        log_info_msg "Starting GPS (Global Positioning System) Daemon..."
        $DAEMON $GPSD_OPTIONS -P $PIDFILE $DEVICES
        evaluate_retval
}
stop() {
	log_info_msg "Stopping GPS (Global Positioning System) Daemon..."
	kill `cat $PIDFILE`
	rm -f $PIDFILE
	evaluate_retval
}
status() {
	pid=`pidof $DAEMON`
	if [ "$pid" ]; then
		echo "GPS Daemon running on PID $pid"
	else
		echo "GPS Daemon not running"
	fi
}
case $1 in
	start)
		start
		;;
	stop)
		stop
		;;
	restart)
		stop
		start
		;;
	status)
		status
		;;
         *)
                 echo "Usage: $0 {start|stop|restart|status}"
                 ;;
esac
