Skip to content

Commit 8f1e871

Browse files
authored
Merge pull request #1313 from ckyrouac/reinstall-old-fix
reinstall: Only add --cleanup when bootc version >= 1.1.8
2 parents 4978fdd + 0ec300e commit 8f1e871

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-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: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,23 @@ 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+
"--rm",
14+
image,
15+
"bootc",
16+
"install",
17+
"to-existing-root",
18+
"--help",
19+
])
20+
.output()?;
21+
let stdout_str = String::from_utf8_lossy(&output.stdout);
22+
Ok(stdout_str.contains("--cleanup"))
23+
}
24+
25+
pub(crate) fn reinstall_command(image: &str, ssh_key_file: &str) -> Result<Command> {
1026
let mut podman_command_and_args = [
1127
// We use podman to run the bootc container. This might change in the future to remove the
1228
// podman dependency.
@@ -49,13 +65,18 @@ pub(crate) fn reinstall_command(image: &str, ssh_key_file: &str) -> Command {
4965
// The image is always pulled first, so let's avoid requiring the credentials to be baked
5066
// in the image for this check.
5167
"--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",
5568
]
5669
.map(String::from)
5770
.to_vec();
5871

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

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

75-
command
96+
Ok(command)
7697
}
7798

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

0 commit comments

Comments
 (0)