Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(packaging): ensure that uhid is loaded automatically #2906

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions cmake/FindSystemd.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# SYSTEMD_FOUND - system has systemd
# SYSTEMD_USER_UNIT_INSTALL_DIR - the systemd system unit install directory
# SYSTEMD_SYSTEM_UNIT_INSTALL_DIR - the systemd user unit install directory
# SYSTEMD_MODULES_LOAD_DIR - the systemd modules-load.d directory

IF (NOT WIN32)

Expand All @@ -15,19 +16,20 @@ IF (NOT WIN32)
if (SYSTEMD_FOUND)
execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE}
--variable=systemduserunitdir systemd
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE SYSTEMD_USER_UNIT_INSTALL_DIR)

string(REGEX REPLACE "[ \t\n]+" "" SYSTEMD_USER_UNIT_INSTALL_DIR
"${SYSTEMD_USER_UNIT_INSTALL_DIR}")

execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE}
--variable=systemdsystemunitdir systemd
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE SYSTEMD_SYSTEM_UNIT_INSTALL_DIR)

string(REGEX REPLACE "[ \t\n]+" "" SYSTEMD_SYSTEM_UNIT_INSTALL_DIR
"${SYSTEMD_SYSTEM_UNIT_INSTALL_DIR}")
execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE}
--variable=modules_load_dir systemd
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE SYSTEMD_MODULES_LOAD_DIR)

mark_as_advanced(SYSTEMD_USER_UNIT_INSTALL_DIR SYSTEMD_SYSTEM_UNIT_INSTALL_DIR)
mark_as_advanced(SYSTEMD_USER_UNIT_INSTALL_DIR SYSTEMD_SYSTEM_UNIT_INSTALL_DIR SYSTEMD_MODULES_LOAD_DIR)

endif ()

Expand Down
4 changes: 1 addition & 3 deletions cmake/FindUdev.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ IF (NOT WIN32)
if (UDEV_FOUND)
execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE}
--variable=udevdir udev
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE UDEV_RULES_INSTALL_DIR)

string(REGEX REPLACE "[ \t\n]+" "" UDEV_RULES_INSTALL_DIR
"${UDEV_RULES_INSTALL_DIR}")

set(UDEV_RULES_INSTALL_DIR "${UDEV_RULES_INSTALL_DIR}/rules.d")

mark_as_advanced(UDEV_RULES_INSTALL_DIR)
Expand Down
4 changes: 4 additions & 0 deletions cmake/packaging/linux.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ file(COPY "${SUNSHINE_SOURCE_ASSETS_DIR}/linux/assets/"
if(${SUNSHINE_BUILD_APPIMAGE} OR ${SUNSHINE_BUILD_FLATPAK})
install(FILES "${SUNSHINE_SOURCE_ASSETS_DIR}/linux/misc/60-sunshine.rules"
DESTINATION "${SUNSHINE_ASSETS_DIR}/udev/rules.d")
install(FILES "${SUNSHINE_SOURCE_ASSETS_DIR}/linux/misc/60-sunshine.conf"
DESTINATION "${SUNSHINE_ASSETS_DIR}/modules-load.d")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/sunshine.service"
DESTINATION "${SUNSHINE_ASSETS_DIR}/systemd/user")
else()
Expand All @@ -21,6 +23,8 @@ else()
if(SYSTEMD_FOUND)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/sunshine.service"
DESTINATION "${SYSTEMD_USER_UNIT_INSTALL_DIR}")
install(FILES "${SUNSHINE_SOURCE_ASSETS_DIR}/linux/misc/60-sunshine.conf"
DESTINATION "${SYSTEMD_MODULES_LOAD_DIR}")
endif()
endif()

Expand Down
5 changes: 5 additions & 0 deletions packaging/linux/AppImage/AppRun
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ 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 udevadm control --reload-rules
sudo udevadm trigger --property-match=DEVNAME=/dev/uinput
sudo modprobe uhid

# sunshine service
mkdir -p ~/.config/systemd/user
Expand All @@ -64,6 +66,9 @@ function remove() {
# remove input rules
sudo rm -f /etc/udev/rules.d/60-sunshine.rules

# remove uhid module loading config
sudo rm -f /etc/modules-load.d/60-sunshine.conf

# remove service
sudo rm -f ~/.config/systemd/user/sunshine.service
}
Expand Down
2 changes: 2 additions & 0 deletions packaging/linux/Arch/sunshine.install
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ do_udev_reload() {
post_install() {
do_setcap
do_udev_reload
modprobe uhid
}

post_upgrade() {
do_setcap
do_udev_reload
modprobe uhid
}

6 changes: 6 additions & 0 deletions packaging/linux/flatpak/scripts/additional-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ cp /app/share/sunshine/systemd/user/sunshine.service $HOME/.config/systemd/user/
echo Sunshine User Service has been installed.
echo Use [systemctl --user enable sunshine] once to autostart Sunshine on login.

# Load uhid (DS5 emulation)
UHID=$(cat /app/share/sunshine/modules-load.d/60-sunshine.conf)
echo "Enabling DS5 emulation."
flatpak-spawn --host pkexec sh -c "echo '$UHID' > /etc/modules-load.d/60-sunshine.conf"
flatpak-spawn --host pkexec modprobe uhid

# Udev rule
UDEV=$(cat /app/share/sunshine/udev/rules.d/60-sunshine.rules)
echo Configuring mouse permission.
Expand Down
3 changes: 2 additions & 1 deletion packaging/linux/flatpak/scripts/remove-additional-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ rm $HOME/.config/systemd/user/sunshine.service
systemctl --user daemon-reload
echo Sunshine User Service has been removed.

# Udev rule
# Remove rules
flatpak-spawn --host pkexec sh -c "rm /etc/modules-load.d/60-sunshine.conf"
flatpak-spawn --host pkexec sh -c "rm /etc/udev/rules.d/60-sunshine.rules"
echo Mouse permission removed. Restart computer to take effect.
2 changes: 2 additions & 0 deletions src_assets/linux/misc/60-sunshine.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Sunshine needs uhid for DS5 emulation
uhid
3 changes: 3 additions & 0 deletions src_assets/linux/misc/postinst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ if [ -x "$path_to_setcap" ] ; then
$path_to_setcap cap_sys_admin+p $path_to_sunshine
fi

# Load uhid (DS5 emulation)
modprobe uhid

# Trigger udev rule reload for /dev/uinput
path_to_udevadm=$(which udevadm)
if [ -x "$path_to_udevadm" ] ; then
Expand Down