diff --git a/src/initcpio.rs b/src/initcpio.rs new file mode 100644 index 0000000..6e7e979 --- /dev/null +++ b/src/initcpio.rs @@ -0,0 +1,28 @@ +use std::fmt::Write; + +pub struct Initcpio { + encrypted: bool, +} + +impl Initcpio { + pub fn new(encrypted: bool) -> Self { + Self { encrypted } + } + + pub fn to_config(&self) -> String { + let mut output = String::from( + "MODULES=() +BINARIES=() +FILES=() +HOOKS=(base udev keyboard consolefont block ", + ); + + if self.encrypted { + output.write_str("encrypt ").unwrap(); + } + + output.write_str("filesystems keyboard fsck)\n").unwrap(); + + output + } +} diff --git a/src/main.rs b/src/main.rs index 7ca7917..f785e1d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ mod args; mod error; +mod initcpio; mod presets; mod process; mod storage; @@ -30,11 +31,6 @@ use tempfile::tempdir; const BOOT_PARTITION_INDEX: u8 = 1; const ROOT_PARTITION_INDEX: u8 = 3; -static MKINITCPIO: &'static str = "MODULES=() -BINARIES=() -FILES=() -HOOKS=(base udev keyboard consolefont block encrypt filesystems keyboard fsck)"; - static JOURNALD_CONF: &'static str = " [Journal] Storage=volatile @@ -313,8 +309,11 @@ fn create(command: CreateCommand, running: Arc) -> Result<(), Error> .run(ErrorKind::Locale)?; info!("Generating initramfs"); - fs::write(mount_point.path().join("etc/mkinitcpio.conf"), MKINITCPIO) - .context(ErrorKind::Initramfs)?; + fs::write( + mount_point.path().join("etc/mkinitcpio.conf"), + initcpio::Initcpio::new(encrypted_root.is_some()).to_config(), + ) + .context(ErrorKind::Initramfs)?; arch_chroot .execute() .arg(mount_point.path())