From cce31e19c25bd34aee2dc952e2b5747f0dab29cc Mon Sep 17 00:00:00 2001 From: rickpeters Date: Sun, 27 Sep 2026 16:00:39 +0200 Subject: [PATCH] refactor: DKMS confs in patches/; an existing leds-valve DKMS override is kept and restored --- AGENTS.md | 4 ++- CHANGELOG.md | 3 +- lib/cec.sh | 5 +--- lib/common.sh | 15 +++++----- lib/fremont-poweroff.sh | 5 +--- lib/steam-machine.sh | 33 +++++++++++++++++++-- patches/README.md | 4 ++- patches/leds-valve-dkms.conf | 2 ++ patches/steamify-cros-ec-cec.dkms.conf | 6 ++++ patches/steamify-fremont-poweroff.dkms.conf | 6 ++++ 10 files changed, 62 insertions(+), 21 deletions(-) create mode 100644 patches/leds-valve-dkms.conf create mode 100644 patches/steamify-cros-ec-cec.dkms.conf create mode 100644 patches/steamify-fremont-poweroff.dkms.conf diff --git a/AGENTS.md b/AGENTS.md index 75500d1..b1a3afb 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -154,7 +154,9 @@ gamescope and the Plasma desktop. Primary target: the Valve Steam Machine `restart_plasmashell_if_stopped` (`lib/common.sh`). - LED driver: `leds-valve-dkms-git`'s Makefile builds against `uname -r`, not DKMS's target kernel: `/etc/dkms/leds-valve-dkms.conf` sets - `MAKE[0]="make KVERSION=${kernelver}"` (written before the AUR install). + `MAKE[0]="make KVERSION=${kernelver}"` (written before the AUR install; + someone's own override there is backed up, kept with ours appended, and + restored on disable). Without it, other kernels build against the running kernel's tree and fail (CachyOS kernels are clang-built; DKMS adds `LLVM=1` only for the target's tree). Headers for every installed kernel are installed first, diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d02441..60efe05 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,8 @@ one per merged pull request. ## 2.5.0 - 2026-09-27 -- **refactor: The session sync and kernel headers scripts in patches/** +- **refactor: DKMS confs in patches/; an existing leds-valve DKMS override is kept and restored** +- `bd4fa3a` **refactor: The session sync and kernel headers scripts in patches/** - `8ffa0f2` **refactor: systemd units in services/, read with service_file like patches/** - `8a2601d` **docs: README screenshot at 2.5.0 with Update notifications; AGENTS.md: retake it when rows change** - `572417b` **fix: Open Steamify from the notification starts the app (own scope), the same way it was last used (app or terminal)** diff --git a/lib/cec.sh b/lib/cec.sh index e8e4724..ffe570a 100644 --- a/lib/cec.sh +++ b/lib/cec.sh @@ -76,10 +76,7 @@ cec_driver_enable() { patch_file cros-ec-cec-single-port.patch | patch -s -d "$tmp" -p1 || { rm -rf "$tmp"; err "Patching Valve's CEC driver failed."; return 1; } echo 'obj-m += cros-ec-cec.o' >"$tmp/Makefile" - printf '%s\n' "# Written by Steamify: Valve's cros_ec_cec, which knows the Steam Machine." \ - "PACKAGE_NAME=\"$CEC_DKMS_NAME\"" "PACKAGE_VERSION=\"$CEC_DKMS_VER\"" \ - 'BUILT_MODULE_NAME[0]="cros-ec-cec"' 'DEST_MODULE_LOCATION[0]="/updates/dkms"' \ - 'AUTOINSTALL="yes"' >"$tmp/dkms.conf" + patch_file "$CEC_DKMS_NAME.dkms.conf" | fill NAME="$CEC_DKMS_NAME" VERSION="$CEC_DKMS_VER" >"$tmp/dkms.conf" sudo dkms remove "$CEC_DKMS_NAME/$CEC_DKMS_VER" --all >/dev/null 2>&1 sudo rm -rf "$CEC_DKMS_SRC" sudo install -d "$CEC_DKMS_SRC" && sudo install -m644 "$tmp"/{cros-ec-cec.c,Makefile,dkms.conf} "$CEC_DKMS_SRC/" diff --git a/lib/common.sh b/lib/common.sh index ba0c45c..e709249 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -9,16 +9,17 @@ ok() { echo -e "${c_green}[OK]${c_reset} $*"; } # patch_file : a file from patches/ (module sources, patches). The # single-file build replaces this with one that has them embedded. patch_file() { cat "$SCRIPT_DIR/patches/$1"; } -# service_file [KEY=value...]: a systemd unit from services/, with -# each @KEY@ replaced by its value. The single-file build replaces -# service_raw like patch_file. +# service_file [KEY=value...]: a systemd unit from services/, filled +# in. The single-file build replaces service_raw like patch_file. service_raw() { cat "$SCRIPT_DIR/services/$1"; } -service_file() { - local name="$1" kv +service_file() { local name="$1"; shift; service_raw "$name" | fill "$@"; } +# fill [KEY=value...]: stdin with each @KEY@ replaced by its value (paths, +# names; no "|" in them). +fill() { + local kv local -a subst=(-e '') - shift for kv in "$@"; do subst+=(-e "s|@${kv%%=*}@|${kv#*=}|g"); done - service_raw "$name" | sed "${subst[@]}" + sed "${subst[@]}" } warn() { echo -e "${c_yellow}[WARN]${c_reset} $*"; } err() { echo -e "${c_red}[ERROR] $*${c_reset}" >&2; } diff --git a/lib/fremont-poweroff.sh b/lib/fremont-poweroff.sh index 2ea8482..2fb1d6c 100644 --- a/lib/fremont-poweroff.sh +++ b/lib/fremont-poweroff.sh @@ -28,10 +28,7 @@ poweroff_fix_enable() { tmp="$(mktemp -d)" patch_file "$POWEROFF_DKMS_NAME.c" > "$tmp/$POWEROFF_DKMS_NAME.c" echo "obj-m += $POWEROFF_DKMS_NAME.o" >"$tmp/Makefile" - printf '%s\n' "# Written by Steamify: the Steam Machine powers off instead of booting up again." \ - "PACKAGE_NAME=\"$POWEROFF_DKMS_NAME\"" "PACKAGE_VERSION=\"$POWEROFF_DKMS_VER\"" \ - "BUILT_MODULE_NAME[0]=\"$POWEROFF_DKMS_NAME\"" 'DEST_MODULE_LOCATION[0]="/updates/dkms"' \ - 'AUTOINSTALL="yes"' >"$tmp/dkms.conf" + patch_file "$POWEROFF_DKMS_NAME.dkms.conf" | fill NAME="$POWEROFF_DKMS_NAME" VERSION="$POWEROFF_DKMS_VER" >"$tmp/dkms.conf" sudo dkms remove "$POWEROFF_DKMS_NAME/$POWEROFF_DKMS_VER" --all >/dev/null 2>&1 sudo rm -rf "$POWEROFF_DKMS_SRC" sudo install -d "$POWEROFF_DKMS_SRC" && diff --git a/lib/steam-machine.sh b/lib/steam-machine.sh index 348e717..f5c174e 100644 --- a/lib/steam-machine.sh +++ b/lib/steam-machine.sh @@ -224,9 +224,11 @@ install_valve_led_driver() { # a clang-built tree). DKMS reads this override after the package's # dkms.conf; written before the install so its own build works too. # On a fresh system dkms isn't installed yet, so /etc/dkms doesn't exist. + # Someone's own override is backed up and kept, with ours after it: it's + # sourced as bash, so our MAKE[0] wins. sudo mkdir -p "$(dirname "$LED_DKMS_OVERRIDE")" - if ! printf '%s\n' "# Written by cachyos-gamescope-boot: build for DKMS's target kernel." \ - 'MAKE[0]="make KVERSION=${kernelver}"' | sudo tee "$LED_DKMS_OVERRIDE" >/dev/null; then + if ! led_dkms_override | sudo tee "$LED_DKMS_OVERRIDE.new" >/dev/null || + ! sudo mv -f "$LED_DKMS_OVERRIDE.new" "$LED_DKMS_OVERRIDE"; then err "Couldn't write $LED_DKMS_OVERRIDE; without it the LED driver only builds for the running kernel." return 1 fi @@ -285,6 +287,30 @@ install_valve_led_driver() { LED_UDEV_RULE="/etc/udev/rules.d/70-valve-leds-user.rules" LED_DKMS_OVERRIDE="/etc/dkms/leds-valve-dkms.conf" + +led_dkms_override() { + # The override to write: an existing one's own lines (backed up the first + # time), without ours from an earlier run, then ours. Before 2.5.0 the + # file was ours alone, with a different comment. + local ours + ours="$(patch_file leds-valve-dkms.conf)" + if [[ -f "$LED_DKMS_OVERRIDE" ]]; then + grep -qxF -f <(echo "$ours") "$LED_DKMS_OVERRIDE" || + grep -q '^# Written by cachyos-gamescope-boot' "$LED_DKMS_OVERRIDE" || + backup_file "$LED_DKMS_OVERRIDE" >&2 + grep -vxF -f <(echo "$ours") "$LED_DKMS_OVERRIDE" | grep -v '^# Written by cachyos-gamescope-boot' + fi + echo "$ours" +} + +led_dkms_override_remove() { + # Puts someone's own override back, or removes ours. + if [[ -f "$LED_DKMS_OVERRIDE.bak-gamescope-wizard" ]]; then + sudo mv -f "$LED_DKMS_OVERRIDE.bak-gamescope-wizard" "$LED_DKMS_OVERRIDE" + else + sudo rm -f "$LED_DKMS_OVERRIDE" + fi +} HEADERS_SCRIPT="/usr/local/lib/cachyos-gamescope-boot/ensure-kernel-headers" HEADERS_UNIT="/etc/systemd/system/ensure-kernel-headers.service" @@ -404,7 +430,8 @@ machine_disable() { krevert machine reload_powerdevil sudo systemctl disable ensure-kernel-headers.service 2>/dev/null - sudo rm -f "$LED_DKMS_OVERRIDE" "$HEADERS_UNIT" "$HEADERS_SCRIPT" + led_dkms_override_remove + sudo rm -f "$HEADERS_UNIT" "$HEADERS_SCRIPT" sudo rmdir "$(dirname "$HEADERS_SCRIPT")" 2>/dev/null sudo systemctl daemon-reload ok "Steam Machine support removed (the AUR helper, if installed, is kept)." diff --git a/patches/README.md b/patches/README.md index 9a88df6..bf6c056 100644 --- a/patches/README.md +++ b/patches/README.md @@ -2,12 +2,14 @@ Files Steamify builds or applies, kept out of the shell code so they can be read and reviewed on their own. `lib/*.sh` reads them with `patch_file -`; the single-file build (`.github/tools/bundle.sh`) embeds them. +` (piped through `fill KEY=value...` for `@KEY@` placeholders); the single-file build (`.github/tools/bundle.sh`) embeds them. | File | Used by | What | |---|---|---| | `steamify-fremont-poweroff.c` | `lib/fremont-poweroff.sh` (Steam Machine support) | Kernel module (DKMS): clears GPIO 18's S4/S5 wake bit before power-off, so the Steam Machine stays off with recent kernels | | `sync-steamos-session.sh` | `lib/login-manager.sh` (SteamOS conversion, plasma-login-manager) | The sync bridge: copies Steam's session choice from `zz-steamos-autologin.conf` into `plasmalogin.conf`'s `[Autologin]` | | `ensure-kernel-headers.sh` | `lib/steam-machine.sh` (Steam Machine support) | Run at boot: installs missing headers for every installed kernel | +| `leds-valve-dkms.conf` | `lib/steam-machine.sh` (Steam Machine support) | `/etc/dkms` override: build the LED driver for DKMS's target kernel; appended to someone's own override, which is backed up and restored | +| `steamify-fremont-poweroff.dkms.conf`, `steamify-cros-ec-cec.dkms.conf` | `lib/fremont-poweroff.sh`, `lib/cec.sh` | The DKMS modules' `dkms.conf` (`fill NAME=... VERSION=...`) | | `steamify-notifier.py` | `lib/update-notifier.sh` (Update notifications) | The daily check: notification and tray icon when there's a new release | | `cros-ec-cec-single-port.patch` | `lib/cec.sh` (HDMI-CEC) | Makes Valve's Steam Machine CEC driver find amdgpu's HDMI port | diff --git a/patches/leds-valve-dkms.conf b/patches/leds-valve-dkms.conf new file mode 100644 index 0000000..260b95a --- /dev/null +++ b/patches/leds-valve-dkms.conf @@ -0,0 +1,2 @@ +# Written by Steamify: build leds-valve for DKMS's target kernel, not the running one. +MAKE[0]="make KVERSION=${kernelver}" diff --git a/patches/steamify-cros-ec-cec.dkms.conf b/patches/steamify-cros-ec-cec.dkms.conf new file mode 100644 index 0000000..ebad554 --- /dev/null +++ b/patches/steamify-cros-ec-cec.dkms.conf @@ -0,0 +1,6 @@ +# Written by Steamify: Valve's cros_ec_cec, which knows the Steam Machine. +PACKAGE_NAME="@NAME@" +PACKAGE_VERSION="@VERSION@" +BUILT_MODULE_NAME[0]="cros-ec-cec" +DEST_MODULE_LOCATION[0]="/updates/dkms" +AUTOINSTALL="yes" diff --git a/patches/steamify-fremont-poweroff.dkms.conf b/patches/steamify-fremont-poweroff.dkms.conf new file mode 100644 index 0000000..3dfea37 --- /dev/null +++ b/patches/steamify-fremont-poweroff.dkms.conf @@ -0,0 +1,6 @@ +# Written by Steamify: the Steam Machine powers off instead of booting up again. +PACKAGE_NAME="@NAME@" +PACKAGE_VERSION="@VERSION@" +BUILT_MODULE_NAME[0]="@NAME@" +DEST_MODULE_LOCATION[0]="/updates/dkms" +AUTOINSTALL="yes"