Skip to content

Commit

Permalink
installer: Flesh out basic structure for Installer + Model
Browse files Browse the repository at this point in the history
Signed-off-by: Ikey Doherty <[email protected]>
  • Loading branch information
ikeycode committed Jun 21, 2024
1 parent 19493f4 commit fdba2bc
Show file tree
Hide file tree
Showing 7 changed files with 178 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/installer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ edition = "2021"

[dependencies]
system = { path = "../system" }
thiserror.workspace = true
97 changes: 97 additions & 0 deletions crates/installer/src/account.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// SPDX-FileCopyrightText: Copyright © 2024 Serpent OS Developers
//
// SPDX-License-Identifier: MPL-2.0

/// Identifies an account
#[derive(Debug, Clone)]
pub struct Account {
/// User ID
uid: u16,

/// Group ID
gid: u16,

/// Account name
username: String,

/// Human username string
gecos: Option<String>,

/// Home directory
homedir: String,

/// Which shell to use
shell: String,

/// New password
password: Option<String>,

/// Builtin user? (root)
builtin: bool,
}

impl Default for Account {
fn default() -> Self {
Self {
uid: 1000,
gid: 1000,
username: "user".into(),
gecos: None,
homedir: "/home/user".into(),
shell: "/bin/bash".into(),
password: None,
builtin: false,
}
}
}

impl Account {
/// Return an account definition for the root account
pub fn root() -> Self {
Self {
uid: 0,
gid: 0,
username: "root".to_string(),
homedir: "/root".to_string(),
builtin: true,
..Default::default()
}
}

/// New account with the given username
pub fn new<S: AsRef<str>>(username: S) -> Self {
Self {
username: username.as_ref().to_string(),
..Default::default()
}
}

/// Update the IDs
pub fn with_id(self, uid: u16, gid: u16) -> Self {
Self { uid, gid, ..self }
}

/// Update the gecos
pub fn with_gecos<S: AsRef<str>>(self, gecos: S) -> Self {
Self {
gecos: Some(gecos.as_ref().to_string()),
..self
}
}

/// Update the shell
pub fn with_shell<S: AsRef<str>>(self, shell: S) -> Self {
Self {
shell: shell.as_ref().to_string(),
..self
}
}

/// Update the password
pub fn with_password<P: AsRef<str>>(self, p: P) -> Self {
Self {
password: Some(p.as_ref().to_string()),
..self
}
}
}
53 changes: 53 additions & 0 deletions crates/installer/src/engine.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// SPDX-FileCopyrightText: Copyright © 2024 Serpent OS Developers
//
// SPDX-License-Identifier: MPL-2.0

//! Concrete implementation of the isntaller
use system::{
disk::{self, Disk},
locale::{self, Locale},
};
use thiserror::Error;

use crate::Model;

#[derive(Debug, Error)]
pub enum Error {
#[error("disk: {0}")]
Disk(#[from] disk::Error),

#[error("locale: {0}")]
Locale(#[from] locale::Error),
}

/// The installer does some initial probing and is used with a Model
/// to build an execution routine
pub struct Installer<'a> {
/// Complete locale registry
locale_registry: locale::Registry,

/// Available / loaded locales
locales: Vec<Locale<'a>>,

/// All known/useful disks
disks: Vec<Disk>,
}

impl<'a> Installer<'a> {
/// Return a newly initialised installer
pub fn new() -> Result<Self, Error> {
let locale_registry = locale::Registry::new()?;
let disks = Disk::discover()?;
Ok(Self {
locale_registry,
locales: Vec::new(),
disks,
})
}

/// build the model into a set of install steps
pub fn compile_to_steps(&self, _model: &Model) -> Result<(), Error> {
todo!("dont know how")
}
}
10 changes: 10 additions & 0 deletions crates/installer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,13 @@
// SPDX-License-Identifier: MPL-2.0

//! Lichen installer APIs
mod model;

pub use model::Model;

mod account;
pub use account::Account;

mod engine;
pub use engine::Installer;
14 changes: 14 additions & 0 deletions crates/installer/src/model.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-FileCopyrightText: Copyright © 2024 Serpent OS Developers
//
// SPDX-License-Identifier: MPL-2.0

use std::collections::BTreeSet;

use crate::Account;

/// Core model for the installation target
#[derive(Debug, Default)]
pub struct Model {
/// All accounts in the system.
pub accounts: BTreeSet<Account>,
}
1 change: 1 addition & 0 deletions lichen_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ dialoguer = { version = "0.11.0", features = ["completion", "fuzzy-matcher", "fu
indicatif = "0.17.8"
futures.workspace = true
tokio.workspace = true
installer = { path = "../crates/installer" }
system = { path = "../crates/system" }
console = "0.15.8"

0 comments on commit fdba2bc

Please sign in to comment.