Don't set the crypt hook when unnecessary (fix #20)

This commit is contained in:
Roey Darwish Dror 2019-06-20 22:20:18 +03:00
parent 4b7547a57e
commit e339b722df
2 changed files with 34 additions and 7 deletions

28
src/initcpio.rs Normal file
View File

@ -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
}
}

View File

@ -1,5 +1,6 @@
mod args; mod args;
mod error; mod error;
mod initcpio;
mod presets; mod presets;
mod process; mod process;
mod storage; mod storage;
@ -30,11 +31,6 @@ use tempfile::tempdir;
const BOOT_PARTITION_INDEX: u8 = 1; const BOOT_PARTITION_INDEX: u8 = 1;
const ROOT_PARTITION_INDEX: u8 = 3; 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 = " static JOURNALD_CONF: &'static str = "
[Journal] [Journal]
Storage=volatile Storage=volatile
@ -313,8 +309,11 @@ fn create(command: CreateCommand, running: Arc<AtomicBool>) -> Result<(), Error>
.run(ErrorKind::Locale)?; .run(ErrorKind::Locale)?;
info!("Generating initramfs"); info!("Generating initramfs");
fs::write(mount_point.path().join("etc/mkinitcpio.conf"), MKINITCPIO) fs::write(
.context(ErrorKind::Initramfs)?; mount_point.path().join("etc/mkinitcpio.conf"),
initcpio::Initcpio::new(encrypted_root.is_some()).to_config(),
)
.context(ErrorKind::Initramfs)?;
arch_chroot arch_chroot
.execute() .execute()
.arg(mount_point.path()) .arg(mount_point.path())