darrylb123 / usbrelay

Control usb relay - based on hidapi
GNU General Public License v2.0
315 stars 98 forks source link

Add --export-id option to simplify matching relays in udev rules #72

Closed wentasah closed 2 years ago

wentasah commented 2 years ago

With this change, one can put the following line to an udev rule file, e.g., /etc/udev/rules.d/50-dct-tech-usb-relay-2.rules:

SUBSYSTEMS=="usb", ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="05df", IMPORT{program}="/usr/bin/usbrelay -q --export-id $devnode"

This ensures that subsequent rules can use relay ID stored in the ID_SERIAL environment variable to match different relays. For example giving permissions for different relays to different users can be achieved by the following rules:

SUBSYSTEMS=="usb", ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="05df", ENV{ID_SERIAL}=="PSUIS", MODE="0600", OWNER="user1"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="05df", ENV{ID_SERIAL}=="0U70M", MODE="0600", OWNER="user2"
darrylb123 commented 2 years ago

Merged, looks very limited in scope

darrylb123 commented 2 years ago

Tested the --export_id option