1141cc406Sopenharmony_ci#!/bin/sh
2141cc406Sopenharmony_ci
3141cc406Sopenharmony_ci# This file is part of sane-backends.
4141cc406Sopenharmony_ci#
5141cc406Sopenharmony_ci# This script changes the permissions and ownership of a USB device under
6141cc406Sopenharmony_ci# /proc/bus/usb to grant access to this device to users in the scanner group.
7141cc406Sopenharmony_ci#
8141cc406Sopenharmony_ci# Ownership is set to root:scanner, permissions are set to 0660.
9141cc406Sopenharmony_ci#
10141cc406Sopenharmony_ci# Arguments :
11141cc406Sopenharmony_ci# -----------
12141cc406Sopenharmony_ci# ACTION=[add|remove]
13141cc406Sopenharmony_ci# DEVICE=/proc/bus/usb/BBB/DDD
14141cc406Sopenharmony_ci# TYPE=usb
15141cc406Sopenharmony_ci
16141cc406Sopenharmony_ci# latest hotplug doesn't set DEVICE on 2.6.x kernels
17141cc406Sopenharmony_ciif [ -z "$DEVICE" ] ; then
18141cc406Sopenharmony_ci  IF=`echo $DEVPATH | sed 's/\(bus\/usb\/devices\/\)\(.*\)-\(.*\)/\2/'`
19141cc406Sopenharmony_ci  DEV=$(cat /sys/${DEVPATH}/devnum)
20141cc406Sopenharmony_ci  DEVICE=`printf '/proc/bus/usb/%.03d/%.03d' $IF $DEV`
21141cc406Sopenharmony_cifi
22141cc406Sopenharmony_ci
23141cc406Sopenharmony_ciif [ "$ACTION" = "add" -a "$TYPE" = "usb" ]; then
24141cc406Sopenharmony_ci  chown root:scanner "$DEVICE"
25141cc406Sopenharmony_ci  chmod 0660 "$DEVICE"
26141cc406Sopenharmony_cifi
27141cc406Sopenharmony_ci
28141cc406Sopenharmony_ci
29141cc406Sopenharmony_ci# That's an insecure but simple alternative
30141cc406Sopenharmony_ci# Everyone has access to the scanner
31141cc406Sopenharmony_ci
32141cc406Sopenharmony_ci# if [ "$ACTION" = "add" -a "$TYPE" = "usb" ]; then
33141cc406Sopenharmony_ci#  chmod 0666 "$DEVICE"
34141cc406Sopenharmony_ci# fi
35