Files
Sunshine/src_assets/linux/misc/postinst
T
ReenigneArcher 50c54196ef Fix udev rules for virtual gamepad nodes
Extend udev rule reloading to cover hidraw and input subsystems so permissions are applied to dynamically created libvirtualhid gamepad child nodes, not just /dev/uinput and /dev/uhid.

Also:
- Always install the udev rules file regardless of whether libudev is detected at build time
- Add Homebrew postinst support to copy rules to host-monitored directories
- Trigger udevadm reload on rule removal (AppImage, Flatpak)
- Update comments to say "gamepad emulation" instead of "DS5 emulation"
- Add docs clarifying that manual chmod/setfacl changes are lost on reconnect and how to reload rules
2026-08-29 17:46:07 -04:00

51 lines
2.0 KiB
Bash

#!/bin/sh
# Load uhid for descriptor-driven gamepad emulation
echo "Loading uhid kernel module for gamepad emulation."
modprobe uhid
# Homebrew installs host integration files inside its Cellar. Copy them to
# host directories that systemd-udevd and systemd-modules-load monitor.
script_dir=$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd)
packaged_udev_rule="$script_dir/../lib/udev/rules.d/60-sunshine.rules"
packaged_modules_file="$script_dir/../lib/modules-load.d/60-sunshine.conf"
if [ -f "$packaged_udev_rule" ]; then
echo "Installing Sunshine udev rules."
install -Dm644 "$packaged_udev_rule" /etc/udev/rules.d/60-sunshine.rules
fi
if [ -f "$packaged_modules_file" ]; then
echo "Installing Sunshine modules-load configuration."
install -Dm644 "$packaged_modules_file" /etc/modules-load.d/60-sunshine.conf
fi
# Ensure Sunshine can grab images from KMS
path_to_setcap=$(which setcap)
if [ -x "$script_dir/sunshine" ]; then
path_to_sunshine=$(readlink -f "$script_dir/sunshine")
else
path_to_sunshine=$(readlink -f "$(which sunshine)")
fi
if [ -x "$path_to_setcap" ] ; then
echo "Setting CAP_SYS_ADMIN, CAP_SYS_NICE capabilities on Sunshine binary."
echo "$path_to_setcap cap_sys_admin,cap_sys_nice+p $path_to_sunshine"
$path_to_setcap cap_sys_admin,cap_sys_nice+p "$path_to_sunshine"
echo "CAP_SYS_ADMIN, CAP_SYS_NICE capabilities set on Sunshine binary."
else
echo "error: setcap not found or not executable."
fi
# Reload the rules and reapply them to both virtual device factories and any
# gamepad child nodes that already exist.
path_to_udevadm=$(which udevadm)
if [ -x "$path_to_udevadm" ] ; then
echo "Reloading udev rules."
$path_to_udevadm control --reload-rules
$path_to_udevadm trigger --property-match=DEVNAME=/dev/uinput
$path_to_udevadm trigger --property-match=DEVNAME=/dev/uhid
$path_to_udevadm trigger --subsystem-match=hidraw
$path_to_udevadm trigger --subsystem-match=input
echo "Udev rules reloaded successfully."
else
echo "error: udevadm not found or not executable."
fi