lanzaboote/rust/lanzatool/src/cli.rs

84 lines
1.7 KiB
Rust
Raw Normal View History

2022-11-21 19:29:16 -05:00
use std::path::{Path, PathBuf};
use anyhow::Result;
use clap::{Parser, Subcommand};
2022-11-23 09:30:24 -05:00
use crate::install;
2022-11-21 19:29:16 -05:00
#[derive(Parser)]
pub struct Cli {
#[clap(subcommand)]
pub commands: Commands,
}
#[derive(Subcommand)]
pub enum Commands {
2022-11-23 09:26:26 -05:00
Install {
2022-11-24 08:12:00 -05:00
// Secure Boot Public Key
#[clap(long)]
2022-11-23 09:26:26 -05:00
public_key: PathBuf,
2022-11-24 08:12:00 -05:00
// Secure Boot Private Key
#[clap(long)]
private_key: PathBuf,
// Secure Boot PKI Bundle for auto enrolling key
#[clap(long)]
pki_bundle: PathBuf,
// Enable auto enrolling your keys in UEFI
// Be aware that this might irrevocably brick your device
#[clap(long, default_value = "false")]
auto_enroll: bool,
2022-11-23 09:26:26 -05:00
bootspec: PathBuf,
},
2022-11-21 19:29:16 -05:00
}
impl Cli {
pub fn call(self) -> Result<()> {
self.commands.call()
}
}
impl Commands {
pub fn call(self) -> Result<()> {
match self {
2022-11-23 09:26:26 -05:00
Commands::Install {
public_key,
2022-11-24 08:12:00 -05:00
private_key,
pki_bundle,
auto_enroll,
2022-11-23 09:26:26 -05:00
bootspec,
2022-11-24 08:12:00 -05:00
} => install(
&public_key,
&private_key,
&pki_bundle,
auto_enroll,
&bootspec,
),
2022-11-21 19:29:16 -05:00
}
}
}
2022-11-24 08:12:00 -05:00
fn install(
public_key: &Path,
private_key: &Path,
pki_bundle: &Path,
auto_enroll: bool,
bootspec: &Path,
) -> Result<()> {
2022-11-23 14:40:01 -05:00
let lanzaboote_stub = std::env::var("LANZABOOTE_STUB")?;
let initrd_stub = std::env::var("LANZABOOTE_INITRD_STUB")?;
2022-11-24 08:12:00 -05:00
2022-11-23 14:40:01 -05:00
install::install(
public_key,
2022-11-24 08:12:00 -05:00
private_key,
pki_bundle,
auto_enroll,
2022-11-23 14:40:01 -05:00
bootspec,
Path::new(&lanzaboote_stub),
Path::new(&initrd_stub),
)
2022-11-23 09:26:26 -05:00
}