diff --git a/rust/src/cliwrap/cliutil.rs b/rust/src/cliwrap/cliutil.rs index b02a027719..58dea2a429 100644 --- a/rust/src/cliwrap/cliutil.rs +++ b/rust/src/cliwrap/cliutil.rs @@ -1,6 +1,9 @@ // SPDX-License-Identifier: Apache-2.0 OR MIT use anyhow::Result; +use std::collections::HashMap; +use std::fs::File; +use std::io::{self, BufRead, BufReader, Error, ErrorKind}; use std::os::unix::process::CommandExt; use std::{thread, time}; @@ -94,3 +97,31 @@ pub fn run_unprivileged>( exec_real_binary(target_bin, &argv) } } + +pub fn read_config_file(file_path: &str, key_to_check: &str) -> Result, io::Error> { + let file = File::open(file_path)?; + let reader = BufReader::new(file); + + let mut config_map = HashMap::new(); + + for line in reader.lines() { + let line = line?; + // Ignore comments + if !line.trim().starts_with("#") { + // Split the line into key and value using '=' as a delimiter + let parts: Vec<&str> = line.splitn(2, '=').map(|s| s.trim()).collect(); + if parts.len() == 2 { + config_map.insert(parts[0].to_string(), parts[1].to_string()); + } else { + return Err(Error::new(ErrorKind::Other, "An example error occurred")); + } + } + } + + // Check the value of the specified key + if let Some(value) = config_map.get(key_to_check) { + Ok(Some(value.clone())) + } else { + Ok(None) + } +} diff --git a/rust/src/cliwrap/kernel_install.rs b/rust/src/cliwrap/kernel_install.rs index cc2a0077b0..8d8a995404 100644 --- a/rust/src/cliwrap/kernel_install.rs +++ b/rust/src/cliwrap/kernel_install.rs @@ -64,6 +64,30 @@ fn redo_systemctl_wrap() -> Result<()> { Ok(()) } +#[context("Running initoverlayfs")] +fn run_initoverlayfs() -> Result<()> { + const OSTREED_CONFIGFILE: &str = "/etc/ostreed.conf"; + const INITOVERLAY_CONFIGNAME: &str = "InitOverlayFS"; + const INITOVERLAY_INSTALL_CMD: &str = "initoverlayfs-install"; + + match crate::cliwrap::cliutil::read_config_file(OSTREED_CONFIGFILE, INITOVERLAY_CONFIGNAME) { + Ok(Some(value)) if value == "true" => { + let empty_argv: Vec<&str> = Vec::new(); + if let Err(err) = cliutil::exec_real_binary(INITOVERLAY_INSTALL_CMD, &empty_argv) { + return Err(anyhow!( + "Error: Command '{}' failed with: {}", + INITOVERLAY_INSTALL_CMD, + err + )); + } + } + _ => { + // Ignore all other cases (key not found or value not equal to "true") + } + } + Ok(()) +} + #[context("Running dracut")] fn run_dracut(kernel_dir: &str) -> Result<()> { let root_fs = Utf8Dir::open_ambient_dir("/", cap_std::ambient_authority())?; @@ -108,5 +132,10 @@ fn run_dracut(kernel_dir: &str) -> Result<()> { &root_fs, (Utf8Path::new("lib/modules").join(kernel_dir)).join("initramfs.img"), )?; + + if let Err(error) = run_initoverlayfs() { + return Err(anyhow!("Failed to execute initoverlayfs: {}", error)); + } + Ok(()) } diff --git a/src/daemon/rpm-ostreed.conf b/src/daemon/rpm-ostreed.conf index 05a8aa63c1..5944cded8e 100644 --- a/src/daemon/rpm-ostreed.conf +++ b/src/daemon/rpm-ostreed.conf @@ -6,3 +6,4 @@ #AutomaticUpdatePolicy=none #IdleExitTimeout=60 #LockLayering=false +#InitOverlayFS=false