home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / share / doc / libgphoto2-2 / linux-hotplug / usbcam.console next >
Encoding:
Text File  |  2006-08-30  |  1.6 KB  |  46 lines

  1. #!/bin/bash
  2. # $Id: usbcam.console 7452 2004-12-21 10:53:01Z hun $
  3. #
  4. # /etc/hotplug/usb/usbcam
  5. #
  6. # Sets up newly plugged in USB camera so that the user who owns
  7. # the console according to pam_console can access it from user space
  8. #
  9. # Note that for this script to work, you'll need all of the following:
  10. # a) a line in the file /etc/hotplug/usermap that corresponds to the 
  11. #    camera you are using. You can get the correct lines for all cameras 
  12. #    supported by libgphoto2 by running "print-usb-usermap".
  13. # b) a setup using pam_console creates the respective lock files
  14. #    containing the name of the respective user. You can check for that
  15. #    by executing "echo `cat /var/{run,lock}/console.lock`" and 
  16. #    verifying the appropriate user is mentioned somewhere there.
  17. # c) a Linux kernel supporting hotplug and usbdevfs
  18. # d) the hotplug package (http://linux-hotplug.sourceforge.net/)
  19. #
  20. # In the usermap file, the first field "usb module" should be named 
  21. # "usbcam" like this script.
  22.  
  23. if [ "${ACTION}" = "add" ] && [ -f "${DEVICE}" ]
  24. then
  25.     # New code, using lock files instead of copying /dev/console permissions
  26.     # This also works with non-gdm logins (e.g. on a virtual terminal)
  27.     # Idea and code from Nalin Dahyabhai <nalin@redhat.com>
  28.     CONSOLEOWNER=""
  29.     for conlock in \
  30.         /var/run/console.lock \
  31.         /var/run/console/console.lock \
  32.         /var/lock/console.lock
  33.     do
  34.         if [ -f "$conlock" ]; then
  35.         CONSOLEOWNER=`cat $conlock`
  36.         fi
  37.     done
  38.     if [ -n "$CONSOLEOWNER" ]
  39.     then
  40.         chmod 0000 "${DEVICE}"
  41.         chown "$CONSOLEOWNER" "${DEVICE}"
  42.         chmod 0600 "${DEVICE}"
  43.     fi
  44. fi
  45.