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 } }