|
1 |
| -use std::process::Command; |
2 |
| - |
3 | 1 | use super::ROOT_KEY_MOUNT_POINT;
|
4 | 2 | use crate::users::UserKeys;
|
| 3 | +use anyhow::{ensure, Context, Result}; |
| 4 | +use bootc_utils::CommandRunExt; |
| 5 | +use std::process::Command; |
| 6 | +use which::which; |
5 | 7 |
|
6 | 8 | pub(crate) fn command(image: &str, root_key: &Option<UserKeys>) -> Command {
|
7 | 9 | let mut podman_command_and_args = [
|
@@ -58,3 +60,42 @@ pub(crate) fn command(image: &str, root_key: &Option<UserKeys>) -> Command {
|
58 | 60 |
|
59 | 61 | command
|
60 | 62 | }
|
| 63 | + |
| 64 | +/// Path to the podman installation script. Can be influenced by the build |
| 65 | +/// SYSTEM_REINSTALL_BOOTC_INSTALL_PODMAN_PATH parameter to override. Defaults |
| 66 | +/// to /usr/lib/system-reinstall-bootc/install-podman |
| 67 | +const fn podman_install_script_path() -> &'static str { |
| 68 | + if let Some(path) = option_env!("SYSTEM_REINSTALL_BOOTC_INSTALL_PODMAN_PATH") { |
| 69 | + path |
| 70 | + } else { |
| 71 | + "/usr/lib/system-reinstall-bootc/install-podman" |
| 72 | + } |
| 73 | +} |
| 74 | + |
| 75 | +pub(crate) fn ensure_podman_installed() -> Result<()> { |
| 76 | + if which("podman").is_ok() { |
| 77 | + return Ok(()); |
| 78 | + } |
| 79 | + |
| 80 | + tracing::warn!( |
| 81 | + "Podman was not found on this system. It's required in order to install a bootc image." |
| 82 | + ); |
| 83 | + |
| 84 | + ensure!( |
| 85 | + which(podman_install_script_path()).is_ok(), |
| 86 | + "Podman installation script {} not found, cannot automatically install podman. Please install it manually and try again.", |
| 87 | + podman_install_script_path() |
| 88 | + ); |
| 89 | + |
| 90 | + Command::new(podman_install_script_path()) |
| 91 | + .run_with_cmd_context() |
| 92 | + .context("installing podman")?; |
| 93 | + |
| 94 | + // Make sure the installation was actually successful |
| 95 | + ensure!( |
| 96 | + which("podman").is_ok(), |
| 97 | + "podman still doesn't seem to be available, despite the installation. Please install it manually and try again." |
| 98 | + ); |
| 99 | + |
| 100 | + Ok(()) |
| 101 | +} |
0 commit comments