Fix user group add

This commit is contained in:
2025-07-15 14:33:34 -04:00
parent fd5c2b91c4
commit 42b154b015

View File

@@ -16,7 +16,6 @@ case $# in
esac esac
useradd_cmd=(useradd -m -U) useradd_cmd=(useradd -m -U)
group_str=""
if id -u "$user" &>/dev/null; then if id -u "$user" &>/dev/null; then
ask_ok "User $user exists. Run script-user-remove first?" || exit $? ask_ok "User $user exists. Run script-user-remove first?" || exit $?
@@ -30,11 +29,18 @@ if [[ -d /mnt/array/home-retired/$user ]]; then
ask_ok "Restore user $user's files from /mnt/array/home-retired/$user?" && restore=1 ask_ok "Restore user $user's files from /mnt/array/home-retired/$user?" && restore=1
fi fi
groups=()
samba=0 samba=0
ask_ok "Enable shared file access for user $user?" && group_str="smbgrp" && samba=1 if ask_ok "Enable shared file access for user $user?"; then
ask_ok "Make $user an admin?" && group_str+=",wheel" 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+=("$user")
"${useradd_cmd[@]}" "${useradd_cmd[@]}"