From 42b154b01508542b666cbdf2d3ee8678758c3ca8 Mon Sep 17 00:00:00 2001 From: Bryan Roessler Date: Tue, 15 Jul 2025 14:33:34 -0400 Subject: [PATCH] Fix user group add --- scripts/usr/local/bin/script-user-add | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/scripts/usr/local/bin/script-user-add b/scripts/usr/local/bin/script-user-add index 5e3a71a1..f6f7b60d 100755 --- a/scripts/usr/local/bin/script-user-add +++ b/scripts/usr/local/bin/script-user-add @@ -16,7 +16,6 @@ case $# in esac useradd_cmd=(useradd -m -U) -group_str="" if id -u "$user" &>/dev/null; then ask_ok "User $user exists. Run script-user-remove first?" || exit $? @@ -30,24 +29,31 @@ if [[ -d /mnt/array/home-retired/$user ]]; then ask_ok "Restore user $user's files from /mnt/array/home-retired/$user?" && restore=1 fi +groups=() samba=0 -ask_ok "Enable shared file access for user $user?" && group_str="smbgrp" && samba=1 -ask_ok "Make $user an admin?" && group_str+=",wheel" +if ask_ok "Enable shared file access for user $user?"; then + groups+=("smbgrp") + samba=1 +fi -[[ -n $group_str ]] && useradd_cmd+=("-G" "$group_str") +ask_ok "Make $user an admin?" && groups+=("wheel") + +if (( ${#groups[@]} )); then + useradd_cmd+=("-G" "$(IFS=,; echo "${groups[*]}")") +fi useradd_cmd+=("$user") "${useradd_cmd[@]}" echo "$user:$password" | chpasswd -if (( restore )); then +if ((restore)); then if rsync -av --progress=info2 "/mnt/array/home-retired/$user/" "/home/$user/"; then ask_ok "User $user's files successfully restored, remove backup at /mnt/array/home-retired/$user?" && \ rm -rf "/mnt/array/home-retired/$user" fi fi -if (( samba )); then +if ((samba)); then (echo "$password"; echo "$password") | smbpasswd -a -s "$user" fi