reworking system_config to better build an ableOS file tree

This commit is contained in:
able 2023-05-23 06:39:19 -05:00
parent 48ca72e613
commit 917ca121e3
2 changed files with 96 additions and 73 deletions

View file

@ -20,36 +20,42 @@ resolution = "1024x768x24"
core = "https://git.ablecorp.us/AbleOS/core" core = "https://git.ablecorp.us/AbleOS/core"
userspace = "https://git.ablecorp.us/AbleOS/ableos_userland" userspace = "https://git.ablecorp.us/AbleOS/ableos_userland"
[packages] [apps]
[packages.list_files] [apps.list_files]
version = "0.1.1" version = "0.1.1"
hash = "" hash = ""
repo = "userspace" repo = "userspace"
[packages.list_files.configuration]
[users]
[users.able] [users.able]
home = "/home/able/"
password_hash = "abc123" password_hash = "abc123"
[users.able.repositories] [users.able.repositories]
able_repo = "https://git.ablecorp.us/able/ableos_packages" able_repo = "https://git.ablecorp.us/able/ableos_apps"
[users.able.packages]
[users.able.packages.ablecraft]
[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" version = "0.1.1"
hash = "" hash = ""
repo = "able_repo" repo = "able_repo"
[users.able.packages.ablecraft.configuration] # [users.able.apps.ablecraft.configuration]
[users.able.packages.list_files.configuration] [users.able.apps.list_files.configuration]
use_color = true use_color = true
[users.able.packages.list_files.permissions] [users.able.apps.list_files.permissions]
file_paths = ["/"] file_paths = ["/"]
[users.chad] [users.chad]
home = "/chad/"
password_hash = "abc123" password_hash = "abc123"
[users.chad.repositories]
[users.chad.packages]

View file

@ -1,20 +1,25 @@
use std::{ use {
std::{
env, env,
error::Error, error::Error,
fmt::format,
fs::{self, File}, fs::{self, File},
io::{Read, Write}, io::{Read, Write},
path, },
toml::{self, Table, Value},
}; };
use toml::Table;
use toml::{self, Value};
fn main() -> Result<(), Box<dyn Error>> { fn main() -> Result<(), Box<dyn Error>> {
let mut args: Vec<String> = env::args().collect(); let mut args: Vec<String> = env::args().collect();
// #[cfg(target_os="linux")]
if args.len() == 1 {
println!("Pass a file");
}
args.remove(0); args.remove(0);
let file_path = &args[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(); let mut contents = String::new();
file.read_to_string(&mut contents) file.read_to_string(&mut contents)
@ -28,7 +33,8 @@ fn main() -> Result<(), Box<dyn Error>> {
// HANDLE repolist // HANDLE repolist
{ {
let repolist = value.get("repositories").unwrap(); 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); println!("making repolist {:?}", ret);
} }
@ -55,7 +61,8 @@ fn main() -> Result<(), Box<dyn Error>> {
for user in users_table.keys() { for user in users_table.keys() {
let ut = users_table.get(user).unwrap(); 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(); let pass_hash = ut.get("password_hash").unwrap();
passhash_list.push((user.to_string(), pass_hash.to_string())); passhash_list.push((user.to_string(), pass_hash.to_string()));
@ -63,27 +70,32 @@ fn main() -> Result<(), Box<dyn Error>> {
let ret = make_user(home_path.to_string()); let ret = make_user(home_path.to_string());
println!("making user return {:?}", ret); println!("making user return {:?}", ret);
// Handle homepath generation of USER // 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);
fs::create_dir(pack_folder)?; {
let hp = home_path.clone().to_string();
let apps = ut.get("apps");
fs::create_dir_all(format!("disk/{}/Apps/", hp))?;
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);
fs::create_dir_all(pack_folder)?;
let mut file = File::create(pack_config)?; let mut file = File::create(pack_config)?;
// repo_list_str.as_bytes() // repo_list_str.as_bytes()
let abc = ut let abc = apps.get(app).unwrap().get("configuration");
.get("packages") let tab = match abc {
.unwrap() Some(val) => val.clone(),
.get(package) None => {
.unwrap() let tab = Table::new();
.get("configuration") Value::Table(tab)
.unwrap(); }
let mut abc = abc.to_string(); };
// .unwrap_or(&Value::Table(Table::new()));
let mut abc = tab.to_string();
if abc.len() > 2 { if abc.len() > 2 {
abc.remove(0); abc.remove(0);
abc.remove(0); abc.remove(0);
@ -98,26 +110,33 @@ fn main() -> Result<(), Box<dyn Error>> {
file.write_all(abc.as_bytes())?; 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()); let user_path_repolist = format!("{}/repolist.toml", hp.to_string());
println!("{}", user_path_repolist); println!("{}", user_path_repolist);
match repolist {
Some(repolist) => {
let ret = make_repolist(user_path_repolist, repolist); let ret = make_repolist(user_path_repolist, repolist);
println!("making repolist {:?}", ret); println!("making repolist {:?}", ret);
} }
None => {
let repolist = Table::new();
let ret = make_repolist(user_path_repolist, &Value::Table(repolist));
println!("making repolist {:?}", ret);
}
}
} }
let ret = generate_password_hashlist(passhash_list); let ret = generate_password_hashlist(passhash_list);
println!("making password hashlist {:?}", ret); println!("making password hashlist {:?}", ret);
} }
// TODO: Handle system wide things like repolist and Apps/
{}
// let mut file = File::create("disk/foo.txt")?; // let mut file = File::create("disk/foo.txt")?;
// file.write_all(b"Hello, world!")?; // file.write_all(b"Hello, world!")?;
@ -192,10 +211,7 @@ TERM_BACKDROP={}
Ok(()) Ok(())
} }
pub fn make_user(mut home_path: String) -> std::io::Result<()> { pub fn make_user(home_path: String) -> std::io::Result<()> {
home_path.remove(0);
home_path.remove(home_path.len() - 1);
let path = format!("disk/{}", home_path); let path = format!("disk/{}", home_path);
fs::create_dir_all(path)?; fs::create_dir_all(path)?;
Ok(()) 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<()> { pub fn make_repolist(path: String, repolist: &Value) -> std::io::Result<()> {
let path = format!("disk/{}", path); let path = format!("disk/{}", path);
let mut file = File::create(path)?; let mut file = File::create(path)?;
let mut repo_list_str = String::new(); let mut repo_list_str = String::new();
for (repo_name, repo_url) in repolist.as_table().unwrap() { for (repo_name, repo_url) in repolist.as_table().unwrap() {