Skip to content

Commit fd96aa0

Browse files
fix(packaging/Linux): ensure that uhid is loaded automatically (#2906)
Co-authored-by: ReenigneArcher <[email protected]>
1 parent 6de97fd commit fd96aa0

File tree

10 files changed

+40
-22
lines changed

10 files changed

+40
-22
lines changed

cmake/FindSystemd.cmake

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# SYSTEMD_FOUND - system has systemd
55
# SYSTEMD_USER_UNIT_INSTALL_DIR - the systemd system unit install directory
66
# SYSTEMD_SYSTEM_UNIT_INSTALL_DIR - the systemd user unit install directory
7+
# SYSTEMD_MODULES_LOAD_DIR - the systemd modules-load.d directory
78

89
IF (NOT WIN32)
910

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

20-
string(REGEX REPLACE "[ \t\n]+" "" SYSTEMD_USER_UNIT_INSTALL_DIR
21-
"${SYSTEMD_USER_UNIT_INSTALL_DIR}")
22-
2322
execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE}
2423
--variable=systemdsystemunitdir systemd
24+
OUTPUT_STRIP_TRAILING_WHITESPACE
2525
OUTPUT_VARIABLE SYSTEMD_SYSTEM_UNIT_INSTALL_DIR)
2626

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

30-
mark_as_advanced(SYSTEMD_USER_UNIT_INSTALL_DIR SYSTEMD_SYSTEM_UNIT_INSTALL_DIR)
32+
mark_as_advanced(SYSTEMD_USER_UNIT_INSTALL_DIR SYSTEMD_SYSTEM_UNIT_INSTALL_DIR SYSTEMD_MODULES_LOAD_DIR)
3133

3234
endif ()
3335

cmake/FindUdev.cmake

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@ if(NOT WIN32)
2222

2323
execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE}
2424
--variable=udevdir udev
25+
OUTPUT_STRIP_TRAILING_WHITESPACE
2526
OUTPUT_VARIABLE UDEV_RULES_INSTALL_DIR)
2627

27-
string(REGEX REPLACE "[ \t\n]+" "" UDEV_RULES_INSTALL_DIR
28-
"${UDEV_RULES_INSTALL_DIR}")
29-
3028
set(UDEV_RULES_INSTALL_DIR "${UDEV_RULES_INSTALL_DIR}/rules.d")
3129

3230
mark_as_advanced(UDEV_RULES_INSTALL_DIR)

cmake/packaging/linux.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ file(CREATE_LINK "${SUNSHINE_SOURCE_ASSETS_DIR}/linux/assets/shaders"
1414
if(${SUNSHINE_BUILD_APPIMAGE} OR ${SUNSHINE_BUILD_FLATPAK})
1515
install(FILES "${SUNSHINE_SOURCE_ASSETS_DIR}/linux/misc/60-sunshine.rules"
1616
DESTINATION "${SUNSHINE_ASSETS_DIR}/udev/rules.d")
17+
install(FILES "${SUNSHINE_SOURCE_ASSETS_DIR}/linux/misc/60-sunshine.conf"
18+
DESTINATION "${SUNSHINE_ASSETS_DIR}/modules-load.d")
1719
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/sunshine.service"
1820
DESTINATION "${SUNSHINE_ASSETS_DIR}/systemd/user")
1921
else()
@@ -27,6 +29,8 @@ else()
2729
if(SYSTEMD_FOUND)
2830
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/sunshine.service"
2931
DESTINATION "${SYSTEMD_USER_UNIT_INSTALL_DIR}")
32+
install(FILES "${SUNSHINE_SOURCE_ASSETS_DIR}/linux/misc/60-sunshine.conf"
33+
DESTINATION "${SYSTEMD_MODULES_LOAD_DIR}")
3034
endif()
3135
endif()
3236

packaging/linux/AppImage/AppRun

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ function install() {
4747
# user input rules
4848
# shellcheck disable=SC2002
4949
cat "$SUNSHINE_SHARE_HERE/udev/rules.d/60-sunshine.rules" | sudo tee /etc/udev/rules.d/60-sunshine.rules
50+
cat "$SUNSHINE_SHARE_HERE/modules-load.d/60-sunshine.conf" | sudo tee /etc/modules-load.d/60-sunshine.conf
51+
sudo modprobe uhid
5052
sudo udevadm control --reload-rules
5153
sudo udevadm trigger --property-match=DEVNAME=/dev/uinput
5254
sudo udevadm trigger --property-match=DEVNAME=/dev/uhid
@@ -65,6 +67,9 @@ function remove() {
6567
# remove input rules
6668
sudo rm -f /etc/udev/rules.d/60-sunshine.rules
6769

70+
# remove uhid module loading config
71+
sudo rm -f /etc/modules-load.d/60-sunshine.conf
72+
6873
# remove service
6974
sudo rm -f ~/.config/systemd/user/sunshine.service
7075
}

packaging/linux/Arch/sunshine.install

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ do_udev_reload() {
1313
post_install() {
1414
do_setcap
1515
do_udev_reload
16+
modprobe uhid
1617
}
1718

1819
post_upgrade() {
1920
do_setcap
2021
do_udev_reload
22+
modprobe uhid
2123
}

packaging/linux/fedora/Sunshine.spec

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -211,15 +211,13 @@ xvfb-run ./tests/test_sunshine
211211
cd %{_builddir}/Sunshine/build
212212
%make_install
213213

214-
# Add modules-load configuration
215-
# load the uhid module in initramfs even if it doesn't detect the module as being used during dracut
216-
# which must be run every time a new kernel is installed
217-
install -D -m 0644 /dev/stdin %{buildroot}/usr/lib/modules-load.d/uhid.conf <<EOF
218-
uhid
219-
EOF
220-
221214
%post
222215
# Note: this is copied from the postinst script
216+
217+
# Load uhid (DS5 emulation)
218+
echo "Loading uhid kernel module for DS5 emulation."
219+
modprobe uhid
220+
223221
# Check if we're in an rpm-ostree environment
224222
if [ ! -x "$(command -v rpm-ostree)" ]; then
225223
echo "Not in an rpm-ostree environment, proceeding with post install steps."
@@ -239,10 +237,6 @@ else
239237
echo "rpm-ostree environment detected, skipping post install steps. Restart to apply the changes."
240238
fi
241239

242-
%preun
243-
# Remove modules-load configuration
244-
rm -f /usr/lib/modules-load.d/uhid.conf
245-
246240
%files
247241
# Executables
248242
%caps(cap_sys_admin+p) %{_bindir}/sunshine
@@ -255,7 +249,7 @@ rm -f /usr/lib/modules-load.d/uhid.conf
255249
%{_udevrulesdir}/*-sunshine.rules
256250

257251
# Modules-load configuration
258-
%{_modulesloaddir}/uhid.conf
252+
%{_modulesloaddir}/*-sunshine.conf
259253

260254
# Desktop entries
261255
%{_datadir}/applications/*.desktop

packaging/linux/flatpak/scripts/additional-install.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ cp "/app/share/sunshine/systemd/user/sunshine.service" "$HOME/.config/systemd/us
66
echo "Sunshine User Service has been installed."
77
echo "Use [systemctl --user enable sunshine] once to autostart Sunshine on login."
88

9+
# Load uhid (DS5 emulation)
10+
UHID=$(cat /app/share/sunshine/modules-load.d/60-sunshine.conf)
11+
echo "Enabling DS5 emulation."
12+
flatpak-spawn --host pkexec sh -c "echo '$UHID' > /etc/modules-load.d/60-sunshine.conf"
13+
flatpak-spawn --host pkexec modprobe uhid
14+
915
# Udev rule
1016
UDEV=$(cat /app/share/sunshine/udev/rules.d/60-sunshine.rules)
1117
echo "Configuring mouse permission."

packaging/linux/flatpak/scripts/remove-additional-install.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ rm "$HOME/.config/systemd/user/sunshine.service"
66
systemctl --user daemon-reload
77
echo "Sunshine User Service has been removed."
88

9-
# Udev rule
9+
# Remove rules
10+
flatpak-spawn --host pkexec sh -c "rm /etc/modules-load.d/60-sunshine.conf"
1011
flatpak-spawn --host pkexec sh -c "rm /etc/udev/rules.d/60-sunshine.rules"
1112
echo "Input rules removed. Restart computer to take effect."
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Sunshine needs uhid for DS5 emulation
2+
uhid

src_assets/linux/misc/postinst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#!/bin/sh
22

3+
# Load uhid (DS5 emulation)
4+
echo "Loading uhid kernel module for DS5 emulation."
5+
modprobe uhid
6+
37
# Check if we're in an rpm-ostree environment
48
if [ ! -x "$(command -v rpm-ostree)" ]; then
59
echo "Not in an rpm-ostree environment, proceeding with post install steps."

0 commit comments

Comments
 (0)