From 917ca121e31da3cedc3a64fc3ecec3af2b52e8cf Mon Sep 17 00:00:00 2001 From: able Date: Tue, 23 May 2023 06:39:19 -0500 Subject: [PATCH] reworking system_config to better build an ableOS file tree --- .../system_config/assets/example_config.toml | 36 +++-- programs/system_config/src/main.rs | 133 ++++++++++-------- 2 files changed, 96 insertions(+), 73 deletions(-) diff --git a/programs/system_config/assets/example_config.toml b/programs/system_config/assets/example_config.toml index 01bc6d8..08d0279 100644 --- a/programs/system_config/assets/example_config.toml +++ b/programs/system_config/assets/example_config.toml @@ -20,36 +20,42 @@ resolution = "1024x768x24" core = "https://git.ablecorp.us/AbleOS/core" userspace = "https://git.ablecorp.us/AbleOS/ableos_userland" -[packages] -[packages.list_files] +[apps] +[apps.list_files] version = "0.1.1" hash = "" repo = "userspace" -[packages.list_files.configuration] - -[users] [users.able] -home = "/home/able/" password_hash = "abc123" [users.able.repositories] -able_repo = "https://git.ablecorp.us/able/ableos_packages" -[users.able.packages] -[users.able.packages.ablecraft] +able_repo = "https://git.ablecorp.us/able/ableos_apps" + + +[users.able.apps] +[users.able.apps.able_editor] +version = "1.0" + +[users.able.apps.able_editor.plugins.rustfmt] +version = "1.0" +hash = "" +repo = "default" +[users.able.apps.able_editor.plugins.repositories] +default = ["https://github.com/able_editor/plugins"] + + +[users.able.apps.ablecraft] version = "0.1.1" hash = "" repo = "able_repo" -[users.able.packages.ablecraft.configuration] -[users.able.packages.list_files.configuration] +# [users.able.apps.ablecraft.configuration] +[users.able.apps.list_files.configuration] use_color = true -[users.able.packages.list_files.permissions] +[users.able.apps.list_files.permissions] file_paths = ["/"] [users.chad] -home = "/chad/" password_hash = "abc123" -[users.chad.repositories] -[users.chad.packages] diff --git a/programs/system_config/src/main.rs b/programs/system_config/src/main.rs index b8e76a9..35b86bf 100644 --- a/programs/system_config/src/main.rs +++ b/programs/system_config/src/main.rs @@ -1,20 +1,25 @@ -use std::{ - env, - error::Error, - fmt::format, - fs::{self, File}, - io::{Read, Write}, - path, +use { + std::{ + env, + error::Error, + fs::{self, File}, + io::{Read, Write}, + }, + toml::{self, Table, Value}, }; -use toml::Table; -use toml::{self, Value}; + fn main() -> Result<(), Box> { let mut args: Vec = env::args().collect(); + // #[cfg(target_os="linux")] + + if args.len() == 1 { + println!("Pass a file"); + } args.remove(0); let file_path = &args[0]; - println!("{}", file_path); + println!("configuration path - {}", file_path); - let mut file = File::open(file_path).expect("Unable to open the file"); + let mut file = File::open(file_path).unwrap(); //.expect("Unable to open the file"); let mut contents = String::new(); file.read_to_string(&mut contents) @@ -28,7 +33,8 @@ fn main() -> Result<(), Box> { // HANDLE repolist { let repolist = value.get("repositories").unwrap(); - let ret = make_repolist("repolist.toml".to_string(), repolist); + fs::create_dir("disk/System")?; + let ret = make_repolist("System/repolist.toml".to_string(), repolist); println!("making repolist {:?}", ret); } @@ -55,7 +61,8 @@ fn main() -> Result<(), Box> { for user in users_table.keys() { let ut = users_table.get(user).unwrap(); - let home_path = ut.get("home").unwrap(); + // let home_path = ut.get("home").unwrap(); + let home_path = format!("/Users/{}", user); let pass_hash = ut.get("password_hash").unwrap(); passhash_list.push((user.to_string(), pass_hash.to_string())); @@ -63,54 +70,63 @@ fn main() -> Result<(), Box> { let ret = make_user(home_path.to_string()); println!("making user return {:?}", ret); // Handle homepath generation of USER + { - let mut hp = home_path.clone().to_string(); - hp.remove(0); - hp.remove(0); - hp.remove(hp.len() - 1); - hp.remove(hp.len() - 1); - for package in ut.get("packages").unwrap().as_table().unwrap().keys() { - let pack_folder: String = format!("disk/{}/{}", hp, package); - let pack_config: String = format!("disk/{}/{}/config.toml", hp, package); + let hp = home_path.clone().to_string(); + let apps = ut.get("apps"); + fs::create_dir_all(format!("disk/{}/Apps/", hp))?; - fs::create_dir(pack_folder)?; - let mut file = File::create(pack_config)?; - // repo_list_str.as_bytes() - let abc = ut - .get("packages") - .unwrap() - .get(package) - .unwrap() - .get("configuration") - .unwrap(); - let mut abc = abc.to_string(); - if abc.len() > 2 { - abc.remove(0); - abc.remove(0); - abc.remove(abc.len() - 1); - abc.remove(abc.len() - 1); - } - if abc.len() == 2 { - abc.remove(0); - abc.remove(0); - } + println!("ok"); + if apps.is_some() { + let apps = apps.unwrap(); + for app in apps.as_table().unwrap().keys() { + let pack_folder: String = format!("disk/{}/Apps/{}", hp, app); + let pack_config: String = format!("disk/{}/Apps/{}/config.toml", hp, app); - file.write_all(abc.as_bytes())?; + fs::create_dir_all(pack_folder)?; + let mut file = File::create(pack_config)?; + // repo_list_str.as_bytes() + let abc = apps.get(app).unwrap().get("configuration"); + let tab = match abc { + Some(val) => val.clone(), + None => { + let tab = Table::new(); + Value::Table(tab) + } + }; + // .unwrap_or(&Value::Table(Table::new())); + let mut abc = tab.to_string(); + if abc.len() > 2 { + abc.remove(0); + abc.remove(0); + abc.remove(abc.len() - 1); + abc.remove(abc.len() - 1); + } + if abc.len() == 2 { + abc.remove(0); + abc.remove(0); + } + + file.write_all(abc.as_bytes())?; + } } } - { - let repolist = ut.get("repositories").unwrap(); - let mut hp = home_path.clone().to_string(); - hp.remove(0); - hp.remove(0); - hp.remove(hp.len() - 1); - hp.remove(hp.len() - 1); + let repolist = ut.get("repositories"); + let hp = home_path.clone().to_string(); + let user_path_repolist = format!("{}/repolist.toml", hp.to_string()); + println!("{}", user_path_repolist); + match repolist { + Some(repolist) => { + let ret = make_repolist(user_path_repolist, repolist); + println!("making repolist {:?}", ret); + } + None => { + let repolist = Table::new(); - let user_path_repolist = format!("{}/repolist.toml", hp.to_string()); - println!("{}", user_path_repolist); - let ret = make_repolist(user_path_repolist, repolist); - println!("making repolist {:?}", ret); + let ret = make_repolist(user_path_repolist, &Value::Table(repolist)); + println!("making repolist {:?}", ret); + } } } @@ -118,6 +134,9 @@ fn main() -> Result<(), Box> { println!("making password hashlist {:?}", ret); } + // TODO: Handle system wide things like repolist and Apps/ + {} + // let mut file = File::create("disk/foo.txt")?; // file.write_all(b"Hello, world!")?; @@ -192,10 +211,7 @@ TERM_BACKDROP={} Ok(()) } -pub fn make_user(mut home_path: String) -> std::io::Result<()> { - home_path.remove(0); - home_path.remove(home_path.len() - 1); - +pub fn make_user(home_path: String) -> std::io::Result<()> { let path = format!("disk/{}", home_path); fs::create_dir_all(path)?; Ok(()) @@ -203,6 +219,7 @@ pub fn make_user(mut home_path: String) -> std::io::Result<()> { pub fn make_repolist(path: String, repolist: &Value) -> std::io::Result<()> { let path = format!("disk/{}", path); + let mut file = File::create(path)?; let mut repo_list_str = String::new(); for (repo_name, repo_url) in repolist.as_table().unwrap() {