-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
installer: Flesh out basic structure for Installer + Model
Signed-off-by: Ikey Doherty <[email protected]>
- Loading branch information
Showing
7 changed files
with
178 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ edition = "2021" | |
|
||
[dependencies] | ||
system = { path = "../system" } | ||
thiserror.workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters