1
- #[ cfg( any( target_arch = "x86_64" , target_arch = "powerpc64" ) ) ]
1
+ #[ cfg( all(
2
+ any( target_arch = "x86_64" , target_arch = "powerpc64" ) ,
3
+ feature = "grub"
4
+ ) ) ]
2
5
use crate :: bios;
3
6
use crate :: component;
4
- use crate :: component:: { Component , ValidationResult } ;
7
+ use crate :: component:: Component ;
8
+ #[ cfg( feature = "grub" ) ]
9
+ use crate :: component:: ValidationResult ;
5
10
use crate :: coreos;
6
11
#[ cfg( any(
7
12
target_arch = "x86_64" ,
8
13
target_arch = "aarch64" ,
9
14
target_arch = "riscv64"
10
15
) ) ]
11
16
use crate :: efi;
17
+
18
+ #[ cfg( feature = "grub" ) ]
12
19
use crate :: freezethaw:: fsfreeze_thaw_cycle;
13
20
use crate :: model:: { ComponentStatus , ComponentUpdatable , ContentMetadata , SavedState , Status } ;
14
- use crate :: { ostreeutil, util} ;
21
+ #[ cfg( feature = "grub" ) ]
22
+ use crate :: ostreeutil;
23
+ use crate :: util;
15
24
use anyhow:: { anyhow, bail, Context , Result } ;
16
25
use camino:: { Utf8Path , Utf8PathBuf } ;
26
+ #[ cfg( feature = "grub" ) ]
17
27
use clap:: crate_version;
28
+ #[ cfg( feature = "grub" ) ]
18
29
use fn_error_context:: context;
30
+ #[ cfg( feature = "grub" ) ]
19
31
use libc:: mode_t;
32
+ #[ cfg( feature = "grub" ) ]
20
33
use libc:: { S_IRGRP , S_IROTH , S_IRUSR , S_IWUSR } ;
21
34
use serde:: { Deserialize , Serialize } ;
22
35
use std:: borrow:: Cow ;
23
36
use std:: collections:: BTreeMap ;
37
+
38
+ #[ cfg( feature = "grub" ) ]
24
39
use std:: fs:: { self , File } ;
25
- use std:: io:: { BufRead , BufReader , BufWriter , Write } ;
26
- use std:: path:: { Path , PathBuf } ;
40
+ #[ cfg( feature = "grub" ) ]
41
+ use std:: io:: { BufRead , BufWriter , Write } ;
42
+
43
+ #[ cfg( feature = "grub" ) ]
44
+ use std:: io:: BufReader ;
45
+ use std:: path:: Path ;
46
+ #[ cfg( feature = "grub" ) ]
47
+ use std:: path:: PathBuf ;
27
48
28
49
#[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
29
50
pub ( crate ) enum ConfigMode {
30
51
None ,
31
52
Static ,
32
53
WithUUID ,
33
- SystemdBoot ,
34
54
}
35
55
56
+ #[ cfg( feature = "grub" ) ]
36
57
impl ConfigMode {
37
58
pub ( crate ) fn enabled_with_uuid ( & self ) -> Option < bool > {
38
59
match self {
39
60
ConfigMode :: None => None ,
40
61
ConfigMode :: Static => Some ( false ) ,
41
62
ConfigMode :: WithUUID => Some ( true ) ,
42
- ConfigMode :: SystemdBoot => Some ( false ) ,
43
63
}
44
64
}
45
65
}
@@ -48,7 +68,8 @@ pub(crate) fn install(
48
68
source_root : & str ,
49
69
dest_root : & str ,
50
70
device : Option < & str > ,
51
- configs : ConfigMode ,
71
+ #[ cfg( feature = "grub" ) ] configs : ConfigMode ,
72
+ #[ cfg( not( feature = "grub" ) ) ] _configs : ConfigMode ,
52
73
update_firmware : bool ,
53
74
target_components : Option < & [ String ] > ,
54
75
auto_components : bool ,
@@ -85,6 +106,7 @@ pub(crate) fn install(
85
106
}
86
107
87
108
let mut state = SavedState :: default ( ) ;
109
+ #[ cfg( feature = "grub" ) ]
88
110
let mut installed_efi_vendor = None ;
89
111
for & component in target_components. iter ( ) {
90
112
// skip for BIOS if device is empty
@@ -101,18 +123,18 @@ pub(crate) fn install(
101
123
. with_context ( || format ! ( "installing component {}" , component. name( ) ) ) ?;
102
124
log:: info!( "Installed {} {}" , component. name( ) , meta. meta. version) ;
103
125
state. installed . insert ( component. name ( ) . into ( ) , meta) ;
104
- // If not systemd-boot, try to get the efi vendor
105
- if configs != ConfigMode :: SystemdBoot {
106
- // Yes this is a hack...the Component thing just turns out to be too generic.
107
- if let Some ( vendor) = component. get_efi_vendor ( & source_root) ? {
108
- assert ! ( installed_efi_vendor. is_none( ) ) ;
109
- installed_efi_vendor = Some ( vendor) ;
110
- }
126
+
127
+ // Yes this is a hack...the Component thing just turns out to be too generic.
128
+ #[ cfg( feature = "grub" ) ]
129
+ if let Some ( vendor) = component. get_efi_vendor ( & source_root) ? {
130
+ assert ! ( installed_efi_vendor. is_none( ) ) ;
131
+ installed_efi_vendor = Some ( vendor) ;
111
132
}
112
133
}
113
134
114
135
let sysroot = & openat:: Dir :: open ( dest_root) ?;
115
136
137
+ #[ cfg( feature = "grub" ) ]
116
138
match configs. enabled_with_uuid ( ) {
117
139
Some ( uuid) => {
118
140
let meta = get_static_config_meta ( ) ?;
@@ -129,7 +151,8 @@ pub(crate) fn install(
129
151
None => { }
130
152
}
131
153
132
- if configs == ConfigMode :: SystemdBoot {
154
+ #[ cfg( feature = "systemd-boot" ) ]
155
+ {
133
156
let efi = crate :: efi:: Efi :: default ( ) ;
134
157
log:: warn!( "Installing systemd-boot entries" ) ;
135
158
if let Ok ( Some ( mnt) ) = efi. get_mounted_esp ( Path :: new ( dest_root) ) {
@@ -153,6 +176,7 @@ pub(crate) fn install(
153
176
}
154
177
155
178
#[ context( "Get static config metadata" ) ]
179
+ #[ cfg( feature = "grub" ) ]
156
180
fn get_static_config_meta ( ) -> Result < ContentMetadata > {
157
181
let self_bin_meta = std:: fs:: metadata ( "/proc/self/exe" ) . context ( "Querying self meta" ) ?;
158
182
let self_meta = ContentMetadata {
@@ -185,9 +209,11 @@ pub(crate) fn get_components_impl(auto: bool) -> Components {
185
209
if is_efi_booted {
186
210
insert_component ( & mut components, Box :: new ( efi:: Efi :: default ( ) ) ) ;
187
211
} else {
212
+ #[ cfg( feature = "grub" ) ]
188
213
insert_component ( & mut components, Box :: new ( bios:: Bios :: default ( ) ) ) ;
189
214
}
190
215
} else {
216
+ #[ cfg( feature = "grub" ) ]
191
217
insert_component ( & mut components, Box :: new ( bios:: Bios :: default ( ) ) ) ;
192
218
insert_component ( & mut components, Box :: new ( efi:: Efi :: default ( ) ) ) ;
193
219
}
@@ -281,6 +307,7 @@ pub(crate) fn update(name: &str, rootcxt: &RootContext) -> Result<ComponentUpdat
281
307
}
282
308
283
309
/// daemon implementation of component adoption
310
+ #[ cfg( feature = "grub" ) ]
284
311
pub ( crate ) fn adopt_and_update (
285
312
name : & str ,
286
313
rootcxt : & RootContext ,
@@ -327,6 +354,7 @@ pub(crate) fn adopt_and_update(
327
354
}
328
355
329
356
/// daemon implementation of component validate
357
+ #[ cfg( feature = "grub" ) ]
330
358
pub ( crate ) fn validate ( name : & str ) -> Result < ValidationResult > {
331
359
let state = SavedState :: load_from_disk ( "/" ) ?. unwrap_or_default ( ) ;
332
360
let component = component:: new_from_name ( name) ?;
@@ -532,6 +560,8 @@ pub(crate) fn client_run_update() -> Result<()> {
532
560
}
533
561
updated = true ;
534
562
}
563
+
564
+ #[ cfg( feature = "grub" ) ]
535
565
for ( name, adoptable) in status. adoptable . iter ( ) {
536
566
if adoptable. confident {
537
567
if let Some ( r) = adopt_and_update ( name, & rootcxt, false ) ? {
@@ -548,6 +578,7 @@ pub(crate) fn client_run_update() -> Result<()> {
548
578
Ok ( ( ) )
549
579
}
550
580
581
+ #[ cfg( feature = "grub" ) ]
551
582
pub ( crate ) fn client_run_adopt_and_update ( with_static_config : bool ) -> Result < ( ) > {
552
583
let rootcxt = prep_before_update ( ) ?;
553
584
let status: Status = status ( ) ?;
@@ -563,6 +594,7 @@ pub(crate) fn client_run_adopt_and_update(with_static_config: bool) -> Result<()
563
594
Ok ( ( ) )
564
595
}
565
596
597
+ #[ cfg( feature = "grub" ) ]
566
598
pub ( crate ) fn client_run_validate ( ) -> Result < ( ) > {
567
599
let status: Status = status ( ) ?;
568
600
if status. components . is_empty ( ) {
@@ -593,6 +625,7 @@ pub(crate) fn client_run_validate() -> Result<()> {
593
625
}
594
626
595
627
#[ context( "Migrating to a static GRUB config" ) ]
628
+ #[ cfg( feature = "grub" ) ]
596
629
pub ( crate ) fn client_run_migrate_static_grub_config ( ) -> Result < ( ) > {
597
630
// Did we already complete the migration?
598
631
// We need to migrate if bootloader is not none (or not set)
@@ -679,6 +712,7 @@ pub(crate) fn client_run_migrate_static_grub_config() -> Result<()> {
679
712
680
713
/// Writes a stripped GRUB config to `stripped_config_name`, removing lines between
681
714
/// `### BEGIN /etc/grub.d/15_ostree ###` and `### END /etc/grub.d/15_ostree ###`.
715
+ #[ cfg( feature = "grub" ) ]
682
716
fn strip_grub_config_file (
683
717
current_config_content : impl BufRead ,
684
718
dirfd : & openat:: Dir ,
@@ -739,6 +773,7 @@ mod tests {
739
773
}
740
774
741
775
#[ test]
776
+ #[ cfg( feature = "grub" ) ]
742
777
fn test_strip_grub_config_file ( ) -> Result < ( ) > {
743
778
let root: & tempfile:: TempDir = & tempfile:: tempdir ( ) ?;
744
779
let root_path = root. path ( ) ;
0 commit comments