@@ -30,6 +30,8 @@ use crate::{
30
30
stage, util,
31
31
} ;
32
32
33
+ use super :: repart_output:: CryptData ;
34
+
33
35
pub static IPC_CHANNEL : OnceLock < Mutex < IpcSender < InstallationMessage > > > = OnceLock :: new ( ) ;
34
36
35
37
#[ derive( Debug , Clone , Copy , Serialize , Deserialize , PartialEq , Eq ) ]
@@ -193,20 +195,18 @@ impl InstallationState {
193
195
}
194
196
}
195
197
196
-
197
198
/// Copies the current config into a temporary directory, allowing them to be modified without
198
199
/// affecting the original templates :D
199
200
fn layer_configdir ( & self , cfg_dir : & Path ) -> Result < PathBuf > {
200
-
201
201
// /run/readymade-install
202
202
let new_path = PathBuf :: from ( "/run" ) . join ( "readymade-install" ) ;
203
203
std:: fs:: create_dir_all ( & new_path) ?;
204
204
// Copy the contents of the cfg_dir to the new path
205
205
util:: fs:: copy_dir ( cfg_dir, "/run/readymade-install" ) ?;
206
-
206
+
207
207
Ok ( new_path)
208
208
}
209
-
209
+
210
210
#[ allow( clippy:: unwrap_in_result) ]
211
211
#[ tracing:: instrument]
212
212
pub fn install ( & self ) -> Result < ( ) > {
@@ -220,9 +220,8 @@ impl InstallationState {
220
220
let blockdev = & ( self . destination_disk . as_ref ( ) )
221
221
. expect ( "A valid destination device should be set before calling install()" )
222
222
. devpath ;
223
-
224
- // let cfgdir = inst_type.cfgdir();
225
-
223
+
224
+ tracing:: info!( "Layering repart templates" ) ;
226
225
let cfgdir = self . layer_configdir ( & inst_type. cfgdir ( ) ) ?;
227
226
228
227
// Let's write the encryption key to the keyfile
@@ -252,6 +251,10 @@ impl InstallationState {
252
251
253
252
#[ tracing:: instrument]
254
253
fn setup_system ( & self , output : RepartOutput , passphrase : Option < & str > ) -> Result < ( ) > {
254
+ // XXX: This is a bit hacky, but this function should be called before output.generate_fstab() for
255
+ // the fstab generator to be correct, IF we're using encryption
256
+ //
257
+ // todo: Unfuck this
255
258
let mut container = output. to_container ( passphrase) ?;
256
259
257
260
let fstab = output. generate_fstab ( ) ?;
@@ -262,9 +265,9 @@ impl InstallationState {
262
265
. get_xbootldr_partition ( )
263
266
. context ( "No xbootldr partition found" ) ?;
264
267
265
- let crypttab = output. generate_crypttab ( ) ;
268
+ let crypt_data = output. generate_cryptdata ( ) ? ;
266
269
267
- container. run ( || self . _inner_sys_setup ( fstab, crypttab , esp_node, & xbootldr_node) ) ??;
270
+ container. run ( || self . _inner_sys_setup ( fstab, crypt_data , esp_node, & xbootldr_node) ) ??;
268
271
269
272
Ok ( ( ) )
270
273
}
@@ -274,7 +277,7 @@ impl InstallationState {
274
277
pub fn _inner_sys_setup (
275
278
& self ,
276
279
fstab : String ,
277
- crypttab : Option < String > ,
280
+ crypt_data : Option < CryptData > ,
278
281
esp_node : Option < String > ,
279
282
xbootldr_node : & str ,
280
283
) -> Result < ( ) > {
@@ -285,12 +288,16 @@ impl InstallationState {
285
288
esp_partition : esp_node,
286
289
xbootldr_partition : xbootldr_node. to_owned ( ) ,
287
290
lang : self . langlocale . clone ( ) . unwrap_or_else ( || "C.UTF-8" . into ( ) ) ,
291
+ crypt_data : crypt_data. clone ( ) ,
288
292
} ;
289
293
294
+ tracing:: info!( "Writing /etc/fstab..." ) ;
290
295
std:: fs:: write ( "/etc/fstab" , fstab) . wrap_err ( "cannot write to /etc/fstab" ) ?;
291
296
292
- if let Some ( crypttab) = crypttab {
293
- std:: fs:: write ( "/etc/crypttab" , crypttab) . wrap_err ( "cannot write to /etc/crypttab" ) ?;
297
+ if let Some ( data) = crypt_data {
298
+ tracing:: info!( "Writing /etc/crypttab..." ) ;
299
+ std:: fs:: write ( "/etc/crypttab" , data. crypttab )
300
+ . wrap_err ( "cannot write to /etc/crypttab" ) ?;
294
301
}
295
302
296
303
for module in & self . postinstall {
@@ -393,9 +400,9 @@ impl InstallationState {
393
400
#[ allow( clippy:: unwrap_in_result) ]
394
401
#[ tracing:: instrument]
395
402
/// Enable encryption on the root partition config
396
- ///
403
+ ///
397
404
/// This method will modify the root partition config file to enable encryption
398
- ///
405
+ ///
399
406
/// Please use [`Self::layer_configdir`] before calling this method to avoid modifying the original config files
400
407
fn enable_encryption ( & self , cfgdir : & Path ) -> Result < ( ) > {
401
408
if !self . encrypt {
@@ -405,10 +412,10 @@ impl InstallationState {
405
412
let f = std:: fs:: read_to_string ( & root_file) ?;
406
413
let f = Self :: set_encrypt_to_file ( & f, self . tpm ) ;
407
414
// We're gonna write directly to the file.
408
- //
415
+ //
409
416
// Warning: Please don't use this method unless you're using layer_configdir
410
417
std:: fs:: write ( & root_file, f) ?;
411
-
418
+
412
419
// TODO: somehow actually use this config file
413
420
Ok ( ( ) )
414
421
}
0 commit comments