Skip to content

Commit

Permalink
implemented kaps in quardle feature
Browse files Browse the repository at this point in the history
- setup: install kaps sources
- add_kaps: build kaps from sources and add it to quardle

Signed-off-by: leofvo <[email protected]>
  • Loading branch information
leofvo committed Apr 27, 2022
1 parent f3d6f39 commit c77302b
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/quardle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ impl Quardle {
.setup()
.add_kernel()
.add_initramfs()
.add_kaps()
.add_config_file()
.make_archive()?;

Expand Down Expand Up @@ -93,6 +94,16 @@ impl Quardle {
.expect("failed to setup quark");
}

// Install kaps sources
if !std::path::Path::new(&format!("{}kaps", QUARK_CONFIG_DIR)).exists() {
println!("Kaps not found, installing it !");
Command::new("git")
.args(["clone", "https://github.com/virt-do/kaps.git"]) // Using https protocol because it seems not supporting ssh
.current_dir(format!("{}", QUARK_CONFIG_DIR))
.output()
.expect("failed to fetch kaps");
}

// 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 !");
Expand Down Expand Up @@ -204,6 +215,27 @@ impl Quardle {
self
}

/// Append kaps binary to builded image
/// Fetch kaps source code if isn't already installed, build it from source and copy it to the working directory
fn add_kaps(&self) -> &Quardle {
Command::new("cargo")
.current_dir(format!("{}kaps", QUARK_CONFIG_DIR))
.arg("build")
.arg("--release")
// .arg("--out-dir") //TODO: outdir is only available on nightly for now, should be used later
// .arg(format!("{}/rootfs/usr/bin/kaps",self.clone().get_work_dir()))
.output()
.expect("failed to build kaps");

Command::new("cp")
.arg(format!("{}kaps/target/release/kaps", QUARK_CONFIG_DIR))
.arg(format!("{}/rootfs/usr/bin/kaps",self.clone().get_work_dir()))
.output()
.expect("failed to copy kaps");

self
}

/// Generate the config file of the quardle
/// The config file is a JSON file containing a QuardleConfig struct
fn add_config_file(&self) -> &Quardle {
Expand Down

0 comments on commit c77302b

Please sign in to comment.