move command execution to src/internal/exec.rs and add first part of partitioning

axtloss/rework-partitioning
amy 3 years ago
parent 1015f96727
commit 6665868da7

@ -1,7 +1,7 @@
use crate::internal::*;
pub fn choose_pkgs(desktop_setup: &str) {
println!("Installing {}", desktop_setup);
log(format!("Installing {}", desktop_setup));
match desktop_setup {
"onyx" => {
install(vec![

@ -6,7 +6,7 @@ pub fn set_hostname(hostname: &str) {
let return_val = files::append_file("/etc/hostname", hostname);
match return_val {
Ok(_) => {
info(format!("Set hostname to {}", hostname));
log(format!("Set hostname to {}", hostname));
}
Err(e) => {
crash(
@ -19,17 +19,16 @@ pub fn set_hostname(hostname: &str) {
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());
log("Enabled IPv6".to_string());
}
Err(e) => {
crash(format!("Failed to enable IPv6, Error: {}", e), 1);
}
}
} else {
println!("Not enabling ipv6");
log("Not enabling ipv6".to_string());
}
}

@ -1,7 +1,135 @@
pub fn partition(device: &str, mode: &str) {
use crate::internal::exec::*;
use crate::internal::*;
pub fn partition(device: &str, mode: &str, efi: bool) {
if mode == "manual" {
println!("Manual partitioning");
log("Manual partitioning".to_string());
} else {
println!("automatically partitioning {}", device);
log(format!("automatically partitioning {}", device));
if efi {
let return_code = exec(
"parted",
vec![
String::from("-s"),
String::from(device),
String::from("mklabel"),
String::from("gpt"),
],
);
match return_code {
Ok(_) => {
log("Created GPT label".to_string());
}
Err(e) => {
crash(format!("Failed to create GPT label, Error: {}", e), 1);
}
}
let return_code = exec(
"parted",
vec![
String::from("-s"),
String::from(device),
String::from("mkpart"),
String::from("fat32"),
String::from("0"),
String::from("300"),
],
);
match return_code {
Ok(_) => {
log("Created fat32 EFI partition".to_string());
}
Err(e) => {
crash(
format!("Failed to create fat32 EFI partition, Error: {}", e),
1,
);
}
}
let return_code = exec(
"parted",
vec![
String::from("-s"),
String::from(device),
String::from("mkpart"),
String::from("btrfs"),
String::from("300"),
String::from("100%"),
],
);
match return_code {
Ok(_) => {
log("Created btrfs root partition".to_string());
}
Err(e) => {
crash(
format!("Failed to create btrfs root partition, Error: {}", e),
1,
);
}
}
} else {
let return_code = exec(
"parted",
vec![
String::from("-s"),
String::from(device),
String::from("mklabel"),
String::from("msdos"),
],
);
match return_code {
Ok(_) => {
log("Created MSDOS label".to_string());
}
Err(e) => {
crash(format!("Failed to create MSDOS label, Error: {}", e), 1);
}
}
let return_code = exec(
"parted",
vec![
String::from("-s"),
String::from(device),
String::from("mkpart"),
String::from("btrfs"),
String::from("512MIB"),
String::from("100&"),
],
);
match return_code {
Ok(_) => {
log("Created btrfs root partition".to_string());
}
Err(e) => {
crash(
format!("Failed to create btrfs root partition, Error: {}", e),
1,
);
}
}
let return_code = exec(
"parted",
vec![
String::from("-s"),
String::from(device),
String::from("mkpart"),
String::from("ext4"),
String::from("1MIB"),
String::from("512MIB"),
],
);
match return_code {
Ok(_) => {
log("Created ext4 boot partition".to_string());
}
Err(e) => {
crash(
format!("Failed to create ext4 boot partition, Error: {}", e),
1,
);
}
}
}
}
}

@ -1,16 +1,19 @@
use crate::internal::exec::*;
use crate::internal::*;
use std::process::Command;
pub fn new_user(username: &str, hasroot: bool, password: &str) {
let return_val = Command::new("useradd")
.arg("-m")
.arg("-s")
.arg("/bin/bash")
.arg(username)
.output();
let return_val = exec(
"useradd",
vec![
String::from("-m"),
String::from("-s"),
String::from("/bin/bash"),
String::from(username),
],
);
match return_val {
Ok(_) => {
info(format!("Created user {}", username));
log(format!("Created user {}", username));
}
Err(e) => {
crash(
@ -20,37 +23,43 @@ pub fn new_user(username: &str, hasroot: bool, password: &str) {
}
}
if hasroot {
let return_val = Command::new("usermod")
.arg("-a")
.arg("-G")
.arg("wheel")
.arg(username)
.output();
let return_val = exec(
"usermod",
vec![
String::from("-a"),
String::from("-G"),
String::from("wheel"),
String::from(username),
],
);
match return_val {
Ok(_) => {
info(format!("Added user {} to group wheel", username));
log(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();
let return_val = exec(
"arch-chroot",
vec![
String::from("/mnt"),
String::from("usermod"),
String::from("--password"),
String::from("$(echo"),
String::from(format!("${}", password)),
String::from("|"),
String::from("openssl"),
String::from("passwd"),
String::from("-1"),
String::from("-stdin)"),
String::from(username),
],
);
match return_val {
Ok(_) => {
info(format!("Set password for user {}", username));
log(format!("Set password for user {}", username));
}
Err(e) => {
crash(
@ -63,22 +72,25 @@ pub fn new_user(username: &str, hasroot: bool, password: &str) {
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();
let return_val = exec(
"arch-chroot",
vec![
String::from("/mnt"),
String::from("usermod"),
String::from("--password"),
String::from("$(echo"),
String::from(format!("${{{}}}", root_pass)),
String::from("|"),
String::from("openssl"),
String::from("passwd"),
String::from("-1"),
String::from("-stdin)"),
String::from("root"),
],
);
match return_val {
Ok(_) => {
info("Set root password".to_string());
log("Set root password".to_string());
}
Err(e) => {
crash(format!("Failed to set root password, Error: {}", e), 1);

@ -0,0 +1,6 @@
use std::process::Command;
pub fn exec(command: &str, args: Vec<String>) -> Result<std::process::Output, std::io::Error> {
let returncode = Command::new(command).args(args).output();
returncode
}

@ -6,7 +6,7 @@ pub fn create_file(path: &str) {
let return_val = File::create(path);
match return_val {
Ok(_file) => {
info(format!("Created file {}", path));
log(format!("Created file {}", path));
}
Err(e) => {
crash(format!("Failed to create file {}, Error: {}", path, e), 1);
@ -15,7 +15,7 @@ pub fn create_file(path: &str) {
}
pub fn append_file(path: &str, content: &str) -> std::io::Result<()> {
info(format!("Appending {} to file {}", content, path));
log(format!("Appending {} to file {}", content, path));
let mut file = OpenOptions::new().append(true).open(path)?;
file.write(content.as_bytes())?;
Ok(())
@ -25,7 +25,7 @@ pub fn delete_file(path: &str) {
let return_val = std::fs::remove_file(path);
match return_val {
Ok(_) => {
info(format!("Deleted file {}", path));
log(format!("Deleted file {}", path));
}
Err(e) => {
crash(format!("Failed to delete file {}, Error: {}", path, e), 1);
@ -37,7 +37,7 @@ pub fn create_directory(path: &str) {
let return_val = std::fs::create_dir(path);
match return_val {
Ok(_) => {
info(format!("Created directory {}", path));
log(format!("Created directory {}", path));
}
Err(e) => {
crash(
@ -54,7 +54,7 @@ pub fn overwrite_file(path: &str, content: &str) {
let return_val = append_file(path, content);
match return_val {
Ok(_) => {
info(format!("Overwrote file {}", path));
log(format!("Overwrote file {}", path));
}
Err(e) => {
crash(

@ -1,3 +1,4 @@
pub mod exec;
pub mod files;
pub mod install;
pub mod strings;

@ -1,9 +1,8 @@
use crate::uwu;
use std::io::Write;
use std::env;
use std::process::exit;
use std::str::FromStr;
use std::time::UNIX_EPOCH;
use std::{env, io};
pub fn info(a: String) {
let a = if env::var("JADE_UWU").unwrap_or_else(|_| "".to_string()) == "true" {
uwu!(&a)

@ -22,6 +22,12 @@ fn main() {
.help("The device to partition")
.required_if("mode", "auto"),
)
.arg(
Arg::with_name("efi")
.help("If the install destination should be partitioned with EFI")
.long("efi")
.takes_value(false),
),
)
.subcommand(
SubCommand::with_name("locale")
@ -104,6 +110,7 @@ fn main() {
partition::partition(
app.value_of("device").unwrap(),
app.value_of("mode").unwrap(),
app.is_present("efi"),
);
} else if let Some(app) = app.subcommand_matches("locale") {
let kbrlayout = app.value_of("keyboard").unwrap();

Loading…
Cancel
Save