11use crate :: { prompt, users:: get_all_users_keys} ;
22use anyhow:: { ensure, Context , Result } ;
33
4+ use crossterm:: event:: { self , Event } ;
5+ use std:: time:: Duration ;
6+
47const 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
4371pub ( 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