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?";
@@ -9,7 +12,8 @@ fn prompt_single_user(user: &crate::users::UserKeys) -> Result<Vec<&crate::users
9
12
let prompt = indoc:: formatdoc! {
10
13
"Found only one user ({user}) with {num_keys} SSH authorized keys.
11
14
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." ,
13
17
user = user. user,
14
18
num_keys = user. num_keys( ) ,
15
19
} ;
@@ -25,8 +29,10 @@ fn prompt_user_selection(
25
29
// TODO: Handle https://github.com/console-rs/dialoguer/issues/77
26
30
let selected_user_indices: Vec < usize > = dialoguer:: MultiSelect :: new ( )
27
31
. 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)" ,
30
36
} )
31
37
. items ( & keys)
32
38
. interact ( ) ?;
@@ -38,13 +44,35 @@ fn prompt_user_selection(
38
44
. collect ( ) )
39
45
}
40
46
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
+
41
69
/// Temporary safety mechanism to stop devs from running it on their dev machine. TODO: Discuss
42
70
/// final prompting UX in https://github.com/containers/bootc/discussions/1060
43
71
pub ( crate ) fn temporary_developer_protection_prompt ( ) -> Result < ( ) > {
44
72
// Print an empty line so that the warning stands out from the rest of the output
45
73
println ! ( ) ;
46
74
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?" ;
48
76
let answer = ask_yes_no ( prompt, false ) ?;
49
77
50
78
if !answer {
0 commit comments