From 76f90560693d2364da8e369a4b9717c941a79a4f Mon Sep 17 00:00:00 2001 From: Clemens Schwaighofer Date: Fri, 11 Oct 2024 14:39:56 +0900 Subject: [PATCH] Fix user create with groups Move the params into array that we add as dynamic parameters to call --- bin/create_user.sh | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/bin/create_user.sh b/bin/create_user.sh index 5b650d5..a2986ec 100755 --- a/bin/create_user.sh +++ b/bin/create_user.sh @@ -234,11 +234,11 @@ while read -r i; do fi; ssh_group="ssh${ssh_access_type}"; # sshallow group is always added - sub_group_opt=" -G ${ssh_group}"; + sub_group_opt=("${ssh_group}"); # check if "," inside and extract sub groups if [ -z "${_group##*,*}" ]; then sub_group=$(echo "${_group}" | cut -d "," -f 2-); - sub_group_opt=" -G ${ssh_group},${sub_group}"; + sub_group_opt+=("${sub_group}"); fi; # POS 5: do we have a password preset _password=$(echo "${i}" | cut -d ";" -f 5); @@ -314,11 +314,17 @@ while read -r i; do echo "-- Skip '${username}:${group}(${sub_group})'"; else echo "++ Create '${username}:${group}(${sub_group})'"; + params=( + "-c" "$(date +"%F")" "-s" "${user_login_shell}" + "-g" "${group}" "-G" "$(IFS=, ; echo "${sub_group_opt[*]}")" + "-d" "${HOME_FOLDER}${username}" "-m" + "${username}" + ); if [ ${TEST} -eq 0 ]; then # comment is user create time - useradd -c "$(date +"%F")" -s "${user_login_shell}" -g "${group}"${sub_group_opt} -d "${HOME_FOLDER}${username}" -m "${username}"; + useradd "${params[@]}"; else - echo "$> useradd -c \"$(date +"%F")\" -s \"${user_login_shell}\" -g \"${group}\"${sub_group_opt} -d \"${HOME_FOLDER}${username}\" -m \"${username}\""; + echo "$> useradd ${params[*]}"; fi; fi; # set the auth file