use std::path::PathBuf; use anyhow::{Result, bail}; use crate::cmd::cryptsetup; use crate::config; pub fn decrypt_backup(pools: &config::BackupPools) -> Result<(String, String)> { let mut pathbuf = PathBuf::new(); let mut found = false; let mut the_name = String::new(); let mut the_crypt_device = String::new(); for (device, name) in [&pools.backup1, &pools.backup2] .iter() .zip(["backup1", "backup2"]) { pathbuf.push("/dev/disk/by-uuid/"); pathbuf.push(device); if pathbuf.exists() { found = true; the_name = name.to_string(); the_crypt_device.push_str("crypt-"); the_crypt_device.push_str(name); // content is then e.g. "crypt-backup1" println!("found backup disk {name}, will decrypt to {the_crypt_device}"); break; } } if found { cryptsetup::open(&pathbuf, &the_crypt_device)?; Ok((the_name, the_crypt_device)) } else { bail!("no backup disk found") } } pub fn encrypt_backup(crypt_device: String) -> Result<()> { println!("encrypting {crypt_device}"); cryptsetup::close(&crypt_device) }