Skip to content

Commit

Permalink
efi: sync bootentry lable with Anaconda
Browse files Browse the repository at this point in the history
  • Loading branch information
HuijingHei committed Jul 10, 2024
1 parent 8a472ea commit e8e4bf5
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,14 +139,25 @@ 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)
}
}

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());
} else {
// Read /etc/os-release
let release: OsRelease = OsRelease::new()?;
return Ok(release.name);
}
}

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 e8e4bf5

Please sign in to comment.