gpsd.hotplug 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/bin/sh
  2. #
  3. # This script is the gpsd udev handler for add/remove events on matched USB
  4. # devices. It expects to see the following environment variables:
  5. #
  6. # ACTION = either "add" or "remove"
  7. # DEVNAME = the full name of the USB device that was just activated
  8. #
  9. # It will accept from /etc/sysconfig/gpsd the following config variables:
  10. #
  11. # CONTROL_SOCKET = location of the gpsd control socket
  12. # OPTIONS = options to be passed to gpsd on launch
  13. #
  14. # It hands off to gpsdctl for the actual communication with the daemon.
  15. #
  16. # Do not introduce bashims into this script, as we want it to continue to
  17. # work under Ubuntu.
  18. #
  19. # This file is Copyright 2010 by the GPSD project
  20. # SPDX-License-Identifier: BSD-2-clause
  21. PATH=/usr/sbin:$PATH
  22. export PATH
  23. if [ -r /etc/default/gpsd ]; then
  24. . /etc/default/gpsd
  25. elif [ -r /etc/conf.d/gpsd ]; then
  26. . /etc/conf.d/gpsd
  27. elif [ -r /etc/sysconfig/gpsd ]; then
  28. . /etc/sysconfig/gpsd
  29. GPSD_OPTIONS=$OPTIONS
  30. GPSD_SOCKET=$CONTROL_SOCKET
  31. fi
  32. if [ -n "$GPSD_OPTIONS" ]; then
  33. export GPSD_OPTIONS
  34. fi
  35. if [ -n "$GPSD_SOCKET" ]; then
  36. export GPSD_SOCKET
  37. fi
  38. if [ -n "$USBAUTO" ]; then
  39. [ "$USBAUTO" = "true" ] || exit 0
  40. fi
  41. if [ "$ACTION" = "remove" ] ; then
  42. if echo $DEVLINKS | grep -q /dev/gps; then
  43. :
  44. else
  45. exit 0
  46. fi
  47. fi
  48. logger -t "gpsd.hotplug" -p daemon.info "$ACTION" "$DEVNAME"
  49. if [ -z "$DEVNAME" ]
  50. then
  51. logger -t gpsd.hotplug -p daemon.err "no device"
  52. exit 0
  53. fi
  54. # In recent versions of udev, the gpsd script runs in series with
  55. # the task that creates the real /dev/ttyUSBn device
  56. # node. Unfortunately, the gpsd script runs BEFORE the creation of
  57. # the node, and the node is not created until after you kill the
  58. # gpsd script, because the gpsd script waits forever for the node
  59. # to appear.
  60. #
  61. # This is a race condition, and is best fixed by running the
  62. # actual wait/hotplug portion in the background.
  63. {
  64. #logger -t gpsd.hotplug -p daemon.info "waiting for" $DEVNAME
  65. while [ -x $DEVNAME ]
  66. do
  67. sleep 1
  68. done
  69. #logger -t gpsd.hotplug -p daemon.info $DEVNAME "is active"
  70. gpsdctl $ACTION $DEVNAME
  71. } &
  72. # vim: set expandtab shiftwidth=4