From 589584c7c63c066ef93b156a06b541c9a1ca64eb Mon Sep 17 00:00:00 2001 From: trivernis Date: Mon, 27 Mar 2023 20:12:20 +0200 Subject: [PATCH] Add setup users task --- configs/crystal/setup-users/up.nu | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/configs/crystal/setup-users/up.nu b/configs/crystal/setup-users/up.nu index 84f251a..ee6e29f 100644 --- a/configs/crystal/setup-users/up.nu +++ b/configs/crystal/setup-users/up.nu @@ -1,6 +1,28 @@ let RUN_IN_CHROOT = true; + +def create_user [user] { + debug $"Configuring user $($user.name)" + let shell = $"/usr/bin/($user.shell)" + run useradd -m -s $shell -p $user.password $user.name + + if $user.sudoer { + debug "user is sudoer" + run usermod -aG wheel $user.name + } + + touch "/var/lib/AccountsService/users/($user.name)" + "[User]\nsession=onyx" | save -a "/var/lib/AccountsService/users/($user.name)" + info $"Created user ($user.name)" +} + # Applies all system changes of `setup-users` def main [cfg] { - echo "Executing up task `setup-users` with config" $cfg - todo "Implement setup-users" + debug $"Configuring users with config ($cfg)" + ( open /etc/sudoers + | str replace "^# (%wheel ALL=(ALL:ALL) ALL)$" "$1" + | $in + "\nDefaults pwfeedback\n" + | save -f /etc/sudoers ) + mkdir /var/lib/AccountsService/users + + $cfg | each { |$user_cfg| create_user $user_cfg } }