@@ -6,7 +6,22 @@ use bootc_utils::CommandRunExt;
6
6
use std:: process:: Command ;
7
7
use which:: which;
8
8
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 > {
10
25
let mut podman_command_and_args = [
11
26
// We use podman to run the bootc container. This might change in the future to remove the
12
27
// podman dependency.
@@ -49,13 +64,18 @@ pub(crate) fn reinstall_command(image: &str, ssh_key_file: &str) -> Command {
49
64
// The image is always pulled first, so let's avoid requiring the credentials to be baked
50
65
// in the image for this check.
51
66
"--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" ,
55
67
]
56
68
. map ( String :: from)
57
69
. to_vec ( ) ;
58
70
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
+
59
79
podman_command_and_args. push ( "-v" . to_string ( ) ) ;
60
80
podman_command_and_args. push ( format ! ( "{ssh_key_file}:{ROOT_KEY_MOUNT_POINT}" ) ) ;
61
81
@@ -72,7 +92,7 @@ pub(crate) fn reinstall_command(image: &str, ssh_key_file: &str) -> Command {
72
92
let mut command = Command :: new ( & all_args[ 0 ] ) ;
73
93
command. args ( & all_args[ 1 ..] ) ;
74
94
75
- command
95
+ Ok ( command)
76
96
}
77
97
78
98
pub ( crate ) fn pull_image_command ( image : & str ) -> Command {
0 commit comments