user management, desktop and network backend mostly finished
parent
73f0801b0d
commit
1015f96727
@ -1,35 +1,77 @@
|
|||||||
use crate::internal::*;
|
use crate::internal::*;
|
||||||
|
|
||||||
pub fn choose_pkgs(desktop_setup: &str) {
|
pub fn choose_pkgs(desktop_setup: &str) {
|
||||||
println!("Installing {}", desktop_setup);
|
println!("Installing {}", desktop_setup);
|
||||||
match desktop_setup {
|
match desktop_setup {
|
||||||
"onyx" => {
|
"onyx" => {
|
||||||
install(vec!("onyx", "lightdm", "lightdm-gtk-greeter", "lightdm-gtk-greeter-settings"));
|
install(vec![
|
||||||
}
|
"onyx",
|
||||||
"gnome" => {
|
"lightdm",
|
||||||
install(vec!("gnome","gnome-tweaks","chrome-gnome-shell","gdm"));
|
"lightdm-gtk-greeter",
|
||||||
},
|
"lightdm-gtk-greeter-settings",
|
||||||
"kde" => {
|
]);
|
||||||
install(vec!("kde", "plasma", "plasma-wayland-session", "kde-applications", "sddm"));
|
}
|
||||||
},
|
"gnome" => {
|
||||||
"budgie" => {
|
install(vec!["gnome", "gnome-tweaks", "chrome-gnome-shell", "gdm"]);
|
||||||
install(vec!("budgie-desktop", "gnome", "lightdm", "lightdm-gtk-greeter", "lightdm-gtk-greeter-settings"));
|
}
|
||||||
},
|
"kde" => {
|
||||||
"cinnamon" => {
|
install(vec![
|
||||||
install(vec!("cinnamon", "lightdm", "lightdm-gtk-greeter", "lightdm-gtk-greeter-settings", "metacity", "gnome-shell"));
|
"kde",
|
||||||
},
|
"plasma",
|
||||||
"mate" => {
|
"plasma-wayland-session",
|
||||||
install(vec!("mate", "lightdm", "lightdm-gtk-greeter", "lightdm-gtk-greeter-settings", "mate-extra"));
|
"kde-applications",
|
||||||
},
|
"sddm",
|
||||||
"xfce" => {
|
]);
|
||||||
install(vec!("xfce4", "lightdm", "lightdm-gtk-greeter", "lightdm-gtk-greeter-settings", "xfce4-goodies"));
|
}
|
||||||
},
|
"budgie" => {
|
||||||
"enlightenment" => {
|
install(vec![
|
||||||
install(vec!("enlightenment", "lightdm", "lightdm-gtk-greeter", "lightdm-gtk-greeter-settings", "terminology"));
|
"budgie-desktop",
|
||||||
},
|
"gnome",
|
||||||
|
"lightdm",
|
||||||
_ => {
|
"lightdm-gtk-greeter",
|
||||||
crash("Unknown desktop setup".to_string(), 1);
|
"lightdm-gtk-greeter-settings",
|
||||||
}
|
]);
|
||||||
}
|
}
|
||||||
}
|
"cinnamon" => {
|
||||||
|
install(vec![
|
||||||
|
"cinnamon",
|
||||||
|
"lightdm",
|
||||||
|
"lightdm-gtk-greeter",
|
||||||
|
"lightdm-gtk-greeter-settings",
|
||||||
|
"metacity",
|
||||||
|
"gnome-shell",
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
"mate" => {
|
||||||
|
install(vec![
|
||||||
|
"mate",
|
||||||
|
"lightdm",
|
||||||
|
"lightdm-gtk-greeter",
|
||||||
|
"lightdm-gtk-greeter-settings",
|
||||||
|
"mate-extra",
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
"xfce" => {
|
||||||
|
install(vec![
|
||||||
|
"xfce4",
|
||||||
|
"lightdm",
|
||||||
|
"lightdm-gtk-greeter",
|
||||||
|
"lightdm-gtk-greeter-settings",
|
||||||
|
"xfce4-goodies",
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
"enlightenment" => {
|
||||||
|
install(vec![
|
||||||
|
"enlightenment",
|
||||||
|
"lightdm",
|
||||||
|
"lightdm-gtk-greeter",
|
||||||
|
"lightdm-gtk-greeter-settings",
|
||||||
|
"terminology",
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
_ => {
|
||||||
|
crash("Unknown desktop setup".to_string(), 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
pub mod partition;
|
pub mod desktops;
|
||||||
pub mod network;
|
pub mod network;
|
||||||
pub mod users;
|
pub mod partition;
|
||||||
pub mod desktops;
|
pub mod users;
|
||||||
|
@ -1,11 +1,35 @@
|
|||||||
pub fn set_hostname(hostname: &str) {
|
use crate::internal::*;
|
||||||
println!("Setting hostname to {}", hostname);
|
|
||||||
}
|
pub fn set_hostname(hostname: &str) {
|
||||||
|
println!("Setting hostname to {}", hostname);
|
||||||
pub fn enable_ipv6(ipv6: bool) {
|
files::create_file("/etc/hostname");
|
||||||
if ipv6 {
|
let return_val = files::append_file("/etc/hostname", hostname);
|
||||||
println!("enabling ipv6");
|
match return_val {
|
||||||
} else {
|
Ok(_) => {
|
||||||
println!("disabling ipv6");
|
info(format!("Set hostname to {}", hostname));
|
||||||
}
|
}
|
||||||
}
|
Err(e) => {
|
||||||
|
crash(
|
||||||
|
format!("Failed to set hostname to {}, Error: {}", hostname, e),
|
||||||
|
1,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn enable_ipv6(ipv6: bool) {
|
||||||
|
if ipv6 {
|
||||||
|
println!("Enabling IPv6");
|
||||||
|
let return_val = files::append_file("/etc/hosts", "::1 localhost");
|
||||||
|
match return_val {
|
||||||
|
Ok(_) => {
|
||||||
|
info("Enabled IPv6".to_string());
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
crash(format!("Failed to enable IPv6, Error: {}", e), 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
println!("Not enabling ipv6");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
pub fn partition(device: &str, mode: &str) {
|
pub fn partition(device: &str, mode: &str) {
|
||||||
if mode == "manual" {
|
if mode == "manual" {
|
||||||
println!("Manual partitioning");
|
println!("Manual partitioning");
|
||||||
} else {
|
} else {
|
||||||
println!("automatically partitioning {}", device);
|
println!("automatically partitioning {}", device);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,87 @@
|
|||||||
pub fn new_user(username: &str, hasroot: bool, password: &str) {
|
use crate::internal::*;
|
||||||
println!("Creating new user '{}'", username);
|
use std::process::Command;
|
||||||
if hasroot {
|
|
||||||
println!("User '{}' will have root privileges", username);
|
pub fn new_user(username: &str, hasroot: bool, password: &str) {
|
||||||
} else {
|
let return_val = Command::new("useradd")
|
||||||
println!("User '{}' will not have root privileges", username);
|
.arg("-m")
|
||||||
}
|
.arg("-s")
|
||||||
println!("Setting password for user '{}' to '{}'", username, password);
|
.arg("/bin/bash")
|
||||||
}
|
.arg(username)
|
||||||
|
.output();
|
||||||
pub fn root_pass(root_pass: &str) {
|
match return_val {
|
||||||
println!("Setting root password to '{}'", root_pass);
|
Ok(_) => {
|
||||||
}
|
info(format!("Created user {}", username));
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
crash(
|
||||||
|
format!("Failed to create user {}, Error: {}", username, e),
|
||||||
|
1,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if hasroot {
|
||||||
|
let return_val = Command::new("usermod")
|
||||||
|
.arg("-a")
|
||||||
|
.arg("-G")
|
||||||
|
.arg("wheel")
|
||||||
|
.arg(username)
|
||||||
|
.output();
|
||||||
|
match return_val {
|
||||||
|
Ok(_) => {
|
||||||
|
info(format!("Added user {} to group wheel", username));
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
crash(format!("Failed to add user {}, Error: {}", username, e), 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let return_val = Command::new("arch-chroot")
|
||||||
|
.arg("/mnt")
|
||||||
|
.arg("usermod")
|
||||||
|
.arg("--password")
|
||||||
|
.arg("$(echo")
|
||||||
|
.arg(format!("${{{}}}", password))
|
||||||
|
.arg("|")
|
||||||
|
.arg("openssl")
|
||||||
|
.arg("passwd")
|
||||||
|
.arg("-1")
|
||||||
|
.arg("-stdin)")
|
||||||
|
.arg(username)
|
||||||
|
.output();
|
||||||
|
match return_val {
|
||||||
|
Ok(_) => {
|
||||||
|
info(format!("Set password for user {}", username));
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
crash(
|
||||||
|
format!("Failed to set password for user {}, Error: {}", username, e),
|
||||||
|
1,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn root_pass(root_pass: &str) {
|
||||||
|
println!("Setting root password to '{}'", root_pass);
|
||||||
|
let return_val = Command::new("arch-chroot")
|
||||||
|
.arg("/mnt")
|
||||||
|
.arg("usermod")
|
||||||
|
.arg("--password")
|
||||||
|
.arg("$(echo")
|
||||||
|
.arg(format!("${{{}}}", root_pass))
|
||||||
|
.arg("|")
|
||||||
|
.arg("openssl")
|
||||||
|
.arg("passwd")
|
||||||
|
.arg("-1")
|
||||||
|
.arg("-stdin)")
|
||||||
|
.arg("root")
|
||||||
|
.output();
|
||||||
|
match return_val {
|
||||||
|
Ok(_) => {
|
||||||
|
info("Set root password".to_string());
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
crash(format!("Failed to set root password, Error: {}", e), 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -0,0 +1,66 @@
|
|||||||
|
use crate::internal::*;
|
||||||
|
use std::fs::{File, OpenOptions};
|
||||||
|
use std::io::prelude::*;
|
||||||
|
|
||||||
|
pub fn create_file(path: &str) {
|
||||||
|
let return_val = File::create(path);
|
||||||
|
match return_val {
|
||||||
|
Ok(_file) => {
|
||||||
|
info(format!("Created file {}", path));
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
crash(format!("Failed to create file {}, Error: {}", path, e), 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn append_file(path: &str, content: &str) -> std::io::Result<()> {
|
||||||
|
info(format!("Appending {} to file {}", content, path));
|
||||||
|
let mut file = OpenOptions::new().append(true).open(path)?;
|
||||||
|
file.write(content.as_bytes())?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn delete_file(path: &str) {
|
||||||
|
let return_val = std::fs::remove_file(path);
|
||||||
|
match return_val {
|
||||||
|
Ok(_) => {
|
||||||
|
info(format!("Deleted file {}", path));
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
crash(format!("Failed to delete file {}, Error: {}", path, e), 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn create_directory(path: &str) {
|
||||||
|
let return_val = std::fs::create_dir(path);
|
||||||
|
match return_val {
|
||||||
|
Ok(_) => {
|
||||||
|
info(format!("Created directory {}", path));
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
crash(
|
||||||
|
format!("Failed to create directory {}, Error: {}", path, e),
|
||||||
|
1,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn overwrite_file(path: &str, content: &str) {
|
||||||
|
delete_file(path);
|
||||||
|
create_file(path);
|
||||||
|
let return_val = append_file(path, content);
|
||||||
|
match return_val {
|
||||||
|
Ok(_) => {
|
||||||
|
info(format!("Overwrote file {}", path));
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
crash(
|
||||||
|
format!("Failed to overwrite file {}, Error: {}", path, e),
|
||||||
|
1,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,9 @@
|
|||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
pub fn install(pkgs: Vec<&str>) {
|
pub fn install(pkgs: Vec<&str>) {
|
||||||
Command::new("pacman").arg("-S").args(pkgs).output().expect("Failed to install packages");
|
Command::new("pacstrap")
|
||||||
}
|
.arg("/mnt")
|
||||||
|
.args(pkgs)
|
||||||
|
.output()
|
||||||
|
.expect("Failed to install packages");
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue