-
-
Notifications
You must be signed in to change notification settings - Fork 92
/
docker-entrypoint.sh
45 lines (37 loc) · 1.62 KB
/
docker-entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/sh
set -e
DOCKER_USER='dockeruser'
DOCKER_GROUP='dockergroup'
if ! id "$DOCKER_USER" >/dev/null 2>&1; then
echo "First start of the docker container, start initialization process."
USER_ID=${PUID:-9001}
GROUP_ID=${PGID:-9001}
echo "Starting with $USER_ID:$GROUP_ID (UID:GID)"
# 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
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