22
33use anyhow:: { Context , Result , anyhow, bail} ;
44use serde_json:: Value ;
5+ use std:: path:: Path ;
56use std:: process:: Command ;
67use std:: str;
78
89use crate :: grub:: get_boot_counter;
910
10- /// Detects if the system is managed by bootc or is a rpm-ostree system
11- /// Inspect bootc status JSON and decide based on `status.booted.incompatible`.
11+ /// Detects if the system is managed by bootc or is a rpm-ostree system.
12+ /// First checks for `/run/ostree-booted`, then inspects `status.booted.image`
13+ /// from `bootc status --booted --json` to distinguish between the two.
1214pub fn detect_os_deployment ( ) -> Option < & ' static str > {
15+ if !Path :: new ( "/run/ostree-booted" ) . exists ( ) {
16+ log:: info!( "'/run/ostree-booted' not found, not an ostree-based system" ) ;
17+ return None ;
18+ }
19+
1320 let output = match Command :: new ( "bootc" )
1421 . args ( [ "status" , "--booted" , "--json" ] )
1522 . output ( )
@@ -31,24 +38,17 @@ pub fn detect_os_deployment() -> Option<&'static str> {
3138 }
3239 } ;
3340
34- match json
41+ if let Some ( image_type ) = json
3542 . get ( "status" )
3643 . and_then ( |s| s. get ( "booted" ) )
37- . and_then ( |b| b. get ( "incompatible " ) )
38- . and_then ( |i| i . as_bool ( ) )
44+ . and_then ( |b| b. get ( "image " ) )
45+ . filter ( |v| !v . is_null ( ) )
3946 {
40- Some ( true ) => {
41- log:: info!( "System detected as rpm-ostree (incompatible=true)" ) ;
42- Some ( "rpm-ostree" )
43- }
44- Some ( false ) => {
45- log:: info!( "System detected as bootc (incompatible=false)" ) ;
46- Some ( "bootc" )
47- }
48- None => {
49- log:: error!( "bootc status JSON missing boolean field status.booted.incompatible" ) ;
50- None
51- }
47+ log:: info!( "System detected as bootc (status.booted.image: {image_type})" ) ;
48+ Some ( "bootc" )
49+ } else {
50+ log:: info!( "System detected as rpm-ostree (status.booted.image is null or absent)" ) ;
51+ Some ( "rpm-ostree" )
5252 }
5353}
5454
0 commit comments