From b21f81246e1d2d2c2b6b667c0ee441e10ec1f12f Mon Sep 17 00:00:00 2001 From: Huijing Hei Date: Thu, 26 Jun 2025 21:36:43 +0800 Subject: [PATCH 1/3] ostreeutil: add `get_ostree_bootloader()` and `set_ostree_bootloader(value)` Partiatly from https://github.com/coreos/bootupd/pull/947 --- src/ostreeutil.rs | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/src/ostreeutil.rs b/src/ostreeutil.rs index 8aaf3ec..8b970d8 100644 --- a/src/ostreeutil.rs +++ b/src/ostreeutil.rs @@ -6,7 +6,7 @@ use std::path::Path; -use anyhow::Result; +use anyhow::{Context, Result}; use log::debug; /// https://github.com/coreos/rpm-ostree/pull/969/commits/dc0e8db5bd92e1f478a0763d1a02b48e57022b59 @@ -59,3 +59,42 @@ pub(crate) fn rpm_cmd>(sysroot: P) -> Result Result> { + let mut cmd = std::process::Command::new("ostree"); + let result = cmd + .args([ + "config", + "--repo=/sysroot/ostree/repo", + "get", + "sysroot.bootloader", + ]) + .output() + .context("Querying ostree sysroot.bootloader")?; + if !result.status.success() { + // ostree will exit with a none zero return code if the key does not exists + return Ok(None); + } else { + let res = String::from_utf8(result.stdout) + .with_context(|| "decoding as UTF-8 output of ostree command")?; + let bootloader = res.trim_end().to_string(); + return Ok(Some(bootloader)); + } +} + +pub(crate) fn set_ostree_bootloader(bootloader: &str) -> Result<()> { + let status = std::process::Command::new("ostree") + .args([ + "config", + "--repo=/sysroot/ostree/repo", + "set", + "sysroot.bootloader", + bootloader, + ]) + .status()?; + if !status.success() { + anyhow::bail!("Failed to set 'sysroot.bootloader' to '{bootloader}' in ostree repo config"); + } + Ok(()) +} -- 2.49.0