Skip to content

Commit

Permalink
feat: backend for repart and install
Browse files Browse the repository at this point in the history
  • Loading branch information
madonuko committed Jun 26, 2024
1 parent 99e567e commit ac0e8a8
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 17 deletions.
14 changes: 1 addition & 13 deletions src/disks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub fn detect_os() -> Vec<DiskInit> {

disks
.iter()
.filter(|disk| disk.is_disk())
.filter(|disk| disk.is_disk() && disk.is_physical())
.map(|disk| {
let ret = DiskInit {
// id:
Expand Down Expand Up @@ -90,18 +90,6 @@ pub fn partition(dev: &std::path::Path, n: u8) -> PathBuf {
}
}

pub fn last_part(diskpath: &std::path::Path) -> color_eyre::Result<String> {
let sdiskpath = diskpath.display().to_string();
let lsblk = cmd_lib::run_fun!(lsblk -o path)?;
// assume all dev paths start with /

(lsblk.split('\n').skip(1))
.filter(|l| l.starts_with(&sdiskpath))
.last() // last one is the one with max partn
.map(|s| s.to_string())
.ok_or_eyre(color_eyre::Report::msg("lsblk has no output"))
}

#[cfg(test)]
#[cfg(target_os = "linux")]
#[test]
Expand Down
40 changes: 37 additions & 3 deletions src/install.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Albius Recipe generation code for Readymade
//! This module contains the code to generate a `albius::Recipe` object that can be fed into the `albius` binary.
//! So we can actually install something with Readymade.
use color_eyre::Result;
use std::path::{Path, PathBuf};

const REPART_DIR: &str = "/usr/share/readymade/repart-cfgs/";

#[derive(Debug, Clone)]
pub enum InstallationType {
Expand All @@ -9,3 +10,36 @@ pub enum InstallationType {
ChromebookInstall,
Custom,
}

impl InstallationType {
pub fn install(&self, state: &crate::InstallationState) -> Result<()> {
let blockdev = &state.destination_disk.as_ref().unwrap().devpath;
let cfgdir = self.cfgdir();
Self::systemd_repart(blockdev, &cfgdir)?;
if let Self::ChromebookInstall = self {
Self::set_cgpt_flags(blockdev)?;
}
Ok(())
}
fn cfgdir(&self) -> PathBuf {
match self {
Self::ChromebookInstall => const_format::concatcp!(REPART_DIR, "chromebookinstall"),
_ => todo!(),
}
.into()
}
fn systemd_repart(blockdev: &Path, cfgdir: &Path) -> Result<()> {
let dry_run = if cfg!(debug_assertions) { "yes" } else { "no" };
cmd_lib::run_cmd!(
systemd-repart
--dry-run=$dry_run
--definitions=$cfgdir
$blockdev
)?;
Ok(())
}
fn set_cgpt_flags(blockdev: &Path) -> Result<()> {
cmd_lib::run_cmd!(cgpt add -i 1 -t kernel -P 15 -T 1 -S 1 $blockdev)?;
Ok(())
}
}
2 changes: 1 addition & 1 deletion src/pages/installation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl SimpleComponent for InstallationPage {
.register(async move {
let state = INSTALLATION_STATE.read();
tracing::debug!("Starting installation...");
// let recipe = crate::install::generate_recipe(&state)?;
state.installation_type.as_ref().unwrap().install(&state)?;

color_eyre::Result::<_>::Ok(())
})
Expand Down

0 comments on commit ac0e8a8

Please sign in to comment.