On Debian 13 how to make `fwupdmgr update` return non zero exit code if *Devices with firmware updates that need user action*?
May 6, 2:02pm

On Debian 13 (or any system using fwupd), the fwupdmgr update command by default returns a zero exit code even if there are devices requiring user action (e.g., firmware updates that need manual intervention, like a reboot or BIOS setting change). This is because fwupdmgr considers the command successful if it executed without errors, regardless of pending user actions.


Solution: Check for Pending User Actions

To make fwupdmgr update return a non-zero exit code when devices require user action, you need to:

  1. Run fwupdmgr update.
  2. Check the output for devices requiring user action.
  3. Exit with a non-zero code if such devices exist.

Method 1: Using fwupdmgr get-devices and jq

You can parse the output of fwupdmgr get-devices --json to detect devices with Flags: needs-reboot, needs-user-action, etc. and exit accordingly.

Example Script:

bash
#!/bin/bash

# Run the update
fwupdmgr update

# Check for devices requiring user action
if fwupdmgr get-devices --json | jq -e '.Devices[] | select(.Flags | contains("needs-user-action") or contains("needs-reboot"))' >/dev/null; then
    echo "Devices require user action. Exiting with non-zero code."
    exit 1
else
    echo "No user action required. Exiting with zero code."
    exit 0
fi

Method 2: Using fwupdmgr get-updates

Alternatively, you can use fwupdmgr get-updates to check for pending updates that require user action:

bash
#!/bin/bash

# Run the update
fwupdmgr update

# Check for updates requiring user action
if fwupdmgr get-updates | grep -q "User action required"; then
    echo "User action required. Exiting with non-zero code."
    exit 1
else
    echo "No user action required. Exiting with zero code."
    exit 0
fi

Method 3: Using fwupdmgr --json and jq (More Robust)

For a more robust approach, use the JSON output of fwupdmgr get-updates --json to check for UserActionRequired:

bash
#!/bin/bash

# Run the update
fwupdmgr update

# Check for updates requiring user action
if fwupdmgr get-updates --json | jq -e '.Updates[] | select(.UserActionRequired == true)' >/dev/null; then
    echo "User action required. Exiting with non-zero code."
    exit 1
else
    echo "No user action required. Exiting with zero code."
    exit 0
fi

Notes:

  • Ensure jq is installed (sudo apt install jq).
  • The exact flags or fields (e.g., UserActionRequired, needs-reboot) may vary depending on the fwupd version. Adjust the script accordingly.
  • If you want to fail immediately when user action is required (without running fwupdmgr update), use fwupdmgr get-updates first.

May 6, 2:02pm

This is a shared conversation and may include unverified content that doesn't reflect Mistral AI's views. Login to resume chatting.

Le Chat can make mistakes. Check answers. Learn more