From aeb9f89ec1d88fd618825de2374142ee0e228a4f Mon Sep 17 00:00:00 2001 From: Jeremy Soller <jackpot51@gmail.com> Date: Mon, 9 Jan 2017 16:05:27 -0700 Subject: [PATCH] Fix prompt macro, add ability to insert files in config --- src/config/file.rs | 5 +++++ src/config/mod.rs | 2 ++ src/install/mod.rs | 9 ++++++--- 3 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 src/config/file.rs diff --git a/src/config/file.rs b/src/config/file.rs new file mode 100644 index 0000000..0b34aeb --- /dev/null +++ b/src/config/file.rs @@ -0,0 +1,5 @@ +#[derive(Debug, Default, Deserialize)] +pub struct FileConfig { + pub path: String, + pub data: String +} diff --git a/src/config/mod.rs b/src/config/mod.rs index d9cee06..8418384 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -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>, } diff --git a/src/install/mod.rs b/src/install/mod.rs index 5dd65ea..d0af357 100644 --- a/src/install/mod.rs +++ b/src/install/mod.rs @@ -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(()) -- GitLab