Skip to content

Instantly share code, notes, and snippets.

@claabs
Last active June 6, 2026 04:00
Show Gist options
  • Select an option

  • Save claabs/e5971bf8d4607c4355a7d7813a14c74e to your computer and use it in GitHub Desktop.

Select an option

Save claabs/e5971bf8d4607c4355a7d7813a14c74e to your computer and use it in GitHub Desktop.
Batocera service to set a udev rule that persists through upgrades, in this case, the Lossless GC adapter
#!/bin/sh
case "$1" in
start)
# Ensure the destination directory exists
mkdir -p /etc/udev/rules.d/
# Create the udev rule directly in the volatile root filesystem
cat << 'EOF' > /etc/udev/rules.d/99-gamecube-adapter.rules
ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="057e", ATTRS{idProduct}=="0337", DRIVER=="usbhid", RUN+="/bin/sh -c 'echo -n $kernel > /sys/bus/usb/drivers/usbhid/unbind'"
EOF
# Reload and trigger the rule immediately
udevadm control --reload-rules
udevadm trigger
;;
stop)
# Clean up the rule file when stopping the service
rm -f /etc/udev/rules.d/99-gamecube-adapter.rules
udevadm control --reload-rules
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment