entrypoint 578 Bytes
#!/bin/bash

set -ex

TARGET_USER=mongodb
TARGET_GROUP=mongodb

target_home="$(getent passwd "$TARGET_USER" | cut -f 6 -d :)"

if [[ $GID && $GID -ne 0 ]]; then
	groupmod -g $GID "$TARGET_GROUP"
fi
if [[ $UID && $UID -ne 0 ]]; then
	usermod -u $UID "$TARGET_USER"
fi

find "$target_home" \
	'(' -not -user "$TARGET_USER" -a -not -group "$TARGET_GROUP" -exec chown "$TARGET_USER:$TARGET_GROUP" '{}' + ')' -o \
	'(' -not -user "$TARGET_USER" -exec chown "$TARGET_USER" '{}' + ')' -o \
	'(' -not -group "$TARGET_GROUP" -exec chgrp "$TARGET_GROUP" '{}' + ')' -o \
	-true

exec "$@"