lanzaboote/rust/lanzatool/src/cli.rs

65 lines
1.3 KiB
Rust
Raw Normal View History

2022-11-26 08:55:15 -05:00
use std::path::PathBuf;
2022-11-21 19:29:16 -05:00
2022-11-25 17:48:20 -05:00
use anyhow::{Context, Result};
2022-11-21 19:29:16 -05:00
use clap::{Parser, Subcommand};
2022-11-23 09:30:24 -05:00
use crate::install;
2022-11-26 17:19:08 -05:00
use crate::signature::KeyPair;
2022-11-21 19:29:16 -05:00
#[derive(Parser)]
pub struct Cli {
#[clap(subcommand)]
2022-11-26 08:55:15 -05:00
commands: Commands,
2022-11-21 19:29:16 -05:00
}
#[derive(Subcommand)]
2022-11-26 08:55:15 -05:00
enum Commands {
Install(InstallCommand),
}
#[derive(Parser)]
struct InstallCommand {
2022-11-26 18:12:00 -05:00
/// sbsign Public Key
2022-11-26 08:55:15 -05:00
#[arg(long)]
public_key: PathBuf,
2022-11-24 08:12:00 -05:00
2022-11-26 18:12:00 -05:00
/// sbsign Private Key
2022-11-26 08:55:15 -05:00
#[arg(long)]
private_key: PathBuf,
2022-11-24 08:12:00 -05:00
2022-11-26 18:12:00 -05:00
/// EFI system partition mountpoint (e.g. efiSysMountPoint)
esp: PathBuf,
2022-11-26 18:12:00 -05:00
/// List of generations (e.g. /nix/var/nix/profiles/system-*-link)
2022-11-26 08:55:15 -05:00
generations: Vec<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-26 08:55:15 -05:00
Commands::Install(args) => install(args),
2022-11-21 19:29:16 -05:00
}
}
}
2022-11-26 08:55:15 -05:00
fn install(args: InstallCommand) -> Result<()> {
2022-11-25 17:48:20 -05:00
let lanzaboote_stub =
std::env::var("LANZABOOTE_STUB").context("Failed to read LANZABOOTE_STUB env variable")?;
2022-11-24 08:12:00 -05:00
2022-11-26 17:19:08 -05:00
let key_pair = KeyPair::new(&args.public_key, &args.private_key);
2022-11-26 08:55:15 -05:00
install::Installer::new(
PathBuf::from(lanzaboote_stub),
2022-11-26 17:19:08 -05:00
key_pair,
args.esp,
2022-11-26 08:55:15 -05:00
args.generations,
2022-11-23 14:40:01 -05:00
)
2022-11-26 08:55:15 -05:00
.install()
2022-11-23 09:26:26 -05:00
}