Skip to content

Commit

Permalink
Merge pull request containers#685 from HuijingHei/anaconda-label
Browse files Browse the repository at this point in the history
efi: sync bootentry label with Anaconda
  • Loading branch information
cgwalters authored Jul 16, 2024
2 parents b9fd030 + 47557c3 commit eea4124
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ openat = "0.1.20"
openat-ext = ">= 0.2.2, < 0.3.0"
openssl = "^0.10"
os-release = "0.1.0"
regex = "1.10.4"
rustix = { version = "0.38.34", features = ["process", "fs"] }
serde = { version = "^1.0", features = ["derive"] }
serde_json = "^1.0"
Expand Down
27 changes: 22 additions & 5 deletions src/efi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,17 +139,28 @@ impl Efi {
log::debug!("Not booted via EFI, skipping firmware update");
return Ok(());
}
// Read /etc/os-release
let release: OsRelease = OsRelease::new()?;
let product_name: &str = &release.name;
let product_name = get_product_name()?;
log::debug!("Get product name: {product_name}");
assert!(product_name.len() > 0);
// clear all the boot entries that match the target name
clear_efi_target(product_name)?;
create_efi_boot_entry(device, espdir, vendordir, product_name)
clear_efi_target(&product_name)?;
create_efi_boot_entry(device, espdir, vendordir, &product_name)
}
}

#[context("Get product name")]
fn get_product_name() -> Result<String> {
let file_path = Path::new("/etc/system-release");
if file_path.exists() {
let content = std::fs::read_to_string(file_path)?;
let re = regex::Regex::new(r" *release.*").unwrap();
return Ok(re.replace_all(&content, "").to_string());
}
// Read /etc/os-release
let release: OsRelease = OsRelease::new()?;
Ok(release.name)
}

/// Convert a nul-terminated UTF-16 byte array to a String.
fn string_from_utf16_bytes(slice: &[u8]) -> String {
// For some reason, systemd appends 3 nul bytes after the string.
Expand Down Expand Up @@ -659,4 +670,10 @@ Boot0003* test";
);
Ok(())
}
#[test]
fn test_get_product_name() -> Result<()> {
let name = get_product_name()?;
assert!(name.len() > 0);
Ok(())
}
}

0 comments on commit eea4124

Please sign in to comment.