From 7d296ccdeaa9e3ecf00f569dfaf5a99265b35433 Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Wed, 18 Dec 2024 20:38:30 -0500 Subject: [PATCH] jovian-updater-logo-helper: Harden resolution detection Fixes #443 We're forcing `-o pipefail` in the script since it'll be added within `writeShellApplication`... and this causes a surprising failure from the totally cromulent (if rude) pipe we build here. --- .../jovian-updater-logo-helper.sh | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/pkgs/jovian-updater-logo-helper/jovian-updater-logo-helper.sh b/pkgs/jovian-updater-logo-helper/jovian-updater-logo-helper.sh index 8b82731b..8ff943f8 100644 --- a/pkgs/jovian-updater-logo-helper/jovian-updater-logo-helper.sh +++ b/pkgs/jovian-updater-logo-helper/jovian-updater-logo-helper.sh @@ -6,6 +6,7 @@ # - Pass `'canvas:red[128x64!]'` as the input image. # +set -o pipefail set -e set -u PS4=" $ " @@ -38,7 +39,22 @@ display_rotation=$( ) # Gets the "preferred" display resolution -resolution=$(cat /sys/class/drm/card*-eDP-*/modes | head -n1) +resolution=$( + # This following pipe will more than likely SIGPIPE. + # So let's not fail... + set +o pipefail + # Prevent non-existent files from mucking up the output + shopt -s nullglob + ( + # Prefer eDP outputs, or else any DRM output + cat /sys/class/drm/card*-eDP-*/modes /sys/class/drm/card*-*-*/modes /dev/null + # pipe "nothing" in if `nullglob` fails to glob anything ^^^^^^^^^ + # otherwise `cat` will expect to consume `stdin` if given no parameters. + + # If for some reason this fails, fallback on a safe resolution. + echo "1920x1080" + ) | head -n1 # Save only the first match +) # The image dimension will be used as our canvas size. if [[ "$display_rotation" == "0" || "$display_rotation" == "180" ]]; then