#!/bin/bash
#
# gpsd  Hook to gps to put into place any
#	     registration policies.
#
# chkconfig: 2345 14 62
# description: gpsd a daemon for gps device this service policy to 
#	 	local and other sysem access for local gps device on 2947 port.
#

# Source the function library.
. /etc/init.d/functions

pname=gpsd

RETVAL=0

# See how we were called.
start() {
	if [ -x /usr/sbin/gpsd ] ; then
		gprintf "Start GPSD Navigation Daemon for GPS Devices: "
		#sh /usr/sbin/gpsd.hotplug add /dev/gps
		gpsd -p /dev/gps -F /var/run/gpsd.sock
		RETVAL=$?
		if [ "$RETVAL" = 0 ] ; then 
		    gprintf "              [   OK   ]\n"
		    touch /var/lock/subsys/$pname
		 else
    		    gprintf "              [ FAILED ]\n"
	            rm -f /var/lock/subsys/$pname
		 fi
	fi
}

stop() {
	gprintf "Stop GPSD Navigation Daemon: "
	killproc gpsd
	RETVAL=$?
	if [ $RETVAL -eq 0 ]; then
        rm -f /var/lock/subsys/$pname
        rm -f /var/run/gpsd*
	
	echo
	fi
}

# See how we were called.
case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    status)
        status $pname
        RETVAL=$?
        ;;
    restart)
        stop
	sleep 3
        start
        ;;
    *)
        gprintf "Usage: %s {start|stop|restart|status}\n" "$0"
        ;;
esac
exit $RETVAL
