Skip to content

Commit

Permalink
Merge pull request #535 from cgwalters/add-selected-components
Browse files Browse the repository at this point in the history
install: Add support for selecting components
  • Loading branch information
cgwalters committed Sep 29, 2023
2 parents affee1f + 965faf9 commit 1aa3c89
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 9 deletions.
34 changes: 29 additions & 5 deletions src/bootupd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,45 @@ pub(crate) enum ClientRequest {
Status,
}

pub(crate) fn install(source_root: &str, dest_root: &str, device: &str) -> Result<()> {
pub(crate) fn install(
source_root: &str,
dest_root: &str,
device: Option<&str>,
target_components: Option<&[String]>,
) -> Result<()> {
// TODO: Change this to an Option<&str>; though this probably balloons into having
// DeviceComponent and FileBasedComponent
let device = device.unwrap_or("");
let source_root = openat::Dir::open(source_root)?;
SavedState::ensure_not_present(dest_root)
.context("failed to install, invalid re-install attempted")?;

let components = get_components();
if components.is_empty() {
let all_components = get_components();
if all_components.is_empty() {
println!("No components available for this platform.");
return Ok(());
}
let target_components = if let Some(target_components) = target_components {
target_components
.iter()
.map(|name| {
all_components
.get(name.as_str())
.ok_or_else(|| anyhow!("Unknown component: {name}"))
})
.collect::<Result<Vec<_>>>()?
} else {
all_components.values().collect()
};

if target_components.is_empty() {
anyhow::bail!("No components specified");
}

let mut state = SavedState::default();
for component in components.values() {
for component in target_components {
// skip for BIOS if device is empty
if component.name() == "BIOS" && device.trim().is_empty() {
if component.name() == "BIOS" && device.is_empty() {
println!(
"Skip installing component {} without target device",
component.name()
Expand Down
18 changes: 14 additions & 4 deletions src/cli/bootupd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,14 @@ pub struct InstallOpts {
/// Target root
#[clap(value_parser)]
dest_root: String,

/// Target device, used by bios bootloader installation
#[clap(long, value_parser, default_value_t = String::from(""))]
device: String,
#[clap(long)]
device: Option<String>,

#[clap(long = "component")]
/// Only install these components
components: Option<Vec<String>>,
}

#[derive(Debug, Parser)]
Expand Down Expand Up @@ -77,8 +82,13 @@ impl DCommand {

/// Runner for `install` verb.
pub(crate) fn run_install(opts: InstallOpts) -> Result<()> {
bootupd::install(&opts.src_root, &opts.dest_root, &opts.device)
.context("boot data installation failed")?;
bootupd::install(
&opts.src_root,
&opts.dest_root,
opts.device.as_deref(),
opts.components.as_deref(),
)
.context("boot data installation failed")?;
Ok(())
}
}

0 comments on commit 1aa3c89

Please sign in to comment.