From 309228e9db43c2cc9408622e174f5accd4bdc9bf Mon Sep 17 00:00:00 2001 From: Julien BLACHE Date: Mon, 21 Feb 2005 21:00:57 +0000 Subject: [PATCH] Added new hotplug/hotplug-ng hook with scripts and documentation. --- ChangeLog | 4 +++ tools/hotplug-ng/README | 50 +++++++++++++++++++++++++++++ tools/hotplug-ng/convert-usermap.sh | 28 ++++++++++++++++ tools/hotplug-ng/libsane.hotplug | 29 +++++++++++++++++ 4 files changed, 111 insertions(+) create mode 100644 tools/hotplug-ng/README create mode 100755 tools/hotplug-ng/convert-usermap.sh create mode 100755 tools/hotplug-ng/libsane.hotplug diff --git a/ChangeLog b/ChangeLog index dda22183b..7b17cd805 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2005-02-21 Julien Blache + * tools/hotplug-ng: added new hotplug/hotplug-ng hook, with + scripts and documentation. + 2005-02-20 Henning Meier-Geinitz * doc/descriptions/unsupported.desc: Removed Genius diff --git a/tools/hotplug-ng/README b/tools/hotplug-ng/README new file mode 100644 index 000000000..b2a0ba91d --- /dev/null +++ b/tools/hotplug-ng/README @@ -0,0 +1,50 @@ +hotplug/hotplug-ng hook for sane-backends +----------------------------------------- + +The libsane.hotplug script is intended to replace the existing hotplug scripts, +as those won't be usable with the new hotplug-ng. The libsane.hotplug script +works with both hotplug and hotplug-ng. + +This script is provided in the hope that it will be useful, simpler, faster and +more extensible than the current usermap approach. + + +INSTALLATION +------------ + +Install libsane.hotplug in /etc/hotplug/usb, and make it executable. + +Create the directory /etc/sane.d/hotplug, then run the convert-usermap.sh +script on libsane.usermap to produce the libsane.db file: + $ ./convert-usermap.sh libsane.usermap + +The libsane.usermap file can be found in the tools/hotplug directory; for now +the usermap file remains the authoritative source for the list of USB scanners. + + +FILE FORMAT +----------- + +The libsane.db contains 5 tab-separated fields: + +0xVVVV0xPPPProot:scanner0660optional_script + +Fields: + - vendor ID + - product ID + - ownership (user:group) + - permissions + - path of an optional script to run (it can be omitted) + + +USAGE +----- + +When run by hotplug/hotplug-ng, the libsane.hotplug script will grep for +^0xVVVV[[:space:]]0xPPPP in /etc/sane.d/hotplug/*.db. If a match is found, +the settings are applied to the device. + +The optional script is then run; this script can access the environment +variables set by hotplug/hotplug-ng (see the documentation). The libsane.hotplug +script will also set and export the DEVVID and DEVPID variables, containing the +vendor and device ID of the scanner (of the form VVVV and PPPP). diff --git a/tools/hotplug-ng/convert-usermap.sh b/tools/hotplug-ng/convert-usermap.sh new file mode 100755 index 000000000..215864115 --- /dev/null +++ b/tools/hotplug-ng/convert-usermap.sh @@ -0,0 +1,28 @@ +#!/bin/bash +# +# Converts libsane.usermap to the new SANE hotplug db +# + +if [ ! -e libsane.db ]; then + cat > libsane.db <0xPPPProot:scanner0660[/usr/local/bin/foo.sh] +# + +EOF +fi + +cat "$1" | { while read map; do + if $(echo "$map" | grep -q ^# > /dev/null); then + echo $map >> libsane.db + else + set $map + + echo -e "$3\t$4\troot:scanner\t0660\t" >> libsane.db + fi +done } + +exit 0 diff --git a/tools/hotplug-ng/libsane.hotplug b/tools/hotplug-ng/libsane.hotplug new file mode 100755 index 000000000..7310c1e73 --- /dev/null +++ b/tools/hotplug-ng/libsane.hotplug @@ -0,0 +1,29 @@ +#!/bin/sh +# +# This file is part of the SANE distribution. +# Hotplug USB hook for SANE + +if [ "$ACTION" != "add" ]; then + exit 0 +fi + +DEVVID=$(printf %4s $(echo $PRODUCT | cut -d'/' -f1) | tr ' ' 0) +DEVPID=$(printf %4s $(echo $PRODUCT | cut -d'/' -f2) | tr ' ' 0) + +DEVCONF=$(grep -i ^0x$DEVVID\t0x$DEVPID /etc/sane.d/hotplug/*.db 2> /dev/null) + +if [ $? != 0 ]; then + exit 0 +fi + +set $DEVCONF + +chown $3 $DEVICE && chmod $4 $DEVICE + +if [ ! -z $5 -a -x $5 ]; then + export DEVVID + export DEVPID + exec $5 +fi + +exit 0