1#!/bin/sh
2
3# This file is part of sane-backends.
4#
5# This script changes the permissions and ownership of a USB device under
6# /proc/bus/usb to grant access to this device to users in the scanner group.
7#
8# Ownership is set to root:scanner, permissions are set to 0660.
9#
10# Arguments :
11# -----------
12# ACTION=[add|remove]
13# DEVICE=/proc/bus/usb/BBB/DDD
14# TYPE=usb
15
16# latest hotplug doesn't set DEVICE on 2.6.x kernels
17if [ -z "$DEVICE" ] ; then
18  IF=`echo $DEVPATH | sed 's/\(bus\/usb\/devices\/\)\(.*\)-\(.*\)/\2/'`
19  DEV=$(cat /sys/${DEVPATH}/devnum)
20  DEVICE=`printf '/proc/bus/usb/%.03d/%.03d' $IF $DEV`
21fi
22
23if [ "$ACTION" = "add" -a "$TYPE" = "usb" ]; then
24  chown root:scanner "$DEVICE"
25  chmod 0660 "$DEVICE"
26fi
27
28
29# That's an insecure but simple alternative
30# Everyone has access to the scanner
31
32# if [ "$ACTION" = "add" -a "$TYPE" = "usb" ]; then
33#  chmod 0666 "$DEVICE"
34# fi
35