@@ -6,7 +6,23 @@ use bootc_utils::CommandRunExt;
66use std:: process:: Command ;
77use 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
7899pub ( crate ) fn pull_image_command ( image : & str ) -> Command {
0 commit comments