Fix sudoers issue (#24)

axtloss/rework-partitioning
Michal S 2 years ago committed by Michal
parent 402e71ddea
commit b855a36d1a

@ -55,7 +55,7 @@ pub fn new_user(username: &str, hasroot: bool, password: &str, do_hash_pass: boo
format!("Add user {} to wheel group", username).as_str(), format!("Add user {} to wheel group", username).as_str(),
); );
files_eval( files_eval(
files::append_file("/mnt/etc/sudoers", "\n%wheel ALL=(ALL) ALL\n"), files::sed_file("/mnt/etc/sudoers", "# %wheel ALL=(ALL) ALL", "%wheel ALL=(ALL) ALL"),
"Add wheel group to sudoers", "Add wheel group to sudoers",
); );
files_eval( files_eval(

@ -36,6 +36,17 @@ pub fn append_file(path: &str, content: &str) -> std::io::Result<()> {
Ok(()) Ok(())
} }
pub fn sed_file(path: &str, find: &str, replace: &str) -> std::io::Result<()> {
log::info!("Sed '{}' to '{}' in file {}", find, replace, path);
let mut file = OpenOptions::new().read(true).write(true).open(path)?;
let mut contents = String::new();
file.read_to_string(&mut contents)?;
contents = contents.replace(find, replace);
file.set_len(0)?;
file.write_all(contents.as_bytes())?;
Ok(())
}
pub fn create_directory(path: &str) -> std::io::Result<()> { pub fn create_directory(path: &str) -> std::io::Result<()> {
std::fs::create_dir(path) std::fs::create_dir(path)
} }

Loading…
Cancel
Save