Skip to content

reinstall: Move the no users prompt #1120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 install this user in 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