Skip to content

Commit 82de096

Browse files
authored
Merge pull request #1120 from omertuc/promptt
reinstall: Move the no users prompt
2 parents bdc5bed + 7138975 commit 82de096

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

system-reinstall-bootc/src/main.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ pub(crate) mod users;
1111

1212
const ROOT_KEY_MOUNT_POINT: &str = "/bootc_authorized_ssh_keys/root";
1313

14-
const NO_SSH_PROMPT: &str = "None of the users on this system found have authorized SSH keys, if
15-
your image doesn't use cloud-init or other means to set up users, you may not be able to log in
16-
after reinstalling. Do you want to continue?";
17-
1814
fn run() -> Result<()> {
1915
bootc_utils::initialize_tracing();
2016
tracing::trace!("starting {}", env!("CARGO_PKG_NAME"));
@@ -26,7 +22,7 @@ fn run() -> Result<()> {
2622

2723
let root_key = &prompt::get_root_key()?;
2824

29-
if root_key.is_none() && !prompt::ask_yes_no(NO_SSH_PROMPT, false)? {
25+
if root_key.is_none() {
3026
return Ok(());
3127
}
3228

system-reinstall-bootc/src/prompt.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
use crate::users::{get_all_users_keys, UserKeys};
1+
use crate::{
2+
prompt,
3+
users::{get_all_users_keys, UserKeys},
4+
};
25
use anyhow::{ensure, Context, Result};
36

7+
const NO_SSH_PROMPT: &str = "None of the users on this system found have authorized SSH keys, \
8+
if your image doesn't use cloud-init or other means to set up users, \
9+
you may not be able to log in after reinstalling. Do you want to continue?";
10+
411
fn prompt_single_user(user: &crate::users::UserKeys) -> Result<Vec<&crate::users::UserKeys>> {
512
let prompt = format!(
613
"Found only one user ({}) with {} SSH authorized keys. Would you like to import it and its keys to the system?",
@@ -61,6 +68,11 @@ pub(crate) fn ask_yes_no(prompt: &str, default: bool) -> Result<bool> {
6168
pub(crate) fn get_root_key() -> Result<Option<UserKeys>> {
6269
let users = get_all_users_keys()?;
6370
if users.is_empty() {
71+
ensure!(
72+
prompt::ask_yes_no(NO_SSH_PROMPT, false)?,
73+
"cancelled by user"
74+
);
75+
6476
return Ok(None);
6577
}
6678

0 commit comments

Comments
 (0)