diff --git a/sw/deployer/src/main.rs b/sw/deployer/src/main.rs index 457c500..7ae33af 100644 --- a/sw/deployer/src/main.rs +++ b/sw/deployer/src/main.rs @@ -9,7 +9,7 @@ use colored::Colorize; use panic_message::panic_message; use std::{ fs::File, - io::{stdout, BufReader, Read, Write}, + io::{stdin, stdout, BufReader, Read, Write}, path::PathBuf, sync::{ atomic::{AtomicBool, Ordering}, @@ -532,7 +532,7 @@ fn handle_firmware_command( let metadata = sc64::firmware::verify(&firmware)?; println!("{}", "Firmware metadata:".bold()); - println!("{}", metadata); + println!("{}", format!("{}", metadata).blue().to_string()); Ok(()) } @@ -551,7 +551,7 @@ fn handle_firmware_command( let metadata = sc64::firmware::verify(&firmware)?; println!("{}", "Firmware metadata:".bold()); - println!("{}", metadata); + println!("{}", format!("{}", metadata).blue().to_string()); backup_file.write_all(&firmware)?; @@ -568,7 +568,12 @@ fn handle_firmware_command( let metadata = sc64::firmware::verify(&firmware)?; println!("{}", "Firmware metadata:".bold()); - println!("{}", metadata); + println!("{}", format!("{}", metadata).blue().to_string()); + println!("{}", "Firmware file verification was successful".green()); + let answer = prompt(format!("{}", "Continue with update process? [y/N] ".bold())); + if answer.to_ascii_lowercase() != "y" { + panic!("Firmware update process aborted"); + } sc64.reset_state()?; @@ -622,6 +627,14 @@ fn log_wait Result, T, E>(message: String, operation: F) -> result } +fn prompt(message: String) -> String { + print!("{message}"); + stdout().flush().unwrap(); + let mut answer = String::new(); + stdin().read_line(&mut answer).unwrap(); + answer.trim_end().to_string() +} + fn open_file(path: &PathBuf) -> Result<(File, String, usize), sc64::Error> { let name: String = path.file_name().unwrap().to_string_lossy().to_string(); let file = File::open(path)?;