rhboot / efibootmgr

efibootmgr development tree
GNU General Public License v2.0
514 stars 97 forks source link

JSON output support #190

Open pvxe opened 1 year ago

pvxe commented 1 year ago

(JSON output support has been discussed in the past. #70)

Add --json option to enable JSON output support when compiling efibootmgr with it. This output is compact and intended to be fed to other programs that want to interface with efibootmgr.

To enable JSON support, simply compile with make ... JSON=1 compilation flag.

Adds a new optional dependency with libjansson.

If the user runs efibootmgr --json without json support being compiled, it will print the following message:

JSON support is not built-in

The rationale behind this change is that I'd like to avoid parsing textual output from efibootmgr.

As additional context for these changes: I'm working on the development of a python program used for remote management of computers. This python program needs to retrieve BootOrder, BootNext and the boot entries of the machine it's running on. The program runs an efibootmgr subprocess for such tasks.


Example:

./src/efibootmgr --json | python -m json.tool
{
    "BootCurrent": "000D",
    "Timeout": 1,
    "BootOrder": [
        "0000",
        "000D",
        "0001",
        "000F",
        "0010",
    ],
    "vars": [
        {
            "name": "Boot0000",
            "active": true,
            "description": "Windows Boot Manager"
        },
        {
            "name": "Boot0001",
            "active": true,
            "description": "UEFI iPXE"
        },
        {
            "name": "Boot000D",
            "active": true,
            "description": "UEFI OS"
        },
        {
            "name": "Boot000F",
            "active": true,
            "description": "UEFI: IP4 Qualcomm Atheros PCIe Network Controller"
        },
        {
            "name": "Boot0010",
            "active": true,
            "description": "UEFI: IP6 Qualcomm Atheros PCIe Network Controller"
        },
    ]
}
pvxe commented 6 months ago

I've decided to temporarily revert commit https://github.com/rhboot/efibootmgr/commit/5ce076c88670eeb63dea80fcaec60e79f0e57ac6, while issue https://github.com/rhboot/efibootmgr/issues/204 is still present.

I will rebase my changes as soon as a fix is pushed into efibootmgr tree or a new efivar release is pushed with https://github.com/rhboot/efivar/pull/217 merged.

stephen-mw commented 1 month ago

Any update on this? Json output will be very useful to all of us who are building complicated regex parsing of the output at the moment.