forked from msrd0/mkalpiimg
46 lines
1 KiB
Rust
46 lines
1 KiB
Rust
|
//! This module contains definitions to read the setup files.
|
||
|
use anyhow::Context as _;
|
||
|
use serde::de::DeserializeOwned;
|
||
|
use std::{
|
||
|
fs,
|
||
|
path::{Path, PathBuf}
|
||
|
};
|
||
|
|
||
|
pub mod autostart;
|
||
|
pub mod network;
|
||
|
pub mod os;
|
||
|
pub mod packages;
|
||
|
|
||
|
use autostart::Autostart;
|
||
|
use network::Network;
|
||
|
use os::Os;
|
||
|
use packages::Packages;
|
||
|
|
||
|
pub struct Setup {
|
||
|
pub os: Os,
|
||
|
pub network: Network,
|
||
|
pub packages: Packages,
|
||
|
pub autostart: Autostart
|
||
|
}
|
||
|
|
||
|
impl Setup {
|
||
|
fn read<T: DeserializeOwned>(path: &Path, file: &str) -> anyhow::Result<T> {
|
||
|
toml::from_slice(&fs::read(path.join(file)).with_context(|| format!("Failed to read {file}"))?)
|
||
|
.with_context(|| format!("Failed to deserialize {file}"))
|
||
|
}
|
||
|
|
||
|
pub fn load() -> anyhow::Result<Self> {
|
||
|
let path = PathBuf::from("setup");
|
||
|
let os = Self::read(&path, "os.toml")?;
|
||
|
let network = Self::read(&path, "network.toml")?;
|
||
|
let packages = Self::read(&path, "packages.toml")?;
|
||
|
let autostart = Self::read(&path, "autostart.toml")?;
|
||
|
Ok(Self {
|
||
|
os,
|
||
|
network,
|
||
|
packages,
|
||
|
autostart
|
||
|
})
|
||
|
}
|
||
|
}
|