From d20b3ae43faebd713d03143f079947a044d883ca Mon Sep 17 00:00:00 2001 From: Gilles Schintgen Date: Tue, 23 Jul 2024 13:42:18 +0200 Subject: [PATCH 1/4] packaging/Linux: ensure that uhid is loaded automatically --- cmake/FindSystemd.cmake | 14 ++++++++------ cmake/packaging/linux.cmake | 4 ++++ packaging/linux/AppImage/AppRun | 5 +++++ .../linux/flatpak/scripts/additional-install.sh | 6 ++++++ .../flatpak/scripts/remove-additional-install.sh | 3 +++ src_assets/linux/misc/60-sunshine.conf | 2 ++ src_assets/linux/misc/postinst | 3 +++ 7 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 src_assets/linux/misc/60-sunshine.conf diff --git a/cmake/FindSystemd.cmake b/cmake/FindSystemd.cmake index c41ca64d248..c38d62c3f53 100644 --- a/cmake/FindSystemd.cmake +++ b/cmake/FindSystemd.cmake @@ -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) @@ -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 () diff --git a/cmake/packaging/linux.cmake b/cmake/packaging/linux.cmake index 25f3364c1c4..275b3860ab5 100644 --- a/cmake/packaging/linux.cmake +++ b/cmake/packaging/linux.cmake @@ -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() @@ -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() diff --git a/packaging/linux/AppImage/AppRun b/packaging/linux/AppImage/AppRun index 404704c34d3..3c97338c692 100644 --- a/packaging/linux/AppImage/AppRun +++ b/packaging/linux/AppImage/AppRun @@ -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 @@ -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 } diff --git a/packaging/linux/flatpak/scripts/additional-install.sh b/packaging/linux/flatpak/scripts/additional-install.sh index a27db4e09ba..d31e2963428 100644 --- a/packaging/linux/flatpak/scripts/additional-install.sh +++ b/packaging/linux/flatpak/scripts/additional-install.sh @@ -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. diff --git a/packaging/linux/flatpak/scripts/remove-additional-install.sh b/packaging/linux/flatpak/scripts/remove-additional-install.sh index 0d13baeb62c..09490c33c55 100644 --- a/packaging/linux/flatpak/scripts/remove-additional-install.sh +++ b/packaging/linux/flatpak/scripts/remove-additional-install.sh @@ -6,6 +6,9 @@ rm $HOME/.config/systemd/user/sunshine.service systemctl --user daemon-reload echo Sunshine User Service has been removed. +# Uhid loading +flatpak-spawn --host pkexec sh -c "rm /etc/modules-load.d/60-sunshine.conf" + # Udev rule flatpak-spawn --host pkexec sh -c "rm /etc/udev/rules.d/60-sunshine.rules" echo Mouse permission removed. Restart computer to take effect. diff --git a/src_assets/linux/misc/60-sunshine.conf b/src_assets/linux/misc/60-sunshine.conf new file mode 100644 index 00000000000..779674c5076 --- /dev/null +++ b/src_assets/linux/misc/60-sunshine.conf @@ -0,0 +1,2 @@ +# Sunshine needs uhid for DS5 emulation +uhid diff --git a/src_assets/linux/misc/postinst b/src_assets/linux/misc/postinst index e406c76242f..3df8a837985 100644 --- a/src_assets/linux/misc/postinst +++ b/src_assets/linux/misc/postinst @@ -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 From 1cd3f9a63f692a5959c61e280eb6268493a4893e Mon Sep 17 00:00:00 2001 From: Gilles Schintgen Date: Tue, 23 Jul 2024 19:53:08 +0200 Subject: [PATCH 2/4] packaging/Arch: add modprobe uhid --- packaging/linux/Arch/sunshine.install | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packaging/linux/Arch/sunshine.install b/packaging/linux/Arch/sunshine.install index a8a700f1f1c..55e739deb16 100644 --- a/packaging/linux/Arch/sunshine.install +++ b/packaging/linux/Arch/sunshine.install @@ -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 } From a28e1c98fecdd4dee1f65d0c8f69e87f9d79b697 Mon Sep 17 00:00:00 2001 From: Gilles Schintgen Date: Thu, 15 Aug 2024 20:55:35 +0200 Subject: [PATCH 3/4] flatpak review suggestion Co-authored-by: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> --- packaging/linux/flatpak/scripts/remove-additional-install.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packaging/linux/flatpak/scripts/remove-additional-install.sh b/packaging/linux/flatpak/scripts/remove-additional-install.sh index 09490c33c55..85e834dc4c5 100644 --- a/packaging/linux/flatpak/scripts/remove-additional-install.sh +++ b/packaging/linux/flatpak/scripts/remove-additional-install.sh @@ -6,9 +6,7 @@ rm $HOME/.config/systemd/user/sunshine.service systemctl --user daemon-reload echo Sunshine User Service has been removed. -# Uhid loading +# Remove rules flatpak-spawn --host pkexec sh -c "rm /etc/modules-load.d/60-sunshine.conf" - -# Udev rule flatpak-spawn --host pkexec sh -c "rm /etc/udev/rules.d/60-sunshine.rules" echo Mouse permission removed. Restart computer to take effect. From 490bd59b0fa029a3d17151a5ce1f174f806f1221 Mon Sep 17 00:00:00 2001 From: Gilles Schintgen Date: Thu, 15 Aug 2024 21:03:08 +0200 Subject: [PATCH 4/4] build/cmake: improve whitespace handling in FindUdev --- cmake/FindUdev.cmake | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/cmake/FindUdev.cmake b/cmake/FindUdev.cmake index 8343f791d35..385c2a00c7e 100644 --- a/cmake/FindUdev.cmake +++ b/cmake/FindUdev.cmake @@ -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)