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 ( )
@@ -34,19 +41,18 @@ pub fn detect_os_deployment() -> Option<&'static str> {
3441 match 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" ) )
3945 {
40- Some ( true ) => {
41- log:: info!( "System detected as rpm-ostree (incompatible=true )" ) ;
46+ Some ( image ) if image . is_null ( ) => {
47+ log:: info!( "System detected as rpm-ostree (status.booted.image is null )" ) ;
4248 Some ( "rpm-ostree" )
4349 }
44- Some ( false ) => {
45- log:: info!( "System detected as bootc (incompatible=false )" ) ;
50+ Some ( _ ) => {
51+ log:: info!( "System detected as bootc (status.booted.image is present )" ) ;
4652 Some ( "bootc" )
4753 }
4854 None => {
49- log:: error!( "bootc status JSON missing boolean field status.booted.incompatible " ) ;
55+ log:: error!( "bootc status JSON missing field status.booted.image " ) ;
5056 None
5157 }
5258 }
0 commit comments