deb-bootupd/src/ostreeutil.rs
robojerk 95c23891b6
Some checks failed
Build deb-bootupd Artifacts / Build deb-bootupd Artifacts (push) Failing after 1m51s
Simple Build & Upload / build (push) Failing after 1m20s
Add Forgejo Actions workflows for automated builds and artifact uploads
- Add comprehensive build-artifacts.yml workflow with Forgejo Package Registry upload
- Add simple-build.yml workflow for basic artifact management
- Update README.md with workflow documentation and setup instructions
- Fix debian/rules to correctly create bootupctl symlink to /usr/libexec/bootupd
- Improve error handling and validation throughout the codebase
- Remove unused functions and imports
- Update documentation to clarify bootupd is not a daemon
- Fix binary layout to match RPM packaging pattern
2025-08-09 23:38:01 -07:00

56 lines
1.6 KiB
Rust
Executable file

/*
* Copyright (C) 2020 Red Hat, Inc.
* Modified for Debian compatibility
*
* SPDX-License-Identifier: Apache-2.0
*/
use anyhow::{Context, Result};
/// https://github.com/coreos/rpm-ostree/pull/969/commits/dc0e8db5bd92e1f478a0763d1a02b48e57022b59
#[cfg(any(
target_arch = "x86_64",
target_arch = "aarch64",
target_arch = "riscv64"
))]
pub(crate) const BOOT_PREFIX: &str = "usr/lib/ostree-boot";
/// Get sysroot.bootloader in ostree repo config.
pub(crate) fn get_ostree_bootloader() -> Result<Option<String>> {
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")?
.trim_end()
.to_string();
return Ok(Some(res));
}
}
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(())
}