Commit a56ec333 authored by Jeremy Soller's avatar Jeremy Soller

Add sysroot config

parent dd0a541b
Cargo.lock Cargo.lock
sysroot
target target
...@@ -7,7 +7,16 @@ prompt = false ...@@ -7,7 +7,16 @@ prompt = false
# Package settings # Package settings
[packages] [packages]
acid = {}
coreutils = {}
extrautils = {}
games = {}
ion = {}
netutils = {}
pkgutils = {}
orbutils = {} orbutils = {}
smith = {}
userutils = {}
# User settings # User settings
[users.root] [users.root]
......
#[derive(Debug, Default, Deserialize)] #[derive(Debug, Default, Deserialize)]
pub struct GeneralConfig { pub struct GeneralConfig {
pub prompt: bool pub prompt: bool,
pub sysroot: Option<String>
} }
#[derive(Debug, Default, Deserialize)] #[derive(Debug, Default, Deserialize)]
pub struct PackageConfig { pub struct PackageConfig {
pub version: String, pub version: Option<String>,
pub git: String, pub git: Option<String>,
pub path: String, pub path: Option<String>,
} }
...@@ -6,7 +6,9 @@ extern crate userutils; ...@@ -6,7 +6,9 @@ extern crate userutils;
use self::rand::Rng; use self::rand::Rng;
use self::termion::input::TermRead; use self::termion::input::TermRead;
use std::{env, fs};
use std::io::{self, Write}; use std::io::{self, Write};
use std::path::Path;
use std::str::FromStr; use std::str::FromStr;
use config::Config; use config::Config;
...@@ -57,6 +59,19 @@ fn prompt_password(prompt: &str, confirm_prompt: &str) -> Result<String, String> ...@@ -57,6 +59,19 @@ fn prompt_password(prompt: &str, confirm_prompt: &str) -> Result<String, String>
} }
} }
pub fn dir(path: &Path) -> Result<(), String> {
println!("Create directory {}", path.display());
fs::create_dir(path).map_err(|err| format!("failed to create {}: {}", path.display(), err))?;
Ok(())
}
pub fn file(path: &Path, data: &[u8]) -> Result<(), String> {
println!("Create file {}", path.display());
let mut file = fs::File::create(path).map_err(|err| format!("failed to create {}: {}", path.display(), err))?;
file.write_all(data).map_err(|err| format!("failed to write {}: {}", path.display(), err))?;
Ok(())
}
pub fn install(config: Config) -> Result<(), String> { pub fn install(config: Config) -> Result<(), String> {
println!("Install {:#?}", config); println!("Install {:#?}", config);
...@@ -77,6 +92,15 @@ pub fn install(config: Config) -> Result<(), String> { ...@@ -77,6 +92,15 @@ pub fn install(config: Config) -> Result<(), String> {
}) })
} }
let sysroot = {
let mut wd = env::current_dir().map_err(|err| format!("failed to get current dir: {}", err))?;
let path = prompt!(config.general.sysroot, "sysroot".to_string(), "sysroot [sysroot]: ")?;
wd.push(path);
wd
};
println!("Using sysroot: {}", sysroot.display());
let mut passwd = String::new(); let mut passwd = String::new();
let mut next_uid = 1000; let mut next_uid = 1000;
...@@ -101,7 +125,7 @@ pub fn install(config: Config) -> Result<(), String> { ...@@ -101,7 +125,7 @@ pub fn install(config: Config) -> Result<(), String> {
let home = prompt!(user.home, format!("/home/{}", username), "{}: home [/home/{}]: ", username, username)?; let home = prompt!(user.home, format!("/home/{}", username), "{}: home [/home/{}]: ", username, username)?;
let shell = prompt!(user.shell, "/bin/ion".to_string(), "{}: shell [/bin/ion]: ", username)?; let shell = prompt!(user.shell, "/bin/ion".to_string(), "{}: shell [/bin/ion]: ", username)?;
println!("Creating user {}:", username); println!("Adding user {}:", username);
println!("\tPassword: {}", password); println!("\tPassword: {}", password);
println!("\tUID: {}", uid); println!("\tUID: {}", uid);
println!("\tGID: {}", gid); println!("\tGID: {}", gid);
...@@ -112,7 +136,15 @@ pub fn install(config: Config) -> Result<(), String> { ...@@ -112,7 +136,15 @@ pub fn install(config: Config) -> Result<(), String> {
passwd.push_str(&format!("{};{};{};{};{};{};{}\n", username, password, uid, gid, name, home, shell)); passwd.push_str(&format!("{};{};{};{};{};{};{}\n", username, password, uid, gid, name, home, shell));
} }
print!("/etc/passwd:\n{}", passwd); dir(&sysroot)?;
let mut etc = sysroot.clone();
etc.push("etc");
dir(&etc)?;
let mut etc_passwd = etc.clone();
etc_passwd.push("passwd");
file(&etc_passwd, passwd.as_bytes())?;
Ok(()) Ok(())
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment