Skip to content

Commit f0a3ad1

Browse files
committed
If group userGid exists, use its name
1 parent e3e3ed7 commit f0a3ad1

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/common-utils/main.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,12 +411,16 @@ elif [ "${USERNAME}" = "none" ]; then
411411
USER_UID=0
412412
USER_GID=0
413413
fi
414+
414415
# Create or update a non-root user to match UID/GID.
415-
group_name="${USERNAME}"
416+
group_name=$(getent group "$USER_GID" | cut -d: -f3)
417+
if [ -z "$group_name" ]; then
418+
# Group does not yet exist and will be created. Use the user name as group name.
419+
group_name="${USERNAME}"
420+
fi
416421
if id -u ${USERNAME} > /dev/null 2>&1; then
417422
# User exists, update if needed
418423
if [ "${USER_GID}" != "automatic" ] && [ "$USER_GID" != "$(id -g $USERNAME)" ]; then
419-
group_name="$(id -gn $USERNAME)"
420424
groupmod --gid $USER_GID ${group_name}
421425
usermod --gid $USER_GID $USERNAME
422426
fi

0 commit comments

Comments
 (0)