Skip to content

Commit d88e033

Browse files
committed
reinstall: Only add --cleanup when the feature is available in the image
fixes #1312 Signed-off-by: ckyrouac <ckyrouac@redhat.com>
1 parent 21c57d4 commit d88e033

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

system-reinstall-bootc/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fn run() -> Result<()> {
4141
prompt::get_ssh_keys(ssh_key_file_path)?;
4242

4343
let mut reinstall_podman_command =
44-
podman::reinstall_command(&config.bootc_image, ssh_key_file_path);
44+
podman::reinstall_command(&config.bootc_image, ssh_key_file_path)?;
4545

4646
println!();
4747
println!("Going to run command:");

system-reinstall-bootc/src/podman.rs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,22 @@ use bootc_utils::CommandRunExt;
66
use std::process::Command;
77
use which::which;
88

9-
pub(crate) fn reinstall_command(image: &str, ssh_key_file: &str) -> Command {
9+
fn bootc_has_clean(image: &str) -> Result<bool> {
10+
let output = Command::new("podman")
11+
.args([
12+
"run",
13+
image,
14+
"bootc",
15+
"install",
16+
"to-existing-root",
17+
"--help",
18+
])
19+
.output()?;
20+
let stdout_str = String::from_utf8_lossy(&output.stdout);
21+
Ok(stdout_str.contains("--cleanup"))
22+
}
23+
24+
pub(crate) fn reinstall_command(image: &str, ssh_key_file: &str) -> Result<Command> {
1025
let mut podman_command_and_args = [
1126
// We use podman to run the bootc container. This might change in the future to remove the
1227
// podman dependency.
@@ -49,13 +64,18 @@ pub(crate) fn reinstall_command(image: &str, ssh_key_file: &str) -> Command {
4964
// The image is always pulled first, so let's avoid requiring the credentials to be baked
5065
// in the image for this check.
5166
"--skip-fetch-check",
52-
// Always enable the systemd service to cleanup the previous install after booting into the
53-
// bootc system for the first time
54-
"--cleanup",
5567
]
5668
.map(String::from)
5769
.to_vec();
5870

71+
// Enable the systemd service to cleanup the previous install after booting into the
72+
// bootc system for the first time.
73+
// This only happens if the bootc version in the image >= 1.1.8 (this is when the cleanup
74+
// feature was introduced)
75+
if bootc_has_clean(image)? {
76+
bootc_command_and_args.push("--cleanup".to_string());
77+
}
78+
5979
podman_command_and_args.push("-v".to_string());
6080
podman_command_and_args.push(format!("{ssh_key_file}:{ROOT_KEY_MOUNT_POINT}"));
6181

@@ -72,7 +92,7 @@ pub(crate) fn reinstall_command(image: &str, ssh_key_file: &str) -> Command {
7292
let mut command = Command::new(&all_args[0]);
7393
command.args(&all_args[1..]);
7494

75-
command
95+
Ok(command)
7696
}
7797

7898
pub(crate) fn pull_image_command(image: &str) -> Command {

0 commit comments

Comments
 (0)