Files
libgphoto2/packaging/linux-hotplug/usbcam.console
2002-05-10 19:15:56 +00:00

56 lines
2.0 KiB
Bash
Executable File

#!/bin/bash
# $Id$
#
# /etc/hotplug/usb/usbcam
#
# Sets up newly plugged in USB camera so that the user who owns
# the console according to pam_console can access it from user space
#
# Note that for this script to work, you'll need all of the following:
# a) a line in the file /etc/hotplug/usermap that corresponds to the
# camera you are using. You can get the correct lines for all cameras
# supported by gphoto2 by running "gphoto2 --print-usb-usermap".
# b) a setup using pam_console creates the respective lock files
# containing the name of the respective user. You can check for that
# by executing "echo `cat /var/{run,lock}/console.lock`" and
# verifying the appropriate user is mentioned somewhere there.
# c) a Linux kernel supporting hotplug and usbdevfs
# d) the hotplug package (http://linux-hotplug.sourceforge.net/)
#
# In the usermap file, the first field "usb module" should be named
# "usbcam" like this script.
#
if [ "${ACTION}" = "add" ] && [ -f "${DEVICE}" ]
then
# New code, using lock files instead of /dev/console permissions
# This also works with non-gdm logins (e.g. on a virtual terminal)
# Idea and code from Nalin Dahyabhai <nalin@redhat.com>
if [ -f /var/run/console.lock ]
then
CONSOLEOWNER=`cat /var/run/console.lock`
elif [ -f /var/lock/console.lock ]
then
CONSOLEOWNER=`cat /var/lock/console.lock`
else
CONSOLEOWNER=
fi
if [ -n "$CONSOLEOWNER" ]
then
chown 0000 "${DEVICE}"
chown "$CONSOLEOWNER" "${DEVICE}"
chown 0600 "${DEVICE}"
fi
# old code, using traditional parameters and /dev/console permissions
# user="$(ls -l /dev/console | awk '/\/dev\/console$/ { print $3; }')"
# chown "${user}" "${DEVICE}"
# chmod 0600 "${DEVICE}"
# new code, using GNU style parameters and /dev/console permissions
# CONSOLE="/dev/console"
# chown 0000 "${DEVICE}" # precaution against possible race conditions
# chown --reference "${CONSOLE}" "${DEVICE}"
# chmod --reference "${CONSOLE}" "${DEVICE}"
fi