From e6f17288e3d02ddfe3eeb063b637d0986c7bce5f Mon Sep 17 00:00:00 2001 From: David Spencer Date: Wed, 7 Sep 2011 23:21:01 -0400 Subject: system/gpsd: Downgraded to version 2.95 due to API breakage. Added rc.* files and *.desktop files. Added udev rules and scripts. Signed-off-by: dsomero --- system/gpsd/README | 35 +++++++++-- system/gpsd/doinst.sh | 30 ++++++++++ system/gpsd/gpsd.SlackBuild | 56 +++++++++++++++--- system/gpsd/gpsd.hotplug | 124 +++++++++++++++++++++++++++++++++++++++ system/gpsd/gpsd.hotplug.wrapper | 41 +++++++++++++ system/gpsd/gpsd.info | 8 +-- system/gpsd/rc.gpsd.conf.new | 14 +++++ system/gpsd/rc.gpsd.new | 60 +++++++++++++++++++ system/gpsd/slack-desc | 10 ++-- system/gpsd/xgps.desktop | 9 +++ system/gpsd/xgpsspeed.desktop | 9 +++ 11 files changed, 373 insertions(+), 23 deletions(-) create mode 100644 system/gpsd/doinst.sh create mode 100644 system/gpsd/gpsd.hotplug create mode 100644 system/gpsd/gpsd.hotplug.wrapper create mode 100644 system/gpsd/rc.gpsd.conf.new create mode 100644 system/gpsd/rc.gpsd.new create mode 100644 system/gpsd/xgps.desktop create mode 100644 system/gpsd/xgpsspeed.desktop (limited to 'system/gpsd') diff --git a/system/gpsd/README b/system/gpsd/README index 5a1d1b8508..a111f54615 100644 --- a/system/gpsd/README +++ b/system/gpsd/README @@ -1,8 +1,31 @@ -gpsd is a service daemon that monitors one or more GPSes attached to a -host computer through serial or USB ports, making all data on the location, -course, and velocity available to be queried on TCP port 2947 of the host -computer. With gpsd, multiple GPS client applications (such as navigational -and wardriving software) can share access to GPSes without contention or -loss of data. Applications that presently use gpsd include Viking and Kismet. +gpsd is a service daemon that monitors one or more GPSes attached to +a host computer through serial or USB ports, making all data on the +location, course, and velocity available to be queried on TCP port +2947 of the host computer. With gpsd, multiple GPS client applications +(such as navigational and wardriving software) can share access to GPSes +without contention or loss of data. Applications that presently use +gpsd include Viking and Kismet. See README.build for some additional build options that might be useful. + +To enable automatic startup of gpsd at boot time, or when a GPS device is +connected via USB, you need to do the following three steps: + +1. Edit the file /lib/udev/rules.d/97-gpsd.rules and uncomment the line +(or lines) beginning '#ATTRS' that corresponds to your GPS hardware and +save it in /etc/udev/rules.d/. To avoid confusion with other USB serial +devices that you might have, do not uncomment lines that do not +correspond to your GPS hardware. + +2. Make the file /etc/rc.d/rc.gpsd executable. + chmod +x /etc/rc.d/rc.gpsd + +3. Add the following lines to /etc/rc.d/rc.local + if [ -x /etc/rc.d/rc.gpsd ]; then + /etc/rc.d/rc.gpsd start + fi + +Configuration options may be set in the file /etc/rc.d/rc.gpsd.conf. The +defaults will usually be adequate. However, if your GPS is on a real (non-USB) +serial port -- for example, /dev/ttyS0 -- you should add /dev/ttyS0 to +GPS_DEVICES in /etc/rc.d/rc.gpsd.conf. diff --git a/system/gpsd/doinst.sh b/system/gpsd/doinst.sh new file mode 100644 index 0000000000..81e9fca8c2 --- /dev/null +++ b/system/gpsd/doinst.sh @@ -0,0 +1,30 @@ +config() { + NEW="$1" + OLD="$(dirname $NEW)/$(basename $NEW .new)" + # If there's no config file by that name, mv it over: + if [ ! -r $OLD ]; then + mv $NEW $OLD + elif [ "$(cat $OLD | md5sum)" = "$(cat $NEW | md5sum)" ]; then + # toss the redundant copy + rm $NEW + fi + # Otherwise, we leave the .new copy for the admin to consider... +} + +preserve_perms() { + NEW="$1" + OLD="$(dirname $NEW)/$(basename $NEW .new)" + if [ -e $OLD ]; then + cp -a $OLD ${NEW}.incoming + cat $NEW > ${NEW}.incoming + mv ${NEW}.incoming $NEW + fi + config $NEW +} + +preserve_perms etc/rc.d/rc.gpsd.new +config etc/rc.d/rc.gpsd.conf.new + +if [ -x /usr/bin/update-desktop-database ]; then + /usr/bin/update-desktop-database -q usr/share/applications >/dev/null 2>&1 +fi diff --git a/system/gpsd/gpsd.SlackBuild b/system/gpsd/gpsd.SlackBuild index e9c0adc5f6..62962e1390 100644 --- a/system/gpsd/gpsd.SlackBuild +++ b/system/gpsd/gpsd.SlackBuild @@ -1,12 +1,29 @@ #!/bin/sh # Slackware build script for gpsd -# Written by David Spencer -# This script is dedicated to the public domain +# Copyright 2011 David Spencer, Baildon, West Yorkshire, U.K. +# All rights reserved. +# +# Redistribution and use of this script, with or without modification, is +# permitted provided that the following conditions are met: +# +# 1. Redistributions of this script must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED +# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. PRGNAM=gpsd -VERSION=${VERSION:-2.96} -BUILD=${BUILD:-1} +VERSION=${VERSION:-2.95} +BUILD=${BUILD:-2} TAG=${TAG:-_SBo} if [ -z "$ARCH" ]; then @@ -57,9 +74,7 @@ rm -rf $PKG mkdir -p $TMP $PKG $OUTPUT cd $TMP rm -rf $PRGNAM-$VERSION -# 2.96 has a tarball pathname snafu -TARVERSION="${VERSION}bis" -tar xvf $CWD/$PRGNAM-$TARVERSION.tar.gz +tar xvf $CWD/$PRGNAM-$VERSION.tar.gz cd $PRGNAM-$VERSION chown -R root:root . chmod -R u+w,go+r-w,a-s . @@ -84,17 +99,42 @@ CXXFLAGS="$SLKCFLAGS" \ make -make install-strip DESTDIR=$PKG +# --no-print-directory prevents crazy gps-2.94-py2.6.egg-info install path +# (thanks again Niels Horn!) +make --no-print-directory install-strip DESTDIR=$PKG find $PKG/usr/man -type f -exec gzip -9 {} \; for i in $(find $PKG/usr/man -type l) ; do ln -s $( readlink $i ).gz $i.gz ; rm $i ; done +install -D -m 0644 $CWD/xgps.desktop \ + $PKG/usr/share/applications/xgps.desktop +install -D -m 0644 $CWD/xgpsspeed.desktop \ + $PKG/usr/share/applications/xgpsspeed.desktop +install -D -m 0644 packaging/X11/gpsd-logo.png \ + $PKG/usr/share/pixmaps/gpsd-logo.png + +# Use hotplug scripts from gpsd-3.0 instead of 2.95 -- they work ;-) +install -D -m 0755 $CWD/gpsd.hotplug \ + $PKG/lib/udev/gpsd.hotplug +install -D -m 0755 $CWD/gpsd.hotplug.wrapper \ + $PKG/lib/udev/gpsd.hotplug.wrapper +mkdir -p $PKG/lib/udev/rules.d +cat gpsd.rules | \ + sed 's/^ATTRS/#&/' \ + >$PKG/lib/udev/rules.d/97-gpsd.rules + +install -D -m 0644 $CWD/rc.gpsd.new \ + $PKG/etc/rc.d/rc.gpsd.new +install -D -m 0644 $CWD/rc.gpsd.conf.new \ + $PKG/etc/rc.d/rc.gpsd.conf.new + mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION cp -a AUTHORS COPYING INSTALL README TODO $PKG/usr/doc/$PRGNAM-$VERSION cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild mkdir -p $PKG/install cat $CWD/slack-desc > $PKG/install/slack-desc +cat $CWD/doinst.sh > $PKG/install/doinst.sh cd $PKG /sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.${PKGTYPE:-tgz} diff --git a/system/gpsd/gpsd.hotplug b/system/gpsd/gpsd.hotplug new file mode 100644 index 0000000000..805f941998 --- /dev/null +++ b/system/gpsd/gpsd.hotplug @@ -0,0 +1,124 @@ +#!/usr/bin/python +# +# This file is Copyright (c) 2010 by the GPSD project +# BSD terms apply: see the file COPYING in the distribution root for details. +# +# Hotplug script for gpsd by Eric S. Raymond, March 2005 +# This script is part of the gpsd distribution: see http://gpsd.berlios.de +# Can be called like "gpsd.hotplug [add|remove] /dev/ttyUSB0" for test +# purposes. +import sys, time, os, syslog, glob, socket, stat + +CONTROL_SOCKET = os.getenv('GPSD_SOCKET') or "/var/run/gpsd.sock" +GPSD_OPTIONS = os.getenv('GPSD_OPTIONS') or "" + +WHEREAMI = __file__ + +def gpsd_control_connect(complain=True): + "Acquire a connection to the GPSD control socket." + if not os.path.exists(CONTROL_SOCKET): + syslog.syslog("socket %s doesn't exist" % CONTROL_SOCKET) + return None + try: + sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM, 0) + sock.connect(CONTROL_SOCKET) + except socket.error, msg: + if complain: + syslog.syslog("socket %s creation failure: %s" % (CONTROL_SOCKET, msg)) + if sock: + sock.close() + sock = None + #else: + # syslog.syslog("socket %s created OK" % CONTROL_SOCKET) + return sock + +def gpsd_control(action, argument): + "Pass a command to gpsd; start the daemon if not already running." + syslog.syslog("gpsd_control(action=%s, arg=%s)" % (action, argument)) + connect = gpsd_control_connect(complain=False) + if connect: + syslog.syslog("reached a running gpsd") + elif action == 'add': + gpsdcmd = "gpsd %s -F %s" % (GPSD_OPTIONS, CONTROL_SOCKET) + syslog.syslog("launching %s" % gpsdcmd) + os.system(gpsdcmd) + connect = gpsd_control_connect(complain=True) + if not connect: + syslog.syslog("can't reach gpsd") + return None + # We've got a live connection to the gpsd control socket. No + # need to parse the response, because gpsd will lock on to the + # device if it's really a GPS and ignore it if it's not. + if action == 'add': + # Force the group-read & group-write bits on, so gpsd will still be + # able to use this device after dropping root privileges. + os.chmod(argument, stat.S_IMODE(os.stat(argument)[stat.ST_MODE])|0660) + connect.sendall("+%s\r\n" % argument) + connect.recv(12) + elif action == 'remove': + connect.sendall("-%s\r\n" % argument) + connect.recv(12) + elif action == 'send': + connect.sendall("%s\r\n" % argument) + connect.recv(12) + connect.close() + #syslog.syslog("gpsd_control ends") + return action + +def hotplug(action, devpath): + #syslog.syslog("ACTION=%s DEVPATH=%s" % (action,devpath)) + if not devpath: + syslog.syslog("No device") + else: + subnodes = glob.glob("/sys" + devpath + "/*") + subnodes = map(os.path.basename, subnodes) + subnodes = filter(lambda s: s.startswith("ttyUSB"), subnodes) + if len(subnodes) == 0: + syslog.syslog("no ttyUSB device under " + devpath) + return + elif len(subnodes) > 1: + syslog.syslog("too many ttyUSB devices under " + devpath) + return + else: + tty = "/dev/" + subnodes[0] + + syslog.syslog("waiting for " + tty) + while not os.path.exists(tty): + time.sleep(1) + syslog.syslog(tty + " has gone active") + + gpsd_control(action, tty) + + remover = os.getenv("REMOVER") + #syslog.syslog("REMOVER=%s" % remover) + fp = open(remover, "w") + fp.write(WHEREAMI + " remove " + tty) + fp.close() + os.chmod(remover, stat.S_IRUSR|stat.S_IXUSR|stat.S_IRGRP|stat.S_IXGRP) + return + +if __name__ == '__main__': + # In recent versions of udev, the gpsd script runs in series with + # the task that creates the real /dev/ttyUSB0 device + # node. Unfortunately, the gpsd script runs BEFORE the creation of + # the node, and the node is not created until after you kill the + # gpsd script, because the gpsd script waits forever for the node + # to appear. + # + # This is a race condition, and is best fixed by running the + # actual wait/hotplug portion in the background. + pid = os.fork() + if not pid: + syslog.openlog('gpsd.hotplug', 0, syslog.LOG_DAEMON) + try: + if len(sys.argv) == 1: # Called as hotplug script + hotplug(os.getenv("ACTION"), os.getenv("DEVPATH")) + else: # Called by hand for testing + gpsd_control(sys.argv[1], sys.argv[2]) + except: + (exc_type, exc_value, exc_traceback) = sys.exc_info() + syslog.syslog("gpsd.hotplug: exception %s yields %s" % (exc_type, exc_value)) + raise exc_type, exc_value, exc_traceback + #syslog.syslog("gpsd.hotplug ends") + syslog.closelog() + diff --git a/system/gpsd/gpsd.hotplug.wrapper b/system/gpsd/gpsd.hotplug.wrapper new file mode 100644 index 0000000000..429db379ce --- /dev/null +++ b/system/gpsd/gpsd.hotplug.wrapper @@ -0,0 +1,41 @@ +#!/bin/sh +# +# This file is Copyright (c) 2010 by the GPSD project +# BSD terms apply: see the file COPYING in the distribution root for details. +# [Modified to add Slackware-friendly conf file] + +PATH=/usr/sbin:$PATH +export PATH + +if [ -r /etc/default/gpsd ]; then + . /etc/default/gpsd +elif [ -r /etc/sysconfig/gpsd ]; then + . /etc/sysconfig/gpsd + GPSD_OPTIONS=$OPTIONS + GPSD_SOCKET=$CONTROL_SOCKET +elif [ -r /etc/rc.d/rc.gpsd.conf ]; then + . /etc/rc.d/rc.gpsd.conf +fi + +if [ -n "$GPSD_OPTIONS" ]; then + export GPSD_OPTIONS +fi +if [ -n "$GPSD_SOCKET" ]; then + export GPSD_SOCKET +fi + +if [ -n "$USBAUTO" ]; then + [ "$USBAUTO" = "true" ] || exit 0 +fi + +if [ "$ACTION" = "remove" ] ; then + if echo $DEVLINKS | grep -q /dev/gps; then + exec /lib/udev/gpsd.hotplug "$ACTION" "$DEVNAME" + fi + exit 0 +fi + +if [ -x /usr/bin/python ]; then + exec /lib/udev/gpsd.hotplug "$ACTION" "$DEVNAME" +fi + diff --git a/system/gpsd/gpsd.info b/system/gpsd/gpsd.info index 47d9e66b96..f62ee8172f 100644 --- a/system/gpsd/gpsd.info +++ b/system/gpsd/gpsd.info @@ -1,10 +1,10 @@ PRGNAM="gpsd" -VERSION="2.96" +VERSION="2.95" HOMEPAGE="http://gpsd.berlios.de/" -DOWNLOAD="http://download.berlios.de/gpsd/gpsd-2.96bis.tar.gz" -MD5SUM="52b00cab0fb34bbf1923ae35c7ced6c4" +DOWNLOAD="http://download.berlios.de/gpsd/gpsd-2.95.tar.gz" +MD5SUM="12535a9ed9fecf9ea2c5bdc9840da5ae" DOWNLOAD_x86_64="" MD5SUM_x86_64="" MAINTAINER="David Spencer" EMAIL="baildon.research@googlemail.com" -APPROVED="Niels Horn" +APPROVED="dsomero" diff --git a/system/gpsd/rc.gpsd.conf.new b/system/gpsd/rc.gpsd.conf.new new file mode 100644 index 0000000000..3566b69c08 --- /dev/null +++ b/system/gpsd/rc.gpsd.conf.new @@ -0,0 +1,14 @@ +# /etc/rc.d/rc.gpsd.conf +# Configuration settings for gpsd + +# If your GPS is on a real (non-USB) serial port, add /dev/ttyS here, +# for example +# GPSD_DEVICES="/dev/gps* /dev/ttyS1" +GPSD_DEVICES="/dev/gps*" + +# Command line options for the gpsd daemon, see 'man gpsd' for details. +# The most likely options that you might want to set include -b and -n. +GPSD_OPTIONS="" + +# Control socket pathname. It's unlikely you'll want to change this. +GPSD_SOCKET="/var/run/gpsd.sock" diff --git a/system/gpsd/rc.gpsd.new b/system/gpsd/rc.gpsd.new new file mode 100644 index 0000000000..0eee30306a --- /dev/null +++ b/system/gpsd/rc.gpsd.new @@ -0,0 +1,60 @@ +#!/bin/sh + +# /etc/rc.d/rc.gpsd +# Start/stop/restart gpsd +# Sebastian Arcus and David Spencer +# +# To enable automatic discovery of your GPS device by udev, uncomment the +# appropriate line of /etc/udev/rules.d/97-gpsd.rules +# +# Configuration options may be set in /etc/rc.d/rc.gpsd.conf +# but the defaults will usually be adequate. + +gpsd_start() { + + if [ ! -x /lib/udev/gpsd.hotplug.wrapper ]; then + echo "$(basename $0): /lib/udev/gpsd.hotplug.wrapper not found (or not executable); cannot start." + fi + + if [ -r /etc/rc.d/rc.gpsd.conf ]; then + . /etc/rc.d/rc.gpsd.conf + fi + # Set config defaults in case the .conf file was absent or bogus + GPSD_DEVICES="${GPSD_DEVICES:-/dev/gps*}" + GPSD_OPTIONS="${GPSD_OPTIONS:-}" + GPSD_SOCKET="${GPSD_SOCKET:-/var/run/gpsd.sock}" + + for DEVNAME in $GPSD_DEVICES; do + if [ -e $DEVNAME ]; then + echo "$(basename $0): Starting gpsd for $DEVNAME" + ACTION=add DEVNAME=$DEVNAME /lib/udev/gpsd.hotplug.wrapper + else + echo "$(basename $0): $DEVNAME not found, gpsd not started" + fi + done + +} + +gpsd_stop() { + echo "Stopping gpsd..." + killall gpsd >/dev/null 2>&1 + return 0 +} + +case "$1" in + start) + gpsd_start + ;; + stop) + gpsd_stop + ;; + restart) + gpsd_stop + sleep 1 + gpsd_start + ;; + *) + echo "Usage: $0 start|stop|restart" + exit 1 + ;; +esac diff --git a/system/gpsd/slack-desc b/system/gpsd/slack-desc index 30eba3cd67..fd614fa133 100644 --- a/system/gpsd/slack-desc +++ b/system/gpsd/slack-desc @@ -8,11 +8,11 @@ |-----handy-ruler------------------------------------------------------| gpsd: gpsd (GPS service daemon) gpsd: -gpsd: gpsd is a service daemon that monitors one or more GPSes attached to -gpsd: a host computer through serial or USB ports, making all data on the -gpsd: location/course/velocity available to be queried on TCP port 2947 -gpsd: of the host computer. With gpsd, multiple GPS client applications -gpsd: (such as navigational and wardriving software) can share access to +gpsd: gpsd is a service daemon that monitors one or more GPSes attached to +gpsd: a host computer through serial or USB ports, making all data on the +gpsd: location/course/velocity available to be queried on TCP port 2947 +gpsd: of the host computer. With gpsd, multiple GPS client applications +gpsd: (such as navigational and wardriving software) can share access to gpsd: GPSes without contention or loss of data. gpsd: gpsd: Homepage: http://gpsd.berlios.de/ diff --git a/system/gpsd/xgps.desktop b/system/gpsd/xgps.desktop new file mode 100644 index 0000000000..dc61b1264b --- /dev/null +++ b/system/gpsd/xgps.desktop @@ -0,0 +1,9 @@ +[Desktop Entry] +Name=xgps +GenericName=GPS information +Comment=Display GPS information from a gpsd daemon +Exec=xgps +Icon=/usr/share/pixmaps/gpsd-logo.png +Terminal=false +Type=Application +Categories=Utility; diff --git a/system/gpsd/xgpsspeed.desktop b/system/gpsd/xgpsspeed.desktop new file mode 100644 index 0000000000..c327074411 --- /dev/null +++ b/system/gpsd/xgpsspeed.desktop @@ -0,0 +1,9 @@ +[Desktop Entry] +Name=xgpsspeed +GenericName=GPS speedometer +Comment=Display GPS speed from a gpsd daemon +Exec=xgpsspeed +Icon=/usr/share/pixmaps/gpsd-logo.png +Terminal=false +Type=Application +Categories=Utility; -- cgit v1.2.3