Skip to content

Commit f465f1c

Browse files
authored
Merge pull request #1268 from ckyrouac/reinstall-prompt-tweaks
Reinstall prompt tweaks
2 parents 7bcb8b1 + d457c25 commit f465f1c

File tree

4 files changed

+136
-17
lines changed

4 files changed

+136
-17
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: 32 additions & 4 deletions
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?";
@@ -9,7 +12,8 @@ fn prompt_single_user(user: &crate::users::UserKeys) -> Result<Vec<&crate::users
912
let prompt = indoc::formatdoc! {
1013
"Found only one user ({user}) with {num_keys} SSH authorized keys.
1114
Would you like to import its SSH authorized keys
12-
into the root user on the new bootc system?",
15+
into the root user on the new bootc system?
16+
Then you can login as root@ using those keys.",
1317
user = user.user,
1418
num_keys = user.num_keys(),
1519
};
@@ -25,8 +29,10 @@ fn prompt_user_selection(
2529
// TODO: Handle https://github.com/console-rs/dialoguer/issues/77
2630
let selected_user_indices: Vec<usize> = dialoguer::MultiSelect::new()
2731
.with_prompt(indoc::indoc! {
28-
"Select which user's SSH authorized keys you want to
29-
import into the root user of the new bootc system",
32+
"Select which user's SSH authorized keys you want to import into
33+
the root user of the new bootc system.
34+
Then you can login as root@ using those keys.
35+
(arrow keys to move, space to select)",
3036
})
3137
.items(&keys)
3238
.interact()?;
@@ -38,13 +44,35 @@ fn prompt_user_selection(
3844
.collect())
3945
}
4046

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

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

5078
if !answer {

0 commit comments

Comments
 (0)