Fix sed issue for sudoers (hopefully) and replace `micro` with `nano`

axtloss/rework-partitioning
Michal S 2 years ago committed by Michal
parent 43f9f5c324
commit 6c156d2009

@ -29,7 +29,7 @@ pub fn install_base_packages(kernel: String) {
"man-db", "man-db",
"man-pages", "man-pages",
"texinfo", "texinfo",
"micro", "nano",
"sudo", "sudo",
"curl", "curl",
"archlinux-keyring", "archlinux-keyring",

@ -1,5 +1,5 @@
use crate::internal::*; use crate::internal::*;
use std::fs::{File, OpenOptions}; use std::fs::{File, OpenOptions, read_to_string};
use std::io::prelude::*; use std::io::prelude::*;
pub fn create_file(path: &str) { pub fn create_file(path: &str) {
@ -38,12 +38,15 @@ pub fn append_file(path: &str, content: &str) -> std::io::Result<()> {
pub fn sed_file(path: &str, find: &str, replace: &str) -> std::io::Result<()> { pub fn sed_file(path: &str, find: &str, replace: &str) -> std::io::Result<()> {
log::info!("Sed '{}' to '{}' in file {}", find, replace, path); log::info!("Sed '{}' to '{}' in file {}", find, replace, path);
let mut file = OpenOptions::new().read(true).write(true).open(path)?; let mut file = OpenOptions::new().read(true).write(true).open(path)?;
let mut contents = String::new();
file.read_to_string(&mut contents)?; let contents = read_to_string(path)?;
contents = contents.replace(find, replace); let contents = contents.replace(find, replace);
file.set_len(0)?; file.set_len(0)?;
file.write_all(contents.as_bytes())?; file.write_all(contents.as_bytes())?;
Ok(()) Ok(())
} }

Loading…
Cancel
Save