diff options
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | src/main.rs | 52 |
2 files changed, 53 insertions, 0 deletions
@@ -7,4 +7,5 @@ edition = "2021" [dependencies] anyhow = "1.0.68" +num_cpus = "1.15.0" reqwest = { version = "0.11.13", features = ["blocking"] } diff --git a/src/main.rs b/src/main.rs index 231e55d..ab57954 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,7 @@ use anyhow::bail; +use std::env; use std::fs::File; +use std::io::Write; use std::path::Path; use std::process::Command; @@ -22,6 +24,50 @@ fn download_kernel(file_name: &str) -> anyhow::Result<()> { Ok(()) } +fn compile() -> anyhow::Result<()> { + let mut defconfig = Command::new("make"); + defconfig.arg("defconfig"); + + if !defconfig.spawn()?.wait()?.success() { + bail!("make defconfig failed"); + } + + let mut mod2noconfig = Command::new("make"); + mod2noconfig.arg("mod2noconfig"); + + if !mod2noconfig.spawn()?.wait()?.success() { + bail!("make mod2noconfig failed"); + } + + // Drop and close the file before continuing. + { + let mut file = File::options() + .truncate(false) + .append(true) + .open(".config")?; + + file.write_all(CONFIG.as_bytes())?; + } + + let mut olddefconfig = Command::new("make"); + olddefconfig.arg("olddefconfig"); + + if !olddefconfig.spawn()?.wait()?.success() { + bail!("make olddefconfig failed"); + } + + let mut make = Command::new("make"); + make.arg("bzImage") + .arg("modules") + .arg("-j".to_owned() + &num_cpus::get().to_string()); + + if !make.spawn()?.wait()?.success() { + bail!("make failed"); + } + + Ok(()) +} + fn main() -> anyhow::Result<()> { let file_name = Path::new(LATEST).file_name().unwrap().to_str().unwrap(); @@ -36,5 +82,11 @@ fn main() -> anyhow::Result<()> { println!("Kernel source unpacked successfully"); + env::set_current_dir(file_name.trim_end_matches(".tar.xz"))?; + + println!("Compiling kernel..."); + compile()?; + println!("Kernel compiled successfully"); + Ok(()) } |