not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / kcontrol / input / consoleUserPerms
blob015df642f11bc9b7bc73d03ba33f07cf5fab375d
1 #!/bin/bash
3 # /etc/hotplug/usb/consoleUserPerms
5 # Sets up newly plugged in USB device so that the user who owns
6 # the console according to pam_console can access it from user space
8 # Note that for this script to work, you'll need all of the following:
9 # a) a line in the file /etc/hotplug/usb.usermap or another usermap file
10 # in /etc/hotplug/usb/ that corresponds to the device you are using.
11 # b) a setup using pam_console creates the respective lock files
12 # containing the name of the respective user. You can check for that
13 # by executing "echo `cat /var/{run,lock}/console.lock`" and
14 # verifying the appropriate user is mentioned somewhere there.
15 # c) a Linux kernel supporting hotplug and usbdevfs
16 # d) the hotplug package (http://linux-hotplug.sourceforge.net/)
18 # In the usermap file, the first field "usb module" should be named
19 # "consoleUserPerms" to invoke this script.
22 if [ "${ACTION}" = "add" ] && [ -f "${DEVICE}" ]
23 then
24 # New code, using lock files instead of copying /dev/console permissions
25 # This also works with non-kdm logins (e.g. on a virtual terminal)
26 # Idea and code from Nalin Dahyabhai <nalin@redhat.com>
27 if [ -f /var/run/console.lock ]
28 then
29 CONSOLEOWNER=`cat /var/run/console.lock`
30 elif [ -f /var/lock/console.lock ]
31 then
32 CONSOLEOWNER=`cat /var/lock/console.lock`
33 else
34 CONSOLEOWNER=
36 if [ -n "$CONSOLEOWNER" ]
37 then
38 chmod 0000 "${DEVICE}"
39 chown "$CONSOLEOWNER" "${DEVICE}"
40 chmod 0600 "${DEVICE}"