wheel group

This commit is contained in:
JMARyA 2025-01-10 09:28:03 +01:00
parent 33a8fed192
commit 05cf6cf9da
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
6 changed files with 20 additions and 17 deletions

View file

@ -52,5 +52,5 @@ name = "u"
# User password
password = "pass"
# Allow user to use `doas` as root
doas_root= true
# Add user to wheel group
wheel = true

View file

@ -69,8 +69,8 @@ home_dir = "/home/u"
# Set the shell of the user
shell = "/bin/bash"
# Allow user to use `doas` as root
doas_root= true
# Add user to wheel group
wheel = true
# Add user to Docker group
docker = true

View file

@ -52,8 +52,8 @@ name = "u"
# User password
password = "pass"
# Allow user to use `doas` as root
doas_root= true
# Add user to wheel group
wheel = true
# Add user to Docker group
docker = true

View file

@ -44,7 +44,7 @@ pub struct UserConfig {
pub uid: Option<u32>,
pub home_dir: Option<String>,
pub shell: Option<String>,
pub doas_root: Option<bool>,
pub wheel: Option<bool>,
pub docker: Option<bool>,
pub virtualization: Option<bool>,
}

View file

@ -1,7 +1,5 @@
use crate::{
config::UserConfig,
linux::{arch_chroot, install_file},
print_status,
config::UserConfig, linux::{arch_chroot, install_file}, pkg::install_pkgs, print_status
};
pub fn change_passwd(user: &str, pw: &str) {
@ -10,7 +8,10 @@ pub fn change_passwd(user: &str, pw: &str) {
/// Setup the users of the system
pub fn setup_users(conf: &[UserConfig]) {
let mut doas_conf = String::new();
if !conf.is_empty() {
install_pkgs(&["doas"]);
install_file("/mnt/etc/doas.conf", "permit persist :wheel as root", 0o644);
}
for user in conf {
let mut cmd = vec!["useradd"];
@ -45,11 +46,13 @@ pub fn setup_users(conf: &[UserConfig]) {
change_passwd(&user.name, &user.password);
if user.doas_root.unwrap_or_default() {
print_status(&format!("Allowing root doas for {}", user.name));
doas_conf.push_str(&format!("permit {} as root\n", user.name));
if user.wheel.unwrap_or_default() {
print_status(&format!("Adding {} to wheel", user.name));
arch_chroot(
&vec!["usermod", "-a", "-G", "wheel", user.name.as_str()],
None,
false,
);
}
}
install_file("/mnt/etc/doas.conf", &doas_conf, 0o644);
}

View file

@ -94,7 +94,7 @@ pub fn print_config(conf: &InstallConfig) {
for user in user_conf {
let mut groups = Vec::new();
if user.doas_root.unwrap_or_default() {
if user.wheel.unwrap_or_default() {
groups.push("🔑");
}