Source code upload
[framework/connectivity/libgphoto2.git] / packaging / linux-hotplug / usbcam.x11-app
1 #!/bin/bash
2 # $Id: usbcam.x11-app 9668 2006-12-18 16:31:44Z hun $
3 #
4 # /etc/hotplug/usb/usbcam
5 #
6 # Sets up newly plugged in USB camera so that just one certain user
7
8 USER=root
9
10 # can access it from user space. (Replace root by the user you want
11 # to have access to the cameras.)
12
13 # It then runs the X11 application (gtkam is used as an example)
14
15 X11_APP=/usr/bin/gtkam
16
17 # on the X11 display (:0 should work on most single user workstations)
18
19 DISPLAY=:0
20
21 # in the directory (~$USER is just the user's home directory)
22
23 DIRECTORY=~$USER
24
25 #
26 # Note that for this script to work, you'll need all of the following:
27 # a) a line in the file /etc/hotplug/usermap that corresponds to the 
28 #    camera you are using. You can get the correct lines for all cameras 
29 #    supported by libgphoto2 by running
30 #              $ print-camera-list usb-usermap usbcam
31 # b) run your camera software as the user given above
32 # c) a Linux kernel supporting hotplug and usbdevfs
33 # d) the hotplug package (http://linux-hotplug.sourceforge.net/)
34 # e) su
35 # f) env
36 # g) X11
37 #
38 # In the usermap file, the first field "usb module" should be named 
39 # "usbcam" like this script.
40 #
41 # Script written by Trevor Woerner but slightly adapted for inclusion
42 # into libgphoto2. 
43
44 SU=/bin/su
45 ENV=/usr/bin/env
46
47 if [ "${ACTION}" = "add" ] && [ -f "${DEVICE}" ]
48 then
49     chmod a-rwx "${DEVICE}"
50     chown "${USER}" "${DEVICE}"
51     chmod u+rw "${DEVICE}"
52
53     if [ "${USER}" != "root" ]
54     then
55         # we don't want to run this as root. definitely not.
56         cd "${DIRECTORY}"
57         usrhome=~${USER}
58         "${SU}" "${USER}" -c "${ENV} DISPLAY=${DISPLAY} HOME=${usrhome} ${X11_APP}"
59     fi
60 fi