Skip to content

Commit

Permalink
fix: groupmod: GID '20' already exists on MacOS
Browse files Browse the repository at this point in the history
  • Loading branch information
rochecompaan committed Feb 1, 2024
1 parent 75a90d5 commit 191fa59
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,39 @@
#!/usr/bin/env sh
set -e

if [[ -z "$HOST_UID" ]]; then
# Check if HOST_UID and HOST_GID are provided
if [ -z "$HOST_UID" ]; then
echo "ERROR: please set HOST_UID" >&2
exit 1
fi
if [[ -z "$HOST_GID" ]]; then

if [ -z "$HOST_GID" ]; then
echo "ERROR: please set HOST_GID" >&2
exit 1
fi

# Modify a scaf user account to match the host user.
groupmod -g "$HOST_GID" scaf
# Function to check if a group with the given GID already exists
group_exists_with_gid() {
getent group | cut -d: -f3 | grep -q "^$1$"
}

# Modify the scaf user account to match the host user, adjusting for existing GID
if group_exists_with_gid "$HOST_GID"; then
# Find the group name with the target GID
existing_group=$(getent group | awk -F: "\$3 == $HOST_GID { print \$1 }")

# Use the existing group for the scaf user
usermod -g "$existing_group" scaf
else
# If GID does not exist, modify the scaf group to match HOST_GID
groupmod -g "$HOST_GID" scaf
fi

# Modify the scaf user to match HOST_UID
usermod -u "$HOST_UID" scaf

# Drop privileges and execute next container command, or 'bash' if not specified.
if [[ $# -gt 0 ]]; then
# Drop privileges and execute the next container command, or 'sh' if not specified
if [ "$#" -gt 0 ]; then
su-exec scaf "$@"
else
su-exec scaf sh

0 comments on commit 191fa59

Please # to comment.