Skip to content
This repository has been archived by the owner on Sep 17, 2024. It is now read-only.

Fix sudoers issue (#24) #27

Merged
merged 1 commit into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/functions/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub fn new_user(username: &str, hasroot: bool, password: &str, do_hash_pass: boo
format!("Add user {} to wheel group", username).as_str(),
);
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",
);
files_eval(
Expand Down
11 changes: 11 additions & 0 deletions src/internal/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ pub fn append_file(path: &str, content: &str) -> std::io::Result<()> {
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<()> {
std::fs::create_dir(path)
}