mirror of
https://github.com/edera-dev/sprout.git
synced 2025-12-19 10:10:17 +00:00
feat(config): support for setting the default entry to boot
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
version = 1
|
version = 1
|
||||||
|
|
||||||
|
[defaults]
|
||||||
|
entry = "edera"
|
||||||
|
|
||||||
[extractors.boot.filesystem-device-match]
|
[extractors.boot.filesystem-device-match]
|
||||||
has-item = "\\EFI\\BOOT\\xen.efi"
|
has-item = "\\EFI\\BOOT\\xen.efi"
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
version = 1
|
version = 1
|
||||||
|
|
||||||
|
[defaults]
|
||||||
|
entry = "kernel"
|
||||||
|
|
||||||
[extractors.boot.filesystem-device-match]
|
[extractors.boot.filesystem-device-match]
|
||||||
has-item = "\\EFI\\BOOT\\kernel.efi"
|
has-item = "\\EFI\\BOOT\\kernel.efi"
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
version = 1
|
version = 1
|
||||||
|
|
||||||
|
[defaults]
|
||||||
|
entry = "shell"
|
||||||
|
|
||||||
[extractors.boot.filesystem-device-match]
|
[extractors.boot.filesystem-device-match]
|
||||||
has-item = "\\EFI\\BOOT\\shell.efi"
|
has-item = "\\EFI\\BOOT\\shell.efi"
|
||||||
|
|
||||||
[actions.chainload-shell]
|
[actions.chainload-shell]
|
||||||
chainload.path = "$boot\\EFI\\BOOT\\shell.efi"
|
chainload.path = "$boot\\EFI\\BOOT\\shell.efi"
|
||||||
|
|
||||||
[entries.xen]
|
[entries.shell]
|
||||||
title = "Boot Shell"
|
title = "Boot Shell"
|
||||||
actions = ["chainload-shell"]
|
actions = ["chainload-shell"]
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
version = 1
|
version = 1
|
||||||
|
|
||||||
|
[defaults]
|
||||||
|
entry = "xen"
|
||||||
|
|
||||||
[extractors.boot.filesystem-device-match]
|
[extractors.boot.filesystem-device-match]
|
||||||
has-item = "\\EFI\\BOOT\\xen.efi"
|
has-item = "\\EFI\\BOOT\\xen.efi"
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,9 @@ pub struct RootConfiguration {
|
|||||||
/// the configuration is the latest version.
|
/// the configuration is the latest version.
|
||||||
#[serde(default = "latest_version")]
|
#[serde(default = "latest_version")]
|
||||||
pub version: u32,
|
pub version: u32,
|
||||||
|
/// Default options for Sprout.
|
||||||
|
#[serde(default)]
|
||||||
|
pub defaults: DefaultsConfiguration,
|
||||||
/// Values to be inserted into the root sprout context.
|
/// Values to be inserted into the root sprout context.
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub values: BTreeMap<String, String>,
|
pub values: BTreeMap<String, String>,
|
||||||
@@ -59,6 +62,14 @@ pub struct RootConfiguration {
|
|||||||
pub phases: PhasesConfiguration,
|
pub phases: PhasesConfiguration,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Default configuration for Sprout, used when the corresponding options are not specified.
|
||||||
|
#[derive(Serialize, Deserialize, Default, Clone)]
|
||||||
|
pub struct DefaultsConfiguration {
|
||||||
|
/// The entry to boot without showing the boot menu.
|
||||||
|
/// If not specified, a boot menu is shown.
|
||||||
|
pub entry: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
fn latest_version() -> u32 {
|
fn latest_version() -> u32 {
|
||||||
LATEST_VERSION
|
LATEST_VERSION
|
||||||
}
|
}
|
||||||
|
|||||||
14
src/main.rs
14
src/main.rs
@@ -164,13 +164,23 @@ fn main() -> Result<()> {
|
|||||||
// Execute the late phase.
|
// Execute the late phase.
|
||||||
phase(context.clone(), &config.phases.late).context("unable to execute late phase")?;
|
phase(context.clone(), &config.phases.late).context("unable to execute late phase")?;
|
||||||
|
|
||||||
|
// If --boot is specified, or defaults.entry is specified, use that to find the entry to boot.
|
||||||
|
let boot = context
|
||||||
|
.root()
|
||||||
|
.options()
|
||||||
|
.boot
|
||||||
|
.as_ref()
|
||||||
|
.or(config.defaults.entry.as_ref());
|
||||||
|
|
||||||
// Use the boot option if possible, otherwise pick the first entry.
|
// Use the boot option if possible, otherwise pick the first entry.
|
||||||
let entry = if let Some(ref boot) = context.root().options().boot {
|
let entry = if let Some(ref boot) = boot {
|
||||||
entries
|
entries
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.find(|(index, entry)| {
|
.find(|(index, entry)| {
|
||||||
entry.name() == boot || entry.title() == boot || &index.to_string() == boot
|
entry.name() == boot.as_str()
|
||||||
|
|| entry.title() == boot.as_str()
|
||||||
|
|| index.to_string() == boot.as_str()
|
||||||
})
|
})
|
||||||
.context(format!("unable to find entry: {boot}"))?
|
.context(format!("unable to find entry: {boot}"))?
|
||||||
.1 // select the bootable entry.
|
.1 // select the bootable entry.
|
||||||
|
|||||||
Reference in New Issue
Block a user