501cc4d
#!/bin/bash
501cc4d
#
0cb5210
# /sbin/libifp-hotplug
501cc4d
# 
501cc4d
# Cloned off the usbcam hotplug script that is shipped by 
501cc4d
# Red Hat with gphoto2. In principle we could just call that one,
501cc4d
# but it's ugly to depend on a camera driver in order to talk
501cc4d
# to an audio player...
501cc4d
#
501cc4d
# Sets up newly plugged-in iRiver iFP device so that the user who owns
501cc4d
# the console according to pam_console can access it from user space
501cc4d
#
501cc4d
# Note that for this script to work, you'll need all of the following:
501cc4d
# a) a line in the file /etc/hotplug/usb/libifp.usermap that corresponds 
501cc4d
#    to the iFP device you are using.
501cc4d
# b) a setup using pam_console creates the respective lock files
501cc4d
#    containing the name of the respective user. You can check for that
501cc4d
#    by executing "echo `cat /var/{run,lock}/console.lock`" and 
501cc4d
#    verifying the appropriate user is mentioned somewhere there.
501cc4d
# c) a Linux kernel supporting hotplug and usbdevfs
501cc4d
# d) the hotplug package (http://linux-hotplug.sourceforge.net/)
501cc4d
#
501cc4d
# All of the above are expected to be true on recent Red Hat and Fedora
501cc4d
# distributions in the default install.
501cc4d
#
501cc4d
# In the usermap file, the first field "usb module" should be named 
501cc4d
# "libifp" like this script.
501cc4d
# 
501cc4d
501cc4d
if [ "${ACTION}" = "add" ] && [ -f "${DEVICE}" ]
501cc4d
then
501cc4d
    # New code, using lock files instead of copying /dev/console permissions
501cc4d
    # This also works with non-gdm logins (e.g. on a virtual terminal)
501cc4d
    # Idea and code from Nalin Dahyabhai <nalin@redhat.com>
501cc4d
    if [ -f /var/run/console/console.lock ]
501cc4d
    then
501cc4d
        CONSOLEOWNER=`cat /var/run/console/console.lock`
501cc4d
    elif [ -f /var/lock/console.lock ]
501cc4d
    then
501cc4d
        CONSOLEOWNER=`cat /var/lock/console.lock`
501cc4d
    else
501cc4d
        CONSOLEOWNER=
501cc4d
    fi
501cc4d
    if [ -n "$CONSOLEOWNER" ]
501cc4d
    then
501cc4d
        chmod 0000 "${DEVICE}"
501cc4d
        chown "$CONSOLEOWNER" "${DEVICE}"
501cc4d
        chmod 0600 "${DEVICE}"
501cc4d
    fi
501cc4d
fi