make stuff actually run in chroot

axtloss/rework-partitioning
amy 3 years ago
parent d32c20e6f7
commit a241d83130

@ -2,8 +2,8 @@ use crate::internal::*;
pub fn set_hostname(hostname: &str) { pub fn set_hostname(hostname: &str) {
println!("Setting hostname to {}", hostname); println!("Setting hostname to {}", hostname);
files::create_file("/etc/hostname"); files::create_file("/mnt/etc/hostname");
let return_val = files::append_file("/etc/hostname", hostname); let return_val = files::append_file("/mnt/etc/hostname", hostname);
match return_val { match return_val {
Ok(_) => { Ok(_) => {
log(format!("Set hostname to {}", hostname)); log(format!("Set hostname to {}", hostname));
@ -19,7 +19,7 @@ pub fn set_hostname(hostname: &str) {
pub fn enable_ipv6(ipv6: bool) { pub fn enable_ipv6(ipv6: bool) {
if ipv6 { if ipv6 {
let return_val = files::append_file("/etc/hosts", "::1 localhost"); let return_val = files::append_file("/mnt/etc/hosts", "::1 localhost");
match return_val { match return_val {
Ok(_) => { Ok(_) => {
log("Enabled IPv6".to_string()); log("Enabled IPv6".to_string());

@ -2,7 +2,7 @@ use crate::internal::exec::*;
use crate::internal::*; use crate::internal::*;
pub fn new_user(username: &str, hasroot: bool, password: &str) { pub fn new_user(username: &str, hasroot: bool, password: &str) {
let return_val = exec( let return_val = exec_chroot(
"useradd", "useradd",
vec![ vec![
String::from("-m"), String::from("-m"),
@ -23,7 +23,7 @@ pub fn new_user(username: &str, hasroot: bool, password: &str) {
} }
} }
if hasroot { if hasroot {
let return_val = exec( let return_val = exec_chroot(
"usermod", "usermod",
vec![ vec![
String::from("-a"), String::from("-a"),
@ -41,11 +41,9 @@ pub fn new_user(username: &str, hasroot: bool, password: &str) {
} }
} }
} }
let return_val = exec( let return_val = exec_chroot(
"arch-chroot", "usermod",
vec![ vec![
String::from("/mnt"),
String::from("usermod"),
String::from("--password"), String::from("--password"),
String::from("$(echo"), String::from("$(echo"),
String::from(format!("${}", password)), String::from(format!("${}", password)),
@ -72,11 +70,9 @@ pub fn new_user(username: &str, hasroot: bool, password: &str) {
pub fn root_pass(root_pass: &str) { pub fn root_pass(root_pass: &str) {
println!("Setting root password to '{}'", root_pass); println!("Setting root password to '{}'", root_pass);
let return_val = exec( let return_val = exec_chroot(
"arch-chroot", "usermod",
vec![ vec![
String::from("/mnt"),
String::from("usermod"),
String::from("--password"), String::from("--password"),
String::from("$(echo"), String::from("$(echo"),
String::from(format!("${{{}}}", root_pass)), String::from(format!("${{{}}}", root_pass)),

@ -5,6 +5,11 @@ pub fn exec(command: &str, args: Vec<String>) -> Result<std::process::Output, st
returncode returncode
} }
pub fn exec_chroot(command: &str, args: Vec<String>) -> Result<std::process::Output, std::io::Error> {
let returncode = Command::new("arch-chroot").args(&["/mnt", command]).args(args).output();
returncode
}
pub fn exec_workdir(command: &str, workdir: &str, args: Vec<String>,) -> Result<std::process::Output, std::io::Error> { pub fn exec_workdir(command: &str, workdir: &str, args: Vec<String>,) -> Result<std::process::Output, std::io::Error> {
let returncode = Command::new(command).args(args).current_dir(workdir).output(); let returncode = Command::new(command).args(args).current_dir(workdir).output();
returncode returncode

Loading…
Cancel
Save