:: Re: [DNG] vdev - scanner
Forside
Slet denne besked
Besvar denne besked
Skribent: fsmithred
Dato:  
Til: Ralph Ronnquist, dng
Emne: Re: [DNG] vdev - scanner
On 08/16/2016 08:35 PM, fsmithred wrote:
> On 08/16/2016 07:54 PM, Ralph Ronnquist wrote:
>> fsmithred wrote on 17/08/16 09:34:
>>> On 08/16/2016 12:49 PM, shraptor wrote:
>>>> On 2016-08-16 18:19, shraptor wrote:
>>>>> On 2016-08-16 18:11, shraptor wrote:
>>>>>>> I got the scanner working.
>>>>>>>
>>>>>>> If I boot with udev, the scanner works, and the permissions on the
>>>>>>> device
>>>>>>> look like this:
>>>>>>>
>>>>>>> ls -l /dev/bus/usb/002/
>>>>>>> crw-rw-r--+ 1 root root 189, 137 Aug 16 10:30 010
>>>>>>>
>>>>>>> and with vdev, it looks like this:
>>>>>>> crw------- 1 root root 189, 131 Aug 16 10:39 004
>>>>>>>
>>>>>>> I changed the permissions and added myself to the scanner group (oops!)
>>>>>>> and now xsane finds the scanner when I'm running vdev. I hope someone
>>>>>>> knows what to do with this information, because I'm in new territory
>>>>>>> here.
>>>>>>> (and I don't know C.)
>>>>>>>
>>>>>>> If udevadm output for the scanner would help, I'll post it. The udev
>>>>>>> rules
>>>>>>> for scanners are in /lib/udev/rules.d/60-libsane.rules
>>>>>>
>>>>>>
>>>>>> Maybe you should write a vdev action for your scanner
>>>>>> on my system they actions are in /etc/vdev/actions
>>>>>>
>>>>>> for instance optical.act contains
>>>>>>
>>>>>> [vdev-action]
>>>>>> event=any
>>>>>> path=^sr[0-9]*$
>>>>>> VAR_OPTICAL_OWNER=root
>>>>>> VAR_OPTICAL_GROUP=optical
>>>>>> VAR_OPTICAL_MODE=0660
>>>>>> helper=optical.sh
>>>>>> daemonlet=true
>>>>>> if_exists=run
>>>>>>
>>>>>>
>>>>>>
>>>>>> No C is needed. Write something that matches path like for optical
>>>>>> path=^sr[0-9]*$
>>>>>> then set needed permissions and group and vdev will fix it for you
>>>>>>
>>>>>>
>>>>>> When you succeed you may contribute that .act file for others, yeah?
>>>>>
>>>>>
>>>>> Maybe you can use something like null.act
>>>>>
>>>>> [vdev-action]
>>>>> event=add
>>>>> path=^null$
>>>>> VAR_PERMISSIONS_MODE=0666
>>>>> helper=permissions.sh
>>>>> if_exists=run
>>>>>
>>>>>
>>>>>
>>>>> I mean the permissions.sh
>>>>>
>>>>>
>>>>> so something like
>>>>>
>>>>> scanner.act
>>>>>
>>>>> [vdev-action]
>>>>> event=add
>>>>> path=^null$
>>>>
>>>>> VAR_PERMISSIONS_MODE=0664
>>>>> helper=permissions.sh
>>>>> if_exists=run
>>>>>
>>>>> Dunnow wot path you should use but maybe you could figure it out?
>>>>
>>>>
>>>> perhaps?
>>>>
>>>> scanner.act
>>>>
>>>> [vdev-action]
>>>> event=add
>>>> path=^bus/usb/1$
>>>> VAR_OWNER=root
>>>> VAR_GROUP=scanner
>>>> VAR_PERMISSIONS_MODE=0664
>>>> helper=permissions.sh
>>>> if_exists=run
>>>>
>>>>
>>>> Does debian use something like /dev/usbscanner0 or /dev/usb/scanner0?
>>>> Then maybe a new helper scanner.sh is needed, like optical.sh?
>>>>
>>>> In the beginning of vdev creation we dreamt of a udev rules to vdev action
>>>> parser
>>>>
>>>>
>>>
>>> I now have a better idea of what such dreams would entail. Getting close...
>>>
>>>
>>> This mostly works. I can get the right permissions on the device, but when
>>> I add the setfacl command, vdev fails. Error is "Invalid action" and it
>>> lists /usr/etc/vdev/actions/scanner.act. If I run the command in the
>>> console, it works correctly. I tried it with the command before and after
>>> "if_exists=run".
>>>
>>>
>>> [vdev-action]
>>> event=add
>>> path=^bus/usb/*/[001-999]
>>> OS_SUBSYSTEM=usb
>>> OS_TYPE=255/255/255
>>> VAR_OWNER=root
>>> VAR_GROUP=scanner
>>> VAR_PERMISSIONS_MODE=0664
>>> helper=permissions.sh
>>> if_exists=run
>>> command:/usr/bin/setfacl -m g:scanner:rw $VDEV_MOUNTPOINT/$VDEV_PATH
>>>
>>> Any ideas on how to get setfacl to work are welcome. Thanks.
>>>
>>
>> devuan% which setfacl
>> /bin/setfacl
>>
>> maybe? Ralph.
>
> That's weird. When I run 'which setfacl' I'm told it's at
> /usr/bin/setfacl. On further examination, that's a symlink to
> /bin/setfacl. Changing it in the action file didn't make a difference.
>
> Assuming this will eventually work, would daemonlet=true need to be added
> to get vdev to deal with plugging and unplugging the scanner after boot?
>
> -fsr
>


I got it to work. Here's the action file and the helper script. The helper
script is a modified permissions.sh. I added a test for $VDEV_MAJOR and
$VDEV_MINOR to trigger setfacl. Scanner now works on my installation.

The scanner doesn't work when I'm running from a live usb. It seems that
aufs does not support acls. If I boot with udev, the scanner gets the acl
and works. I don't know how udev gets around the aufs problem. I also
don't know how it will work with newer versions of live-config and
live-boot that use overlayfs instead.

-fsr

/etc/vdev/actions/scanner.act

[vdev-action]
event=add
path=^bus/usb/*/[001-999]
OS_SUBSYSTEM=usb
OS_TYPE=255/255/255
VAR_OWNER=root
VAR_GROUP=scanner
VAR_PERMISSIONS_MODE=0664
helper=scanner.sh
if_exists=run


/lib/vdev/scanner.sh

#!/bin/dash

# vdevd helper to set permissions and ownership.
# takes the owner from the VDEV_VAR_PERMISSIONS_OWNER environment variable.
# takes the group from the VDEV_VAR_PERMISSIONS_GROUP environment variable.
# takes the mode from the VDEV_VAR_PERMISSIONS_MODE environment variable

# entry point
main() {

    if [ -n "$VDEV_VAR_PERMISSIONS_OWNER" ] && [ -n
"$VDEV_VAR_PERMISSIONS_GROUP" ]; then


        /bin/chown
"$VDEV_VAR_PERMISSIONS_OWNER":"$VDEV_VAR_PERMISSIONS_GROUP"
"$VDEV_MOUNTPOINT/$VDEV_PATH"
    elif [ -n "$VDEV_VAR_PERMISSIONS_OWNER" ]; then


        /bin/chown "$VDEV_VAR_PERMISSIONS_OWNER" "$VDEV_MOUNTPOINT/$VDEV_PATH"
    elif [ -n "$VDEV_VAR_PERMISSIONS_GROUP" ]; then


        /bin/chgrp "$VDEV_VAR_PERMISSIONS_GROUP" "$VDEV_MOUNTPOINT/$VDEV_PATH"
    fi


    if [ -n "$VDEV_VAR_PERMISSIONS_MODE" ]; then


        /bin/chmod "$VDEV_VAR_PERMISSIONS_MODE" "$VDEV_MOUNTPOINT/$VDEV_PATH"
    fi


"$VDEV_VAR_PERMISSIONS_GROUP" = "scanner" ] ; then
    if [ "$VDEV_MAJOR" = 189 ] && [ "$VDEV_MINOR" = 132 ] ; then
    /bin/setfacl -m g:scanner:rw "$VDEV_MOUNTPOINT/$VDEV_PATH"
    fi


    # reset for next time
    VDEV_VAR_PERMISSIONS_GROUP=
    VDEV_VAR_PERMISSIONS_OWNER=
    VDEV_VAR_PERMISSIONS_MODE=


    return 0
}


if [ $VDEV_DAEMONLET -eq 0 ]; then

set +u
main
exit $?
else

# initialize
set -u
VDEV_VAR_PERMISSIONS_GROUP=
VDEV_VAR_PERMISSIONS_OWNER=
VDEV_VAR_PERMISSIONS_MODE=
fi