Skip to content

Commit

Permalink
udev lock to application username
Browse files Browse the repository at this point in the history
  • Loading branch information
jurkovic-nikola committed Dec 14, 2024
1 parent 09bd841 commit 4edc6e2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions device-permissions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ echo "Cleanup..."
sudo rm -f /etc/udev/rules.d/99-corsair-*.rules

echo "Setting udev device permissions..."
APP_USERNAME="openlinkhub"
lsusb -d 1b1c: | while read -r line; do
ids=$(echo "$line" | awk '{print $6}')
vendor_id=$(echo "$ids" | cut -d':' -f1)
Expand All @@ -19,11 +20,11 @@ done

if [ "$match" = true ]; then
cat > /etc/udev/rules.d/99-corsair-"$device_id".rules <<- EOM
SUBSYSTEMS=="usb", ATTRS{idVendor}=="$vendor_id", ATTRS{idProduct}=="$device_id", MODE="0666"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="$vendor_id", ATTRS{idProduct}=="$device_id", MODE="0600", OWNER="$APP_USERNAME"
EOM
else
cat > /etc/udev/rules.d/99-corsair-"$device_id".rules <<- EOM
KERNEL=="hidraw*", SUBSYSTEMS=="usb", ATTRS{idVendor}=="$vendor_id", ATTRS{idProduct}=="$device_id", MODE="0666"
KERNEL=="hidraw*", SUBSYSTEMS=="usb", ATTRS{idVendor}=="$vendor_id", ATTRS{idProduct}=="$device_id", MODE="0600", OWNER="$APP_USERNAME"
EOM
fi
done
Expand Down
2 changes: 1 addition & 1 deletion src/devices/devices.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ type Product struct {
}

var (
expectedPermission = 0666
expectedPermission = 0600
vendorId uint16 = 6940 // Corsair
interfaceId = 0
devices = make(map[string]*Device, 0)
Expand Down

0 comments on commit 4edc6e2

Please sign in to comment.