Skip to content

Commit

Permalink
Merge pull request #1120 from omertuc/promptt
Browse files Browse the repository at this point in the history
reinstall: Move the no users prompt
  • Loading branch information
omertuc authored Feb 18, 2025
2 parents bdc5bed + 7138975 commit 82de096
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
6 changes: 1 addition & 5 deletions system-reinstall-bootc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ pub(crate) mod users;

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

const NO_SSH_PROMPT: &str = "None of the users on this system found have authorized SSH keys, if
your image doesn't use cloud-init or other means to set up users, you may not be able to log in
after reinstalling. Do you want to continue?";

fn run() -> Result<()> {
bootc_utils::initialize_tracing();
tracing::trace!("starting {}", env!("CARGO_PKG_NAME"));
Expand All @@ -26,7 +22,7 @@ fn run() -> Result<()> {

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

if root_key.is_none() && !prompt::ask_yes_no(NO_SSH_PROMPT, false)? {
if root_key.is_none() {
return Ok(());
}

Expand Down
14 changes: 13 additions & 1 deletion system-reinstall-bootc/src/prompt.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
use crate::users::{get_all_users_keys, UserKeys};
use crate::{
prompt,
users::{get_all_users_keys, UserKeys},
};
use anyhow::{ensure, Context, Result};

const NO_SSH_PROMPT: &str = "None of the users on this system found have authorized SSH keys, \
if your image doesn't use cloud-init or other means to set up users, \
you may not be able to log in after reinstalling. Do you want to continue?";

fn prompt_single_user(user: &crate::users::UserKeys) -> Result<Vec<&crate::users::UserKeys>> {
let prompt = format!(
"Found only one user ({}) with {} SSH authorized keys. Would you like to import it and its keys to the system?",
Expand Down Expand Up @@ -61,6 +68,11 @@ pub(crate) fn ask_yes_no(prompt: &str, default: bool) -> Result<bool> {
pub(crate) fn get_root_key() -> Result<Option<UserKeys>> {
let users = get_all_users_keys()?;
if users.is_empty() {
ensure!(
prompt::ask_yes_no(NO_SSH_PROMPT, false)?,
"cancelled by user"
);

return Ok(None);
}

Expand Down

0 comments on commit 82de096

Please sign in to comment.