forked from AbleOS/ableos_userland
reworking system_config to better build an ableOS file tree
This commit is contained in:
parent
48ca72e613
commit
917ca121e3
|
@ -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]
|
|
||||||
|
|
|
@ -1,20 +1,25 @@
|
||||||
use std::{
|
use {
|
||||||
env,
|
std::{
|
||||||
error::Error,
|
env,
|
||||||
fmt::format,
|
error::Error,
|
||||||
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,54 +70,63 @@ 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();
|
let hp = home_path.clone().to_string();
|
||||||
hp.remove(0);
|
let apps = ut.get("apps");
|
||||||
hp.remove(0);
|
fs::create_dir_all(format!("disk/{}/Apps/", hp))?;
|
||||||
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)?;
|
println!("ok");
|
||||||
let mut file = File::create(pack_config)?;
|
if apps.is_some() {
|
||||||
// repo_list_str.as_bytes()
|
let apps = apps.unwrap();
|
||||||
let abc = ut
|
for app in apps.as_table().unwrap().keys() {
|
||||||
.get("packages")
|
let pack_folder: String = format!("disk/{}/Apps/{}", hp, app);
|
||||||
.unwrap()
|
let pack_config: String = format!("disk/{}/Apps/{}/config.toml", hp, app);
|
||||||
.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);
|
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
let repolist = ut.get("repositories");
|
||||||
hp.remove(0);
|
let hp = home_path.clone().to_string();
|
||||||
hp.remove(0);
|
let user_path_repolist = format!("{}/repolist.toml", hp.to_string());
|
||||||
hp.remove(hp.len() - 1);
|
println!("{}", user_path_repolist);
|
||||||
hp.remove(hp.len() - 1);
|
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());
|
let ret = make_repolist(user_path_repolist, &Value::Table(repolist));
|
||||||
println!("{}", user_path_repolist);
|
println!("making repolist {:?}", ret);
|
||||||
let ret = make_repolist(user_path_repolist, repolist);
|
}
|
||||||
println!("making repolist {:?}", ret);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,6 +134,9 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||||
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() {
|
||||||
|
|
Loading…
Reference in a new issue