-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Dump readymade install state to a file in target root
- Loading branch information
1 parent
b7956de
commit 6da4f17
Showing
6 changed files
with
159 additions
and
13 deletions.
There are no files selected for viewing
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
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,86 @@ | ||
//! Module for exporting Readymade's install state to a file, Useful for other tools to check | ||
//! the initial state of the system. Not so useful when the user modifies the system after and | ||
//! the state drifts from the initial state. (i.e the user repartitions the disk, adds a new disk, | ||
//! spans the BTRFS volume, etc.) | ||
//! | ||
use std::{collections::BTreeMap, path::Path}; | ||
|
||
use color_eyre::Result; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use super::{install::InstallationState, repartcfg::RepartConfig}; | ||
/// The version of the result dump format, for backwards compat reasons | ||
/// | ||
/// If there's any changes to the format, this should be bumped up to the next version. | ||
/// | ||
const RESULT_DUMP_FORMAT_VERSION: &str = "0.1.0"; | ||
#[derive(Serialize, Deserialize, Debug)] | ||
pub struct ReadymadeResult { | ||
pub version: &'static str, | ||
pub readymade_version: &'static str, | ||
pub is_debug_build: bool, | ||
pub state: InstallationState, | ||
pub systemd_repart_data: Option<SystemdRepartData>, | ||
} | ||
|
||
impl ReadymadeResult { | ||
pub fn export_string(&self) -> Result<String> { | ||
Ok(serde_json::to_string_pretty(&self)?) | ||
} | ||
|
||
pub fn new(state: InstallationState, systemd_repart_data: Option<SystemdRepartData>) -> Self { | ||
Self { | ||
version: RESULT_DUMP_FORMAT_VERSION, | ||
readymade_version: env!("CARGO_PKG_VERSION"), | ||
is_debug_build: cfg!(debug_assertions), | ||
state: prep_state_for_export(state).unwrap(), | ||
systemd_repart_data, | ||
} | ||
} | ||
|
||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
pub struct SystemdRepartData { | ||
configs: BTreeMap<String, RepartConfig>, | ||
} | ||
|
||
impl SystemdRepartData { | ||
pub fn new(configs: BTreeMap<String, RepartConfig>) -> Self { | ||
Self { configs } | ||
} | ||
|
||
pub fn get_configs(cfg_path: &Path) -> Result<Self> { | ||
let mut configs = BTreeMap::new(); | ||
// Read path | ||
for entry in std::fs::read_dir(&cfg_path)? { | ||
let entry = entry?; | ||
let path = entry.path(); | ||
if !path.is_file() { | ||
continue; | ||
} | ||
let file_config = std::fs::read_to_string(&path)?; | ||
|
||
// Parse the config | ||
let config: RepartConfig = serde_systemd_unit::from_str(&file_config)?; | ||
|
||
// Add to the list | ||
configs.insert( | ||
path.file_name().unwrap().to_string_lossy().to_string(), | ||
config, | ||
); | ||
} | ||
Ok(Self::new(configs)) | ||
} | ||
} | ||
|
||
pub fn prep_state_for_export(state: InstallationState) -> Result<InstallationState> { | ||
let mut new_state = state.clone(); | ||
|
||
// Clear out passwords | ||
if let Some(ref mut enc_key) = new_state.encryption_key { | ||
enc_key.clear(); | ||
new_state.encryption_key = Some("REDACTED".to_string()); | ||
} | ||
Ok(new_state) | ||
} |
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 |
---|---|---|
|
@@ -4,3 +4,4 @@ pub mod mksys; | |
pub mod postinstall; | ||
pub mod repart_output; | ||
pub mod repartcfg; | ||
pub mod export; |
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