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-12-11 20:09:19 -05:00
|
|
|
/// Configuration limit
|
|
|
|
#[arg(long, default_value_t = 1)]
|
|
|
|
configuration_limit: usize,
|
|
|
|
|
2022-11-26 18:12:00 -05:00
|
|
|
/// EFI system partition mountpoint (e.g. efiSysMountPoint)
|
2022-11-26 16:23:00 -05:00
|
|
|
esp: PathBuf,
|
2022-11-25 21:14:21 -05:00
|
|
|
|
2022-12-11 20:09:19 -05:00
|
|
|
/// List of generation links (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,
|
2022-12-11 20:09:19 -05:00
|
|
|
args.configuration_limit,
|
2022-11-26 16:23:00 -05:00
|
|
|
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
|
|
|
}
|