maybe?
This commit is contained in:
@@ -16,20 +16,30 @@ else
|
|||||||
if [ "${PUID}" -eq 0 ] && [ "${PGID}" -eq 0 ]; then
|
if [ "${PUID}" -eq 0 ] && [ "${PGID}" -eq 0 ]; then
|
||||||
exec "$@"
|
exec "$@"
|
||||||
else
|
else
|
||||||
# Create group if it doesn't exist
|
# Check if the group with the specified GID already exists
|
||||||
if ! getent group appgroup >/dev/null; then
|
if getent group "${PGID}" >/dev/null; then
|
||||||
groupadd -g "${PGID}" appgroup
|
# If the group exists, use its name instead of creating a new one
|
||||||
|
GROUP_NAME=$(getent group "${PGID}" | cut -d: -f1)
|
||||||
|
else
|
||||||
|
# If the group doesn't exist, create it
|
||||||
|
GROUP_NAME="appgroup"
|
||||||
|
groupadd -g "${PGID}" "${GROUP_NAME}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Create user if it doesn't exist
|
# Check if the user with the specified UID already exists
|
||||||
if ! id appuser >/dev/null 2>&1; then
|
if getent passwd "${PUID}" >/dev/null; then
|
||||||
useradd -u "${PUID}" -g appgroup -d /app appuser
|
# If the user exists, use its name instead of creating a new one
|
||||||
|
USER_NAME=$(getent passwd "${PUID}" | cut -d: -f1)
|
||||||
|
else
|
||||||
|
# If the user doesn't exist, create it
|
||||||
|
USER_NAME="appuser"
|
||||||
|
useradd -u "${PUID}" -g "${GROUP_NAME}" -d /app "${USER_NAME}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Ensure proper permissions
|
# Ensure proper permissions
|
||||||
chown -R appuser:appgroup /app
|
chown -R "${USER_NAME}:${GROUP_NAME}" /app
|
||||||
|
|
||||||
# Run as specified user
|
# Run as specified user
|
||||||
exec gosu appuser "$@"
|
exec gosu "${USER_NAME}" "$@"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
Reference in New Issue
Block a user