|
1 | 1 | use crate::{prompt, users::get_all_users_keys};
|
2 | 2 | use anyhow::{ensure, Context, Result};
|
3 | 3 |
|
| 4 | +use crossterm::event::{self, Event}; |
| 5 | +use std::time::Duration; |
| 6 | + |
4 | 7 | const NO_SSH_PROMPT: &str = "None of the users on this system found have authorized SSH keys, \
|
5 | 8 | if your image doesn't use cloud-init or other means to set up users, \
|
6 | 9 | you may not be able to log in after reinstalling. Do you want to continue?";
|
@@ -38,13 +41,35 @@ fn prompt_user_selection(
|
38 | 41 | .collect())
|
39 | 42 | }
|
40 | 43 |
|
| 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 | + |
41 | 66 | /// Temporary safety mechanism to stop devs from running it on their dev machine. TODO: Discuss
|
42 | 67 | /// final prompting UX in https://github.com/containers/bootc/discussions/1060
|
43 | 68 | pub(crate) fn temporary_developer_protection_prompt() -> Result<()> {
|
44 | 69 | // Print an empty line so that the warning stands out from the rest of the output
|
45 | 70 | println!();
|
46 | 71 |
|
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?"; |
48 | 73 | let answer = ask_yes_no(prompt, false)?;
|
49 | 74 |
|
50 | 75 | if !answer {
|
|
0 commit comments