-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
install: Add hidden
ensure-completion
verb
This will be runnable via ``` %post --erroronfail bootc install ensure-completion %end ``` in Anaconda to work around the fact that it's not today using `bootc install to-filesystem`. Signed-off-by: Colin Walters <[email protected]>
- Loading branch information
Showing
3 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
//! This module handles finishing/completion after an ostree-based | ||
//! install from e.g. Anaconda. | ||
use std::os::fd::{AsFd, AsRawFd}; | ||
|
||
use anyhow::Result; | ||
use cap_std_ext::cap_std::fs::Dir; | ||
use ostree_ext::{gio, ostree}; | ||
|
||
use crate::utils::medium_visibility_warning; | ||
|
||
use super::config; | ||
|
||
/// An environment variable set by anaconda that hints | ||
/// we are running as part of that environment. | ||
const ANACONDA_ENV_HINT: &str = "ANA_INSTALL_PATH"; | ||
|
||
fn reconcile_kargs(rootfs: &Dir, sysroot: &ostree::Sysroot) -> Result<()> { | ||
let cancellable = gio::Cancellable::NONE; | ||
|
||
let deployments = sysroot.deployments(); | ||
let deployment = match deployments.as_slice() { | ||
[d] => d, | ||
o => anyhow::bail!("Expected exactly 1 deployment, not {}", o.len()), | ||
}; | ||
|
||
let current_kargs = deployment | ||
.bootconfig() | ||
.expect("bootconfig for deployment") | ||
.get("options"); | ||
let current_kargs = current_kargs | ||
.as_ref() | ||
.map(|s| s.as_str()) | ||
.unwrap_or_default(); | ||
tracing::debug!("current_kargs={current_kargs}"); | ||
let current_kargs = ostree::KernelArgs::from_string(¤t_kargs); | ||
|
||
// Keep this in sync with install_container | ||
let install_config = config::load_config()?; | ||
let install_config_kargs = install_config | ||
.as_ref() | ||
.and_then(|c| c.kargs.as_ref()) | ||
.into_iter() | ||
.flatten() | ||
.map(|s| s.as_str()) | ||
.collect::<Vec<_>>(); | ||
let kargsd = crate::kargs::get_kargs_in_root(rootfs, std::env::consts::ARCH)?; | ||
let kargsd = kargsd.iter().map(|s| s.as_str()).collect::<Vec<_>>(); | ||
|
||
current_kargs.append_argv(&install_config_kargs); | ||
current_kargs.append_argv(&kargsd); | ||
let new_kargs = current_kargs.to_string(); | ||
tracing::debug!("new_kargs={new_kargs}"); | ||
|
||
sysroot.deployment_set_kargs_in_place(deployment, Some(&new_kargs), cancellable)?; | ||
Ok(()) | ||
} | ||
|
||
/// Core entrypoint. | ||
pub(crate) fn run(rootfs: &Dir) -> Result<()> { | ||
let cancellable = gio::Cancellable::NONE; | ||
if std::env::var_os(ANACONDA_ENV_HINT).is_none() { | ||
// Be loud if a user is invoking this outside of the expected setup. | ||
medium_visibility_warning(&format!("Missing environment variable {ANACONDA_ENV_HINT}")); | ||
} | ||
|
||
let sysroot = { | ||
let path = format!("/proc/self/fd/{}", rootfs.as_fd().as_raw_fd()); | ||
ostree::Sysroot::new(Some(&gio::File::for_path(path))) | ||
}; | ||
sysroot.load(cancellable)?; | ||
|
||
reconcile_kargs(rootfs, &sysroot)?; | ||
|
||
Ok(()) | ||
} |