Fix prompt macro, add ability to insert files in config
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
#[derive(Debug, Default, Deserialize)]
|
||||
pub struct FileConfig {
|
||||
pub path: String,
|
||||
pub data: String
|
||||
}
|
||||
@@ -1,12 +1,14 @@
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
mod general;
|
||||
mod file;
|
||||
mod package;
|
||||
mod user;
|
||||
|
||||
#[derive(Debug, Default, Deserialize)]
|
||||
pub struct Config {
|
||||
pub general: general::GeneralConfig,
|
||||
pub files: Vec<file::FileConfig>,
|
||||
pub packages: BTreeMap<String, package::PackageConfig>,
|
||||
pub users: BTreeMap<String, user::UserConfig>,
|
||||
}
|
||||
|
||||
+6
-3
@@ -74,7 +74,7 @@ pub fn install(config: Config) -> Result<(), String> {
|
||||
Err(err) => Err(err)
|
||||
}
|
||||
} else {
|
||||
Ok($def)
|
||||
Ok($dst.unwrap_or($def))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -105,11 +105,15 @@ pub fn install(config: Config) -> Result<(), String> {
|
||||
}
|
||||
|
||||
dir!("");
|
||||
dir!("bin");
|
||||
dir!("etc");
|
||||
dir!("home");
|
||||
|
||||
let mut passwd = String::new();
|
||||
for file in config.files {
|
||||
file!(file.path.trim_matches('/'), file.data.as_bytes());
|
||||
}
|
||||
|
||||
let mut passwd = String::new();
|
||||
let mut next_uid = 1000;
|
||||
for (username, user) in config.users {
|
||||
let password = if let Some(password) = user.password {
|
||||
@@ -144,7 +148,6 @@ pub fn install(config: Config) -> Result<(), String> {
|
||||
|
||||
passwd.push_str(&format!("{};{};{};{};{};{};{}\n", username, password, uid, gid, name, home, shell));
|
||||
}
|
||||
|
||||
file!("etc/passwd", passwd.as_bytes());
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user