No Longer Run MCPI As Root

This commit is contained in:
TheBrokenRail 2021-01-30 21:32:20 -05:00
parent b5556e91c3
commit f6dd4a17e6
13 changed files with 87 additions and 36 deletions

View File

@ -38,6 +38,11 @@ RUN ./build/build-mods.sh
# Runtime Environment # Runtime Environment
FROM runtime-base AS runtime FROM runtime-base AS runtime
# Setup /home Permissions
RUN \
mkdir -p /home && \
chmod -R a+rw /home
# Include Exported Libraries # Include Exported Libraries
COPY --from=build /app/export / COPY --from=build /app/export /
# Include Mods # Include Mods

View File

@ -35,16 +35,23 @@ Minecraft: Pi Edition Modding Project
| ``minecraft-pi-reborn-virgl`` | Minecraft Pi Edition Using VirGL For Hardware Acceleration (Recommended For Desktop) | | ``minecraft-pi-reborn-virgl`` | Minecraft Pi Edition Using VirGL For Hardware Acceleration (Recommended For Desktop) |
| ``minecraft-pi-reborn-native`` | Minecraft: Pi Edition Using Docker Device Mounting For GPU Acceleration (Recommended For ARM Devices (ie. Raspberry Pi, PinePhone, etc)) | | ``minecraft-pi-reborn-native`` | Minecraft: Pi Edition Using Docker Device Mounting For GPU Acceleration (Recommended For ARM Devices (ie. Raspberry Pi, PinePhone, etc)) |
## Troubleshooting Crashes ## Troubleshooting
Game logs are located in ``/tmp/minecraft-pi``. Game logs are located in ``/tmp/minecraft-pi``.
### ``Error response from daemon: error gathering device information while adding custom device "/dev/dri": no such file or directory`` ### ``Error response from daemon: error gathering device information while adding custom device "/dev/dri": no such file or directory``
Make sure you are using the correct GPU drivers for your system. If you are using a Raspberry Pi, make sure you have set your GPU driver to ``Full KMS`` or ``Fake KMS`` in ``raspi-config``. Make sure you are using the correct GPU drivers for your system. If you are using a Raspberry Pi, make sure your GPU driver is set to ``Full KMS`` or ``Fake KMS`` in ``raspi-config``.
### ``Segmentation Fault`` ### ``Segmentation Fault`` (Exit Code: ``139``)
1. Attempt To Reproduce Issue And Record Instructions 1. Attempt To Reproduce Issue And Record Instructions
2. Report On Issue Tracker Including The Instructions To Reproduce 2. Report On Issue Tracker Including The Instructions To Reproduce
### ``[ERR]: Invalid ~/.minecraft-pi Permissions``
Run:
```sh
sudo chown -R "$(id -u):$(id -g)" ~/.minecraft-pi
chmod -R u+rw ~/.minecraft-pi
```
## Dedicated Server ## Dedicated Server
The dedicated server is a version of Minecraft: Pi Edition modified to run in a headless environment. It loads settings from a ``server.properties`` file. The dedicated server is a version of Minecraft: Pi Edition modified to run in a headless environment. It loads settings from a ``server.properties`` file.

5
debian/client/common/DEBIAN/postrm vendored Executable file
View File

@ -0,0 +1,5 @@
#!/bin/sh
set -e
docker image rm thebrokenrail/minecraft-pi-reborn:client

View File

@ -13,7 +13,7 @@ fi
# Export Important Variables # Export Important Variables
export ZENITY_CLASS='Minecraft - Pi edition' export ZENITY_CLASS='Minecraft - Pi edition'
export DOCKER_COMPOSE="docker-compose -f /usr/share/minecraft-pi/client/docker-compose.yml" export DOCKER_COMPOSE_YML="/usr/share/minecraft-pi/client/docker-compose.yml"
# Ensure Features Are Selected # Ensure Features Are Selected
if [ -z "${MCPI_FEATURES+x}" ]; then if [ -z "${MCPI_FEATURES+x}" ]; then
@ -25,13 +25,21 @@ fi
export MCPI_FEATURES export MCPI_FEATURES
export MCPI_USERNAME export MCPI_USERNAME
# Ensure Groups Are Correct
if ! id -Gn "$(whoami)" | grep '\bdocker\b' > /dev/null; then
pkexec /sbin/usermod -aG docker "$(whoami)"
fi
# Allow X11 Connections From Root # Allow X11 Connections From Root
xhost local:root xhost local:root
# Prepare Environment
export USER_HOME="${HOME}"
export USER_UID="$(id -u)"
# Run # Run
sg docker /usr/lib/minecraft-pi/pre-launch.sh set +e
/usr/lib/minecraft-pi/pre-launch.sh
RET=$?
set -e
# Handle Crash
if [ ${RET} -ne 0 ]; then
zenity --class "${ZENITY_CLASS}" --error --no-wrap --text 'Minecraft: Pi Edition has crashed!\n\nExit Code: '${RET}'\n\n<a href="file:///tmp/minecraft-pi">Open Log Folder</a>\n<a href="https://gitea.thebrokenrail.com/TheBrokenRail/minecraft-pi-reborn#troubleshooting">Open Troubleshooting Guide</a>'
exit ${RET}
fi

View File

@ -2,6 +2,9 @@
set -e set -e
# Prepare Data Folder
mkdir -p "${USER_HOME}/.minecraft-pi"
# Create Log Folder # Create Log Folder
rm -rf /tmp/minecraft-pi rm -rf /tmp/minecraft-pi
mkdir -p /tmp/minecraft-pi mkdir -p /tmp/minecraft-pi
@ -20,8 +23,5 @@ set -e
# Kill Logging # Kill Logging
kill ${TAIL_PID} kill ${TAIL_PID}
# Handle Crash # Exit
if [ ${RET} -ne 0 ]; then exit ${RET}
zenity --class "${ZENITY_CLASS}" --error --no-wrap --text 'Minecraft: Pi Edition has crashed!\nLogs are located in /tmp/minecraft-pi.\n\nExit Code: '${RET}
exit ${RET}
fi

View File

@ -3,4 +3,4 @@
set -e set -e
# Launch Minecraft # Launch Minecraft
${DOCKER_COMPOSE} run --rm minecraft-pi docker-compose -f "${DOCKER_COMPOSE_YML}" run --rm minecraft-pi

View File

@ -3,13 +3,15 @@ services:
minecraft-pi: minecraft-pi:
image: 'thebrokenrail/minecraft-pi-reborn:client' image: 'thebrokenrail/minecraft-pi-reborn:client'
network_mode: 'host' network_mode: 'host'
user: '${USER_UID}'
volumes: volumes:
- /usr/bin/qemu-arm-static:/usr/bin/qemu-arm-static - /usr/bin/qemu-arm-static:/usr/bin/qemu-arm-static
- '/tmp/.X11-unix:/tmp/.X11-unix' - '/tmp/.X11-unix:/tmp/.X11-unix'
- '~/.minecraft-pi:/root/.minecraft' - '${USER_HOME}/.minecraft-pi:/root/.minecraft'
devices: devices:
- '/dev/dri:/dev/dri' - '/dev/dri:/dev/dri'
environment: environment:
- 'HOME=/root'
- 'DISPLAY=unix${DISPLAY}' - 'DISPLAY=unix${DISPLAY}'
- 'MCPI_FEATURES=${MCPI_FEATURES}' - 'MCPI_FEATURES=${MCPI_FEATURES}'
- 'MCPI_USERNAME=${MCPI_USERNAME}' - 'MCPI_USERNAME=${MCPI_USERNAME}'

View File

@ -8,7 +8,7 @@ VIRGL_PID=$!
# Launch Minecraft # Launch Minecraft
set +e set +e
${DOCKER_COMPOSE} run --rm minecraft-pi docker-compose -f "${DOCKER_COMPOSE_YML}" run --rm minecraft-pi
RET=$? RET=$?
set -e set -e

View File

@ -3,12 +3,14 @@ services:
minecraft-pi: minecraft-pi:
image: 'thebrokenrail/minecraft-pi-reborn:client' image: 'thebrokenrail/minecraft-pi-reborn:client'
network_mode: 'host' network_mode: 'host'
user: '${USER_UID}'
volumes: volumes:
- /usr/bin/qemu-arm-static:/usr/bin/qemu-arm-static - /usr/bin/qemu-arm-static:/usr/bin/qemu-arm-static
- '/tmp/.X11-unix:/tmp/.X11-unix' - '/tmp/.X11-unix:/tmp/.X11-unix'
- '/tmp/.virgl_test:/tmp/.virgl_test' - '/tmp/.virgl_test:/tmp/.virgl_test'
- '~/.minecraft-pi:/root/.minecraft' - '${USER_HOME}/.minecraft-pi:/home/.minecraft'
environment: environment:
- 'HOME=/home'
- 'DISPLAY=unix${DISPLAY}' - 'DISPLAY=unix${DISPLAY}'
- 'MCPI_FEATURES=${MCPI_FEATURES}' - 'MCPI_FEATURES=${MCPI_FEATURES}'
- 'MCPI_USERNAME=${MCPI_USERNAME}' - 'MCPI_USERNAME=${MCPI_USERNAME}'

View File

@ -2,8 +2,10 @@
set -e set -e
# Prepare Environment
export MCPI_ROOT="${PWD}" export MCPI_ROOT="${PWD}"
export USER_UID="${UID}"
# Launch Minecraft # Launch Minecraft
DOCKER_COMPOSE="docker-compose -f /usr/share/minecraft-pi/server/docker-compose.yml" DOCKER_COMPOSE_YML='/usr/share/minecraft-pi/server/docker-compose.yml'
${DOCKER_COMPOSE} run --rm minecraft-pi-server docker-compose -f "${DOCKER_COMPOSE_YML}" run --rm minecraft-pi-server

View File

@ -3,6 +3,9 @@ services:
minecraft-pi-server: minecraft-pi-server:
image: 'thebrokenrail/minecraft-pi-reborn:server' image: 'thebrokenrail/minecraft-pi-reborn:server'
network_mode: 'host' network_mode: 'host'
user: '${USER_UID}'
volumes: volumes:
- /usr/bin/qemu-arm-static:/usr/bin/qemu-arm-static - /usr/bin/qemu-arm-static:/usr/bin/qemu-arm-static
- '${MCPI_ROOT}:/root/.minecraft' - '${MCPI_ROOT}:/home/.minecraft'
environment:
- 'HOME=/home'

View File

@ -1,3 +1,5 @@
#define _GNU_SOURCE
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
@ -23,20 +25,35 @@ struct timespec32 {
void run_tests() { void run_tests() {
// Test clock_gettime64 // Test clock_gettime64
struct timespec64 ts64; {
long out = syscall(SYS_clock_gettime64, CLOCK_MONOTONIC, &ts64); struct timespec64 ts64;
if (out != 0) { long out = syscall(SYS_clock_gettime64, CLOCK_MONOTONIC, &ts64);
if (errno == ENOSYS) { if (out != 0) {
// clock_gettime64 Unsupported, Testing clock_gettime if (errno == ENOSYS) {
struct timespec32 ts32; // clock_gettime64 Unsupported, Testing clock_gettime
out = syscall(SYS_clock_gettime, CLOCK_MONOTONIC, &ts32); struct timespec32 ts32;
if (out != 0) { out = syscall(SYS_clock_gettime, CLOCK_MONOTONIC, &ts32);
if (out != 0) {
// Failure
ERR("Unable To Run clock_gettime Syscall: %s", strerror(errno));
}
} else {
// Failure // Failure
ERR("Unable To Run clock_gettime Syscall: %s", strerror(errno)); ERR("Unable To Run clock_gettime64 Syscall: %s", strerror(errno));
} }
} else { }
}
// Test ~/.minecraft Permissions
{
char *path = NULL;
asprintf(&path, "%s/.minecraft", getenv("HOME"));
int ret = access(path, R_OK | W_OK);
free(path);
if (ret != 0) {
// Failure // Failure
ERR("Unable To Run clock_gettime64 Syscall: %s", strerror(errno)); ERR("%s", "Invalid ~/.minecraft-pi Permissions");
} }
} }
} }

View File

@ -6,7 +6,7 @@ DEB_VERSION='1.0.0'
# Dependencies # Dependencies
REQUIRED_DOCKER_VERSION='19.03' REQUIRED_DOCKER_VERSION='19.03'
COMMON_DEPENDENCIES="docker.io (>=${REQUIRED_DOCKER_VERSION}) | docker-ce (>=${REQUIRED_DOCKER_VERSION}), libseccomp2 (>=2.4.2), docker-compose, binfmt-support" COMMON_DEPENDENCIES="docker.io (>=${REQUIRED_DOCKER_VERSION}) | docker-ce (>=${REQUIRED_DOCKER_VERSION}), libseccomp2 (>=2.4.2), docker-compose, binfmt-support"
CLIENT_DEPENDENCIES="zenity, policykit-1, passwd, login, x11-xserver-utils" CLIENT_DEPENDENCIES="zenity, x11-xserver-utils"
RECOMMENDED_DEPENDENCIES="qemu-user-static" RECOMMENDED_DEPENDENCIES="qemu-user-static"
set -e set -e
@ -40,7 +40,7 @@ package_client() {
cp debian/tmp/client-image.tar.gz "debian/tmp/$1/usr/share/minecraft-pi/client/image.tar.gz" cp debian/tmp/client-image.tar.gz "debian/tmp/$1/usr/share/minecraft-pi/client/image.tar.gz"
prepare_control "debian/tmp/$1" ", ${CLIENT_DEPENDENCIES}" prepare_control "debian/tmp/$1" ", ${CLIENT_DEPENDENCIES}"
# Build # Build
dpkg -b "debian/tmp/$1" out/deb dpkg-deb -b --root-owner-group "debian/tmp/$1" out/deb
} }
package_client virgl package_client virgl
package_client native package_client native
@ -55,7 +55,7 @@ package_server() {
cp debian/tmp/server-image.tar.gz debian/tmp/server/usr/share/minecraft-pi/server/image.tar.gz cp debian/tmp/server-image.tar.gz debian/tmp/server/usr/share/minecraft-pi/server/image.tar.gz
prepare_control debian/tmp/server '' prepare_control debian/tmp/server ''
# Build # Build
dpkg -b debian/tmp/server out/deb dpkg-deb -b --root-owner-group debian/tmp/server out/deb
} }
package_server package_server