set everything according to config ( #7 )

axtloss/rework-partitioning
amy 3 years ago
parent 3346476322
commit c32994741c

@ -1,3 +1,5 @@
use crate::functions::*;
use crate::internal::*;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize)]
@ -46,38 +48,111 @@ struct Users {
hasroot: bool, hasroot: bool,
} }
pub fn read_config() { pub fn read_config(configpath: &str) {
let data = let data = std::fs::read_to_string(configpath);
std::fs::read_to_string("example_config.json").expect("Unable to read example_config.json"); match &data {
let config: Config = serde_json::from_str(&data).expect("Unable to parse example_config.json"); Ok(_) => {
println!("---------Partition---------"); log(format!(
"[ \x1b[2;1;32mOK\x1b[0m ] {}",
format!("Read config file {}", configpath).as_str()
));
}
Err(e) => {
crash(
format!(
"{} ERROR: {}",
format!("Read config file {}", configpath).as_str(),
e
),
e.raw_os_error().unwrap(),
);
}
}
let config: std::result::Result<Config, serde_json::Error> =
serde_json::from_str(&data.unwrap());
match &config {
Ok(_) => {
log(format!(
"[ \x1b[2;1;32mOK\x1b[0m ] {}",
format!("Parse config file {}", configpath).as_str()
));
}
Err(e) => {
crash(
format!(
"{} ERROR: {}",
format!("Parse config file {}", configpath).as_str(),
e
),
1,
);
}
}
let config: Config = config.unwrap();
println!("---------Setup Partitions---------");
println!("{}", config.partition.device); println!("{}", config.partition.device);
println!("{}", config.partition.mode); println!("{}", config.partition.mode);
println!("{}", config.partition.efi); println!("{}", config.partition.efi);
println!("---------Bootloader---------"); partition::partition(
config.partition.device.as_str(),
config.partition.mode.as_str(),
config.partition.efi,
);
base::install_base_packages();
base::genfstab();
println!("---------Install Bootloader---------");
println!("{}", config.bootloader.r#type); println!("{}", config.bootloader.r#type);
println!("{}", config.bootloader.location); println!("{}", config.bootloader.location);
println!("---------Locale---------"); if config.bootloader.r#type == "grub-efi" {
base::install_bootloader_efi(config.bootloader.location.as_str());
} else if config.bootloader.r#type == "grub-legacy" {
base::install_bootloader_legacy(config.bootloader.location.as_str());
}
println!("---------Set Locale---------");
println!("{:?}", config.locale.locale); println!("{:?}", config.locale.locale);
println!("{}", config.locale.keymap); println!("{}", config.locale.keymap);
println!("{}", config.locale.timezone); println!("{}", config.locale.timezone);
println!("---------Networking---------"); locale::set_locale(config.locale.locale.join(" "));
locale::set_keyboard(config.locale.keymap.as_str());
locale::set_timezone(config.locale.timezone.as_str());
println!("---------Set Networking---------");
println!("{}", config.networking.hostname); println!("{}", config.networking.hostname);
println!("{}", config.networking.ipv6); println!("{}", config.networking.ipv6);
println!("---------Users---------"); network::set_hostname(config.networking.hostname.as_str());
network::create_hosts();
if config.networking.ipv6 {
network::enable_ipv6();
}
println!("---------Create Users---------");
println!("---------"); println!("---------");
for i in 0..config.users.len() { for i in 0..config.users.len() {
println!("{}", config.users[i].name); println!("{}", config.users[i].name);
println!("{}", config.users[i].password); println!("{}", config.users[i].password);
println!("{}", config.users[i].hasroot); println!("{}", config.users[i].hasroot);
users::new_user(
config.users[i].name.as_str(),
config.users[i].hasroot,
config.users[i].password.as_str(),
);
println!("---------"); println!("---------");
} }
println!("---------Rootpass---------"); println!("---------Set Rootpass---------");
println!("{}", config.rootpass); println!("{}", config.rootpass);
println!("---------Desktop---------"); users::root_pass(config.rootpass.as_str());
println!("---------Install Desktop---------");
println!("{}", config.desktop); println!("{}", config.desktop);
println!("---------Timeshift---------"); desktops::choose_pkgs(config.desktop.as_str());
println!("---------Setup Timeshift---------");
println!("{}", config.timeshift); println!("{}", config.timeshift);
println!("---------Extra packages---------"); if config.timeshift {
base::setup_timeshift();
}
println!("---------Install Extra packages---------");
println!("{:?}", config.extra_packages); println!("{:?}", config.extra_packages);
let mut extra_packages: Vec<&str> = Vec::new();
for i in 0..config.extra_packages.len() {
extra_packages.push(config.extra_packages[i].as_str());
}
install(extra_packages);
} }

@ -199,8 +199,8 @@ fn main() {
base::genfstab(); base::genfstab();
} else if app.subcommand_matches("setup-timeshift").is_some() { } else if app.subcommand_matches("setup-timeshift").is_some() {
base::setup_timeshift(); base::setup_timeshift();
} else if app.subcommand_matches("config").is_some() { } else if let Some(app) = app.subcommand_matches("config") {
crate::internal::config::read_config(); crate::internal::config::read_config(app.value_of("config").unwrap());
} else { } else {
println!("Running TUI installer"); println!("Running TUI installer");
} }

Loading…
Cancel
Save