Skip to content

Commit 1137169

Browse files
committed
reinstall: Print reboot message after install completes
Signed-off-by: ckyrouac <[email protected]>
1 parent 0886b20 commit 1137169

File tree

4 files changed

+130
-14
lines changed

4 files changed

+130
-14
lines changed

Cargo.lock

Lines changed: 99 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

system-reinstall-bootc/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ platforms = ["*-unknown-linux-gnu"]
1818
anyhow = { workspace = true }
1919
bootc-utils = { path = "../utils" }
2020
clap = { workspace = true, features = ["derive"] }
21+
crossterm = "0.29.0"
2122
dialoguer = "0.11.0"
2223
indoc = { workspace = true }
2324
log = "0.4.21"

system-reinstall-bootc/src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ fn run() -> Result<()> {
5252
.run_with_cmd_context()
5353
.context("running reinstall command")?;
5454

55+
prompt::reboot()?;
56+
57+
std::process::Command::new("reboot").run()?;
58+
5559
Ok(())
5660
}
5761

system-reinstall-bootc/src/prompt.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use crate::{prompt, users::get_all_users_keys};
22
use anyhow::{ensure, Context, Result};
33

4+
use crossterm::event::{self, Event};
5+
use std::time::Duration;
6+
47
const NO_SSH_PROMPT: &str = "None of the users on this system found have authorized SSH keys, \
58
if your image doesn't use cloud-init or other means to set up users, \
69
you may not be able to log in after reinstalling. Do you want to continue?";
@@ -38,13 +41,35 @@ fn prompt_user_selection(
3841
.collect())
3942
}
4043

44+
pub(crate) fn reboot() -> Result<()> {
45+
let delay_seconds = 10;
46+
println!(
47+
"Operation complete, rebooting in {delay_seconds} seconds. Press Ctrl-C to cancel reboot, or press enter to continue immediately.",
48+
);
49+
50+
let mut elapsed_ms = 0;
51+
let interval = 100;
52+
53+
while elapsed_ms < delay_seconds * 1000 {
54+
if event::poll(Duration::from_millis(0))? {
55+
if let Event::Key(_) = event::read().unwrap() {
56+
break;
57+
}
58+
}
59+
std::thread::sleep(Duration::from_millis(interval));
60+
elapsed_ms += interval;
61+
}
62+
63+
Ok(())
64+
}
65+
4166
/// Temporary safety mechanism to stop devs from running it on their dev machine. TODO: Discuss
4267
/// final prompting UX in https://github.com/containers/bootc/discussions/1060
4368
pub(crate) fn temporary_developer_protection_prompt() -> Result<()> {
4469
// Print an empty line so that the warning stands out from the rest of the output
4570
println!();
4671

47-
let prompt = "THIS WILL REINSTALL YOUR SYSTEM! Are you sure you want to continue?";
72+
let prompt = "NOTICE: This will replace the installed operating system and reboot. Are you sure you want to continue?";
4873
let answer = ask_yes_no(prompt, false)?;
4974

5075
if !answer {

0 commit comments

Comments
 (0)