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 {
|
|
|
|
public_key: PathBuf,
|
|
|
|
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,
|
|
|
|
bootspec,
|
|
|
|
} => install(&public_key, &bootspec),
|
2022-11-21 19:29:16 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-23 09:26:26 -05:00
|
|
|
fn install(public_key: &Path, 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")?;
|
|
|
|
install::install(
|
|
|
|
public_key,
|
|
|
|
bootspec,
|
|
|
|
Path::new(&lanzaboote_stub),
|
|
|
|
Path::new(&initrd_stub),
|
|
|
|
)
|
2022-11-23 09:26:26 -05:00
|
|
|
}
|