diff --git a/CHANGELOG.md b/CHANGELOG.md index 67f4ea04..d667284d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,9 @@ release is checked here and released on by hand. the on-screen keyboard stays above the control center until it is put away, instead of being covered by it where it couldn't be dismissed. +- Update Firmware ends on Done when there is nothing to update, instead of + showing "Failed (2)". + ## [0.4.8] - 2026-12-03 ### Desktop diff --git a/desktop/shell/bin/omarchy-update-firmware b/desktop/shell/bin/omarchy-update-firmware new file mode 100755 index 00000000..a0460391 --- /dev/null +++ b/desktop/shell/bin/omarchy-update-firmware @@ -0,0 +1,26 @@ +#!/bin/bash + +# omarchy:summary=Update system firmware using fwupd. Ensures the fwupd EFI binary is installed +# omarchy:requires-sudo=true + +# Upstream Omarchy's, except that "nothing to update" is not a failure. +set -e +echo -e "\e[32mUpdate Firmware\e[0m" + +if omarchy-cmd-missing fwupdmgr; then + omarchy-pkg-add fwupd +fi + +if [[ -d /sys/firmware/efi ]] && [[ -f /usr/lib/fwupd/efi/fwupdx64.efi ]]; then + sudo install -D /usr/lib/fwupd/efi/fwupdx64.efi /boot/EFI/arch/fwupdx64.efi +fi + +fwupdmgr refresh --force + +# fwupdmgr exits 2 when it has nothing to do: "No updatable devices", the +# usual answer on these boards. That is a result, not a failure, so the +# floating terminal ends on Done instead of "Failed (2)" (#252). +status=0 +sudo fwupdmgr update || status=$? +(( status == 2 )) && exit 0 +exit "$status" diff --git a/docs/upstream.md b/docs/upstream.md index 184778f8..6c473d3b 100644 --- a/docs/upstream.md +++ b/docs/upstream.md @@ -42,6 +42,9 @@ gum), `omarchy-dev-add-migration`, `omarchy-toggle-bar`, `omarchy-launch-browser` and `omarchy-launch-webapp` (Firefox; upstream's web apps need Chromium). +**Upstream's with one change:** `omarchy-update-firmware` ends well when +fwupd has nothing to update (its exit status 2). + **Taken unchanged** for the launcher's Uninstall: `omarchy-remove-launcher-entry`. **Changed for touch and the tablet in the shell.** diff --git a/tests/test_update_firmware.py b/tests/test_update_firmware.py new file mode 100644 index 00000000..ef983f36 --- /dev/null +++ b/tests/test_update_firmware.py @@ -0,0 +1,47 @@ +"""Update Firmware: "nothing to update" is not a failure (#252).""" +from pathlib import Path +import os +import subprocess +import tempfile +import unittest + +SCRIPT = Path(__file__).resolve().parents[1] / 'desktop/shell/bin/omarchy-update-firmware' + + +class UpdateFirmware(unittest.TestCase): + def run_with(self, update_status, refresh_status=0): + with tempfile.TemporaryDirectory() as stubs: + calls = Path(stubs) / 'calls' + for name, body in { + 'omarchy-cmd-missing': 'exit 1\n', + 'sudo': 'exec "$@"\n', + 'fwupdmgr': f'echo "fwupdmgr $*" >> {calls}\n' + f'[ "$1" = refresh ] && exit {refresh_status}\n' + f'exit {update_status}\n', + }.items(): + stub = Path(stubs) / name + stub.write_text('#!/bin/bash\n' + body) + stub.chmod(0o755) + env = dict(os.environ, PATH=f'{stubs}:{os.environ["PATH"]}') + result = subprocess.run(['bash', str(SCRIPT)], env=env, capture_output=True, text=True) + return result.returncode, calls.read_text().splitlines() + + def test_nothing_to_update_ends_well(self): + status, calls = self.run_with(update_status=2) + self.assertEqual(status, 0) + self.assertEqual(calls, ['fwupdmgr refresh --force', 'fwupdmgr update']) + + def test_an_update_that_fails_still_fails(self): + self.assertEqual(self.run_with(update_status=1)[0], 1) + + def test_an_update_that_works_ends_well(self): + self.assertEqual(self.run_with(update_status=0)[0], 0) + + def test_a_failed_refresh_stops_before_the_update(self): + status, calls = self.run_with(update_status=0, refresh_status=1) + self.assertEqual(status, 1) + self.assertEqual(calls, ['fwupdmgr refresh --force']) + + +if __name__ == '__main__': + unittest.main()