packages/utils/sane-backends/files/saned.hotplug
Luiz Angelo Daros de Luca 794c950b32 sane-backends: run (xinetd) saned as non-root
saned requires write access scanner USB bus for its process and
to usblp/bind in order to rebind multifunctional printers back
to usblp (for printing with p910nd).

A hotplug script monitor new USB devices for scanners. Scanners
are detected by searching /usr/share/sane/<vendor>-<backend>.usbid
for the device product_id.

The package saned creates user saned:scanners. Access is granted to
group scanners.

The default xinetd conf was updated to run as saned:scanner.

sane-daemon pkg now has a postinst trigger that runs udevtrigger for
granting perms where there are connected scanners during installation.

Existing hotplug scripts from hplip were removed. They were mostly
useless.

Signed-off-by: Luiz Angelo Daros de Luca <luizluca@gmail.com>
2019-12-21 20:44:56 -03:00

27 lines
745 B
Bash
Executable file

#!/bin/sh
[ "$ACTION" = "add" ] || exit 0
[ "$DEVTYPE" = "usb_device" ] || exit 0
SANE_GROUP=scanner
grep -q -E "^$SANE_GROUP:" /etc/group || exit 0
# Filter SANE known devices
vendor_product="${PRODUCT%/*}"
vendorid="$(printf '%04x' "0x0${vendor_product%/*}")"
productid="$(printf '%04x' "0x0${vendor_product#*/}")"
grep -s -x -F -q "$productid" "/usr/share/sane/$vendorid"-*.usbid || exit 0
grant() {
logger -t "hotplug(usb/20-saned)" "Granting $1 to '$2' for group '$SANE_GROUP'"
chgrp "$SANE_GROUP" "$2"
chmod "$1" "$2"
}
# Needed by script /usr/bin/saned to rebind USB devices back to usblp after use
usblp_bind="/sys/bus/usb/drivers/usblp/bind"
if [ -e "$usblp_bind" ]; then
grant g+w "$usblp_bind"
fi
grant g+rw "/dev/$DEVNAME"