From 1b7e2e88425a0386469570a6f565edd68b192f58 Mon Sep 17 00:00:00 2001 From: Rick Peters Date: Thu, 1 Oct 2026 15:07:16 +0200 Subject: [PATCH] fix: never install an empty NVIDIA hook or script (a failed patch_file piped into install succeeded with no input) --- lib/nvidia.sh | 10 +++++++--- tests/nvidia-test.sh | 2 ++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/nvidia.sh b/lib/nvidia.sh index e280356..df5021a 100644 --- a/lib/nvidia.sh +++ b/lib/nvidia.sh @@ -54,9 +54,13 @@ nvidia_modules_everywhere() { } nvidia_hook_install() { - patch_file steamify-nvidia-initramfs.sh | sudo install -Dm755 /dev/stdin "$NVIDIA_SCRIPT" && - patch_file steamify-nvidia-initramfs.hook | fill SCRIPT="$NVIDIA_SCRIPT" | - sudo install -Dm644 /dev/stdin "$NVIDIA_HOOK" + # Never installs an empty script or hook (a piped patch_file that failed + # still lets install succeed with no input). + local script hook + script="$(patch_file steamify-nvidia-initramfs.sh)" && [[ -n "$script" ]] && + hook="$(patch_file steamify-nvidia-initramfs.hook | fill SCRIPT="$NVIDIA_SCRIPT")" && [[ -n "$hook" ]] || return 1 + printf '%s\n' "$script" | sudo install -Dm755 /dev/stdin "$NVIDIA_SCRIPT" && + printf '%s\n' "$hook" | sudo install -Dm644 /dev/stdin "$NVIDIA_HOOK" } nvidia_rebuild_boot() { diff --git a/tests/nvidia-test.sh b/tests/nvidia-test.sh index 615eb74..550df10 100644 --- a/tests/nvidia-test.sh +++ b/tests/nvidia-test.sh @@ -48,6 +48,8 @@ for loader in limine sdboot grub; do check "$loader: disable restores the file, drops the drop-in, script and hook" '[[ "$(cat "$F")" == "$ORIG" && ! -f "$NVIDIA_INITRAMFS_CONF" && ! -e "$NVIDIA_SCRIPT" && ! -e "$NVIDIA_HOOK" ]]' done +# A missing patches/ file must be an error, never an empty script or hook. +( SCRIPT_DIR="$T/no-patches"; NVIDIA_SCRIPT="$T/empty/script"; NVIDIA_HOOK="$T/empty/hook"; ! nvidia_hook_install 2>/dev/null && [[ ! -s "$T/empty/script" ]] ) && echo "ok a missing patch file is an error, nothing empty installed" || { echo "FAIL a missing patch file is an error, nothing empty installed"; fail=1; } # The pacman hook's script decides again at every kernel change. syncit() { NVIDIA_INITRAMFS_CONF="$NVIDIA_INITRAMFS_CONF" NVIDIA_MODULES_DIR="$NVIDIA_MODULES_DIR" bash "$NVIDIA_SCRIPT" sync; } nvidia_hook_install; rm -f "$NVIDIA_INITRAMFS_CONF"