udev: Use uaccess instead of plugdev (pwr/Solaar#66)
Rules are taken from https://git.lekensteyn.nl/ltunify/. The "VX Nano" receivers (c51a and c526) have been removed as these are only used for Cordless mice and are not even enabled in Solaar. The installer is updated to check for the existence of a group and `mktemp` to create temporary files. (relying on `$TMPDIR` is a bad idea.) This installer is too fancy, most users will be fine with `install -m644 rules.d/42-logitech-unify-permissions.rules /etc/udev/rules.d/`. If you are lazy and want to make `solaar-cli` work over SSH, then this installer will help you. It won't add you to the `plugdev` group, instead it will edit the rule to use your user's primary group. Oh, and it does not change this group to "root" as that is pretty useless given that root is the default.
This commit is contained in:
parent
8852d50971
commit
ec10c9c70c
|
@ -0,0 +1,27 @@
|
||||||
|
# Allows non-root users to have raw access the Logitech Unifying USB Receiver
|
||||||
|
# device. For development purposes, allowing users to write to the receiver is
|
||||||
|
# potentially dangerous (e.g. perform firmware updates).
|
||||||
|
|
||||||
|
# skip actual unified devices, only consider the receiver
|
||||||
|
DRIVERS=="logitech-djdevice", GOTO="not_unify_recv"
|
||||||
|
|
||||||
|
# official Unifying receivers
|
||||||
|
SUBSYSTEM=="hidraw", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c52b", GOTO="unify_dev"
|
||||||
|
SUBSYSTEM=="hidraw", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c532", GOTO="unify_dev"
|
||||||
|
|
||||||
|
# "Unifying Ready" Nano receiver
|
||||||
|
SUBSYSTEM=="hidraw", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c52f", GOTO="unify_dev"
|
||||||
|
|
||||||
|
GOTO="not_unify_recv"
|
||||||
|
|
||||||
|
LABEL="unify_dev"
|
||||||
|
# Allow any seated user to access the receiver.
|
||||||
|
# uaccess: modern ACL-enabled udev
|
||||||
|
# udev-acl: for Ubuntu 12.10 and older
|
||||||
|
TAG+="uaccess", TAG+="udev-acl"
|
||||||
|
|
||||||
|
# Grant members of the "plugdev" group access to receiver (useful for SSH users)
|
||||||
|
#MODE="0660", GROUP="plugdev"
|
||||||
|
|
||||||
|
LABEL="not_unify_recv"
|
||||||
|
# vim: ft=udevrules
|
|
@ -1,20 +0,0 @@
|
||||||
# Initially copied from signal11/hidapi/udev, with modifications.
|
|
||||||
|
|
||||||
# This is a sample udev file for HIDAPI devices which changes the permissions
|
|
||||||
# to 0660 and group to plugdev for a specified device on Linux systems.
|
|
||||||
|
|
||||||
# Make sure the plugdev group exists on your system and your user is a member
|
|
||||||
# before applying these rules.
|
|
||||||
|
|
||||||
# HIDAPI/hidraw for Logitech Unifying Receiver
|
|
||||||
ACTION=="add", KERNEL=="hidraw*", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c52b", GROUP="plugdev", MODE="0660"
|
|
||||||
ACTION=="add", KERNEL=="hidraw*", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c532", GROUP="plugdev", MODE="0660"
|
|
||||||
|
|
||||||
# HIDAPI/hidraw for Logitech Nano Receiver, "Unifying ready"
|
|
||||||
ACTION=="add", KERNEL=="hidraw*", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c52f", GROUP="plugdev", MODE="0660"
|
|
||||||
|
|
||||||
# HIDAPI/hidraw for VX Nano receiver
|
|
||||||
#ACTION=="add", KERNEL=="hidraw*", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c51a", GROUP="plugdev", MODE="0660"
|
|
||||||
#ACTION=="add", KERNEL=="hidraw*", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="c526", GROUP="plugdev", MODE="0660"
|
|
||||||
|
|
||||||
# vim: ft=udevrules
|
|
|
@ -10,19 +10,30 @@ if ! test -d "$RULES_D"; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
RULE=99-logitech-unifying-receiver.rules
|
RULE=42-logitech-unify-permissions.rules
|
||||||
|
|
||||||
if test -n "$1"; then
|
if test -n "$1"; then
|
||||||
SOURCE="$1"
|
SOURCE="$1"
|
||||||
else
|
else
|
||||||
SOURCE="$(dirname "$Z")/$RULE"
|
SOURCE="$(dirname "$Z")/$RULE"
|
||||||
if ! id -G -n | grep -q -F plugdev; then
|
REALUSER="${SUDO_USER-$USER}"
|
||||||
GROUP="$(id -g -n)"
|
if [ -z "$REALUSER" -o "$REALUSER" = "root" ]; then
|
||||||
echo "User '$USER' does not belong to the 'plugdev' group, will use group '$GROUP' in the udev rule."
|
: # ignore unknown and root user
|
||||||
TEMP_RULE="${TMPDIR:-/tmp}/$$-$RULE"
|
else
|
||||||
cp -f "$SOURCE" "$TEMP_RULE"
|
GROUP=plugdev
|
||||||
|
TEMP_RULE="$(mktemp --tmpdir "ltudev.XXXXXXXX")"
|
||||||
|
sed -e "/^#MODE.*\"plugdev\"/s/^#//" "$SOURCE" > "$TEMP_RULE"
|
||||||
|
if ! id -G -n "$REALUSER" | grep -q -F plugdev; then
|
||||||
|
GROUP="$(id -g -n "$REALUSER")"
|
||||||
|
if getent group plugdev >/dev/null; then
|
||||||
|
printf "User '%s' does not belong to the 'plugdev' group, " "$REALUSER"
|
||||||
|
else
|
||||||
|
printf "Group 'plugdev' does not exist, "
|
||||||
|
fi
|
||||||
|
echo "will use group '$GROUP' in the udev rule."
|
||||||
|
sed -i -e "s/\"plugdev\"/\"$GROUP\"/" "$TEMP_RULE"
|
||||||
|
fi
|
||||||
SOURCE="$TEMP_RULE"
|
SOURCE="$TEMP_RULE"
|
||||||
sed -i -e "s/GROUP=\"plugdev\"/GROUP=\"$GROUP\"/" "$SOURCE"
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -36,7 +47,6 @@ if test "$(id -u)" != "0"; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Installing $RULE."
|
echo "Installing $RULE."
|
||||||
cp "$SOURCE" "$RULES_D/$RULE"
|
install -m 644 "$SOURCE" "$RULES_D/$RULE"
|
||||||
chmod a+r "$RULES_D/$RULE"
|
|
||||||
|
|
||||||
echo "Done. Now remove the Unfiying Receiver and plug it in again."
|
echo "Done. Now remove the Unfiying Receiver and plug it in again."
|
||||||
|
|
Loading…
Reference in New Issue