From fb802984f5516e632fb47ffd7eed66697e25e2d8 Mon Sep 17 00:00:00 2001 From: leofvo Date: Mon, 2 May 2022 16:25:22 +0200 Subject: [PATCH] implemented kernel build feature - add_kernel: add kernel binary to quardle Signed-off-by: leofvo --- src/quardle/mod.rs | 51 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/src/quardle/mod.rs b/src/quardle/mod.rs index c7f8022..17a271d 100644 --- a/src/quardle/mod.rs +++ b/src/quardle/mod.rs @@ -46,6 +46,7 @@ impl Quardle { self .setup() + .add_kernel() .add_config_file() .make_archive()?; @@ -89,6 +90,56 @@ impl Quardle { .expect("failed to setup quark"); } + // Install a default kernel configuration file + if !std::path::Path::new(&format!("{}linux-config-x86_64", QUARK_CONFIG_DIR)).exists() { + println!("Kernel config file not found, installing it !"); + Command::new("curl") + .arg("https://raw.githubusercontent.com/virt-do/lab/main/do-vmm/kernel/linux-config-x86_64") + .arg("-O") + .current_dir(format!("{}", QUARK_CONFIG_DIR)) + .output() + .expect("failed to fetch kernel config file"); + } + + // Install a script to build kernel + if !std::path::Path::new(&format!("{}mkkernel.sh", QUARK_CONFIG_DIR)).exists() { + println!("Kernel build script not found, installing it !"); + Command::new("curl") + .arg("https://raw.githubusercontent.com/virt-do/lab/main/do-vmm/kernel/mkkernel.sh") + .arg("-O") + .current_dir(format!("{}", QUARK_CONFIG_DIR)) + .output() + .expect("failed to fetch kernel build script"); + + Command::new("chmod") + .arg("+x") + .arg(format!("{}mkkernel.sh", QUARK_CONFIG_DIR)) + .current_dir(format!("{}", QUARK_CONFIG_DIR)) + .output() + .expect("failed to make kernel build script executable"); + } + + // Building kernel binary + if !std::path::Path::new(&format!("{}linux-cloud-hypervisor", QUARK_CONFIG_DIR)).exists() { + println!("Kernel not builded, building it !"); + Command::new(format!("{}mkkernel.sh", QUARK_CONFIG_DIR)) + .current_dir(format!("{}", QUARK_CONFIG_DIR)) + .output() + .expect("failed to build kernel"); + } + + self + } + + /// Append kernel configuration + /// Fetch automated script if isn't already installed, and use some bash script to build it + fn add_kernel(&self) -> &Quardle { + println!("Installing kernel binary !"); + Command::new("cp") + .arg(format!("{}linux-cloud-hypervisor/arch/x86/boot/compressed/vmlinux.bin", QUARK_CONFIG_DIR)) + .arg(format!("{}/", self.clone().get_work_dir())) + .spawn() + .expect("failed to copy kernel"); self }