Skip to content

Commit

Permalink
Merge branch 'latest' of github.com-b2un0:mtoensing/Docker-Minecraft-…
Browse files Browse the repository at this point in the history
…PaperMC-Server into latest
  • Loading branch information
b2un0 committed Jan 3, 2025
2 parents 599594a + b6d0f04 commit 69b7aa7
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,35 @@ if ! id "$DOCKER_USER" >/dev/null 2>&1; then
GROUP_ID=${PGID:-9001}
echo "Starting with $USER_ID:$GROUP_ID (UID:GID)"

addgroup --gid $GROUP_ID $DOCKER_GROUP
adduser $DOCKER_USER --shell /bin/sh --uid $USER_ID --ingroup $DOCKER_GROUP --disabled-password --gecos ""
# Check if the desired GROUP_ID is already in use
if getent group $GROUP_ID >/dev/null 2>&1; then
EXISTING_GROUP=$(getent group $GROUP_ID | cut -d: -f1)
echo "GID $GROUP_ID is already in use by group $EXISTING_GROUP. Using this group."
DOCKER_GROUP=$EXISTING_GROUP
else
addgroup --gid $GROUP_ID $DOCKER_GROUP
echo "Created group $DOCKER_GROUP with GID $GROUP_ID."
fi

# Check if the desired USER_ID is already in use
if id -u $USER_ID >/dev/null 2>&1; then
EXISTING_USER=$(getent passwd $USER_ID | cut -d: -f1)
echo "UID $USER_ID is already in use by user $EXISTING_USER. Using this user."
DOCKER_USER=$EXISTING_USER
else
# Create user with the specified UID and associated group
adduser --shell /bin/sh --uid $USER_ID --ingroup $DOCKER_GROUP --disabled-password --gecos "" $DOCKER_USER
echo "Created user $DOCKER_USER with UID $USER_ID."
fi

# Set ownership and permissions
chown -vR $USER_ID:$GROUP_ID /opt/minecraft
chmod -vR ug+rwx /opt/minecraft

if [ "$SKIP_PERM_CHECK" != "true" ]
then
if [ "$SKIP_PERM_CHECK" != "true" ]; then
chown -vR $USER_ID:$GROUP_ID /data
fi
fi

export HOME=/home/$DOCKER_USER
exec gosu $DOCKER_USER:$DOCKER_GROUP java -jar -Xms$MEMORYSIZE -Xmx$MEMORYSIZE $JAVAFLAGS /opt/minecraft/paperspigot.jar $PAPERMC_FLAGS nogui

exec gosu $DOCKER_USER:$DOCKER_GROUP java -jar -Xms$MEMORYSIZE -Xmx$MEMORYSIZE $JAVAFLAGS /opt/minecraft/paperspigot.jar $PAPERMC_FLAGS nogui

0 comments on commit 69b7aa7

Please sign in to comment.