Files
Sunshine/packaging/linux/AppImage/AppRun
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

102 lines
2.8 KiB
Bash

#!/bin/bash
# custom AppRun for Sunshine AppImage
# path of the extracted AppRun
HERE="$(dirname "$(readlink -f "${0}")")"
SUNSHINE_PATH=/usr/bin/sunshine
SUNSHINE_BIN_HERE=$HERE/usr/bin/sunshine
SUNSHINE_SHARE_HERE=$HERE/usr/share/sunshine
# Set APPDIR when running directly from the AppDir:
if [ -z "$APPDIR" ]; then
ARGV0="AppRun"
fi
cd "$HERE" || exit 1
function help() {
echo "
------------------------------
Sunshine AppImage package.
------------------------------
sunshine.AppImage options
------------------------
Usage: $ARGV0 --help, -h
------ # This message
$ARGV0 --install, -i
# Install or update input rules and sunshine.service files.
$ARGV0 --remove, -r
# Remove input rules sunshine.service files.
$ARGV0 --appimage-help
# Show available AppImage options
sunshine options
----------------
"
# print sunshine binary help, replacing the sunshine command in usage statement
"$SUNSHINE_BIN_HERE" --help | sed -e "s#$SUNSHINE_BIN_HERE#$ARGV0#g"
}
function install() {
# user input rules
# shellcheck disable=SC2002
cat "$SUNSHINE_SHARE_HERE/udev/rules.d/60-sunshine.rules" | sudo tee /etc/udev/rules.d/60-sunshine.rules
cat "$SUNSHINE_SHARE_HERE/modules-load.d/60-sunshine.conf" | sudo tee /etc/modules-load.d/60-sunshine.conf
sudo modprobe uhid
sudo udevadm control --reload-rules
sudo udevadm trigger --property-match=DEVNAME=/dev/uinput
sudo udevadm trigger --property-match=DEVNAME=/dev/uhid
sudo udevadm trigger --subsystem-match=hidraw
sudo udevadm trigger --subsystem-match=input
# sunshine service
mkdir -p ~/.config/systemd/user
cp -r "$SUNSHINE_SHARE_HERE/systemd/user/" ~/.config/systemd/
# patch service executable path
sed -i -e "s#$SUNSHINE_PATH#$(readlink -f $ARGV0)#g" ~/.config/systemd/user/app-dev.lizardbyte.app.Sunshine.service
# setcap
sudo setcap cap_sys_admin,cap_sys_nice+p "$(readlink -f "$SUNSHINE_BIN_HERE")"
}
function remove() {
# remove input rules
sudo rm -f /etc/udev/rules.d/60-sunshine.rules
sudo udevadm control --reload-rules
# remove uhid module loading config
sudo rm -f /etc/modules-load.d/60-sunshine.conf
# remove service
sudo rm -f ~/.config/systemd/user/app-dev.lizardbyte.app.Sunshine.service
}
# process arguments
if [ "x$1" == "xhelp" ] || [ "x$1" == "x--help" ] || [ "x$1" == "x-h" ] ; then
help
exit $?
fi
if [ "x$1" == "xinstall" ] || [ "x$1" == "x--install" ] || [ "x$1" == "x-i" ] ; then
install
exit $?
fi
if [ "x$1" == "xremove" ] || [ "x$1" == "x--remove" ] || [ "x$1" == "x-r" ] ; then
remove
exit $?
fi
# create config directory if it doesn't exist
# https://github.com/LizardByte/Sunshine/issues/324
mkdir -p ~/.config/sunshine
# run sunshine
"$SUNSHINE_BIN_HERE" $@