diff --git a/.gitignore b/.gitignore index 8895e24..e94549f 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ /core/build /mods/build /out +/debian/tmp diff --git a/debian/client/DEBIAN/postinst b/debian/client/DEBIAN/postinst deleted file mode 100755 index 7d4c2c6..0000000 --- a/debian/client/DEBIAN/postinst +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -set -e - -MCPI_FEATURES='' MCPI_USERNAME='' docker-compose -f /usr/share/minecraft-pi/client/docker-compose.yml pull diff --git a/debian/client/common/DEBIAN/postinst b/debian/client/common/DEBIAN/postinst new file mode 100755 index 0000000..9e61529 --- /dev/null +++ b/debian/client/common/DEBIAN/postinst @@ -0,0 +1,5 @@ +#!/bin/sh + +set -e + +MCPI_MODE='' MCPI_FEATURES='' MCPI_USERNAME='' docker-compose -f /usr/share/minecraft-pi/client/docker-compose.yml pull diff --git a/debian/client/usr/bin/minecraft-pi b/debian/client/common/usr/bin/minecraft-pi similarity index 80% rename from debian/client/usr/bin/minecraft-pi rename to debian/client/common/usr/bin/minecraft-pi index 47c33a9..faa768c 100755 --- a/debian/client/usr/bin/minecraft-pi +++ b/debian/client/common/usr/bin/minecraft-pi @@ -10,10 +10,6 @@ fi export MCPI_FEATURES export MCPI_USERNAME -# Start VirGL -virgl_test_server & -VIRGL_PID="$!" - # Ensure Groups Are Correct if [ -z "${MCPI_SUBSHELL}" ]; then if ! id -Gn "$(whoami)" | grep '\bdocker\b' > /dev/null; then @@ -25,13 +21,9 @@ fi # Allow X11 Connections From Root xhost local:root -# Launch Minecraft -DOCKER_COMPOSE="docker-compose -f /usr/share/minecraft-pi/client/docker-compose.yml" +# Update Docker Container +export DOCKER_COMPOSE="docker-compose -f /usr/share/minecraft-pi/client/docker-compose.yml" (${DOCKER_COMPOSE} pull || :) | zenity --class 'Minecraft - Pi edition' --progress --pulsate --no-cancel --auto-close --text 'Updating Minecraft...' -${DOCKER_COMPOSE} run --rm minecraft-pi || : -RET="$?" -# Kill VirGL -kill "${VIRGL_PID}" - -exit "${RET}" +# Run +/usr/lib/minecraft-pi/run.sh diff --git a/debian/client/usr/share/applications/minecraft-pi.desktop b/debian/client/common/usr/share/applications/minecraft-pi.desktop similarity index 100% rename from debian/client/usr/share/applications/minecraft-pi.desktop rename to debian/client/common/usr/share/applications/minecraft-pi.desktop diff --git a/debian/client/usr/share/minecraft-pi/client/docker-compose.yml b/debian/client/common/usr/share/minecraft-pi/client/docker-compose.yml similarity index 91% rename from debian/client/usr/share/minecraft-pi/client/docker-compose.yml rename to debian/client/common/usr/share/minecraft-pi/client/docker-compose.yml index a4fb390..dea4c8b 100644 --- a/debian/client/usr/share/minecraft-pi/client/docker-compose.yml +++ b/debian/client/common/usr/share/minecraft-pi/client/docker-compose.yml @@ -11,3 +11,4 @@ services: - 'DISPLAY=unix${DISPLAY}' - 'MCPI_FEATURES=${MCPI_FEATURES}' - 'MCPI_USERNAME=${MCPI_USERNAME}' + - 'MCPI_MODE=${MCPI_MODE}' diff --git a/debian/client/usr/share/pixmaps/minecraft-pi.png b/debian/client/common/usr/share/pixmaps/minecraft-pi.png similarity index 100% rename from debian/client/usr/share/pixmaps/minecraft-pi.png rename to debian/client/common/usr/share/pixmaps/minecraft-pi.png diff --git a/debian/client/native/DEBIAN/control b/debian/client/native/DEBIAN/control new file mode 100644 index 0000000..d5e8774 --- /dev/null +++ b/debian/client/native/DEBIAN/control @@ -0,0 +1,8 @@ +Package: minecraft-pi-native +Version: 1.0.0 +Maintainer: TheBrokenRail +Description: Fun with Blocks +Homepage: https://www.minecraft.net/en-us/edition/pi +Architecture: all +Depends: docker.io, docker-compose, zenity, policykit-1, passwd, login, qemu-user-static, binfmt-support +Conflicts: minecraft-pi-virgl diff --git a/debian/client/native/usr/lib/minecraft-pi/run.sh b/debian/client/native/usr/lib/minecraft-pi/run.sh new file mode 100644 index 0000000..84375ea --- /dev/null +++ b/debian/client/native/usr/lib/minecraft-pi/run.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +set -e + +# Enable VirGL +export MCPI_MODE=native + +# Launch Minecraft +${DOCKER_COMPOSE} run --rm minecraft-pi \ No newline at end of file diff --git a/debian/client/DEBIAN/control b/debian/client/virgl/DEBIAN/control similarity index 82% rename from debian/client/DEBIAN/control rename to debian/client/virgl/DEBIAN/control index 56331a7..7db2872 100644 --- a/debian/client/DEBIAN/control +++ b/debian/client/virgl/DEBIAN/control @@ -1,7 +1,8 @@ -Package: minecraft-pi +Package: minecraft-pi-virgl Version: 1.0.0 Maintainer: TheBrokenRail Description: Fun with Blocks Homepage: https://www.minecraft.net/en-us/edition/pi Architecture: all Depends: docker.io, docker-compose, virgl-server, zenity, policykit-1, passwd, login, qemu-user-static, binfmt-support +Conflicts: minecraft-pi-native diff --git a/debian/client/virgl/usr/lib/minecraft-pi/run.sh b/debian/client/virgl/usr/lib/minecraft-pi/run.sh new file mode 100644 index 0000000..e800768 --- /dev/null +++ b/debian/client/virgl/usr/lib/minecraft-pi/run.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +set -e + +# Enable VirGL +export MCPI_MODE=virgl + +# Start VirGL +virgl_test_server & +VIRGL_PID="$!" + +# Launch Minecraft +${DOCKER_COMPOSE} run --rm minecraft-pi || : +RET="$?" + +# Kill VirGL +kill "${VIRGL_PID}" + +exit "${RET}" \ No newline at end of file diff --git a/mods/src/compat.c b/mods/src/compat.c index 0b5ad6f..fd8b0d3 100644 --- a/mods/src/compat.c +++ b/mods/src/compat.c @@ -41,7 +41,7 @@ static void store_x11_window() { // Handle GLFW Error static void glfw_error(__attribute__((unused)) int error, const char *description) { - fprintf(stderr, "GLFW Error: %s\n", description); + fprintf(stderr, "[ERR] GLFW Error: %s\n", description); exit(1); } @@ -465,9 +465,12 @@ HOOK(eglTerminate, EGLBoolean, (__attribute__((unused)) EGLDisplay display)) { // Use VirGL __attribute__((constructor)) static void init() { - is_server = extra_get_is_server(); - setenv("LIBGL_ALWAYS_SOFTWARE", "1", 1); - if (!is_server) { - setenv("GALLIUM_DRIVER", "virpipe", 1); + int mode = extra_get_mode(); + if (mode == 0) { + setenv("LIBGL_ALWAYS_SOFTWARE", "1", 1); + if (!is_server) { + setenv("GALLIUM_DRIVER", "virpipe", 1); + } } + is_server = mode == 2; } diff --git a/mods/src/extra.c b/mods/src/extra.c index 3f37a8a..64436e4 100644 --- a/mods/src/extra.c +++ b/mods/src/extra.c @@ -154,12 +154,22 @@ int extra_has_feature(const char *name) { } } -int extra_get_is_server() { - return getenv("MCPI_SERVER") != NULL; +int extra_get_mode() { + char *mode = getenv("MCPI_MODE"); + if (strcmp("virgl", mode) == 0) { + return 0; + } else if (strcmp("native", mode) == 0) { + return 1; + } else if (strcmp("server", mode) == 0) { + return 2; + } else { + fprintf(stderr, "[ERR] Inavlid MCPI_MODE: %s\n", mode); + exit(1); + } } __attribute__((constructor)) static void init() { - is_server = extra_get_is_server(); + is_server = extra_get_mode() == 2; if (is_server) { server_init(); } diff --git a/mods/src/extra.h b/mods/src/extra.h index 21fc2cb..146e0e8 100644 --- a/mods/src/extra.h +++ b/mods/src/extra.h @@ -7,7 +7,7 @@ extern "C" { #endif int extra_has_feature(const char *name); -int extra_get_is_server(); +int extra_get_mode(); void extra_key_press(char key); void extra_clear_input(); diff --git a/scripts/build.sh b/scripts/build.sh index ea8b76c..8de51a7 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -3,4 +3,4 @@ set -e docker build ${DOCKER_BUILD_OPTIONS} --tag thebrokenrail/minecraft-pi:client -f Dockerfile.client . -docker build ${DOCKER_BUILD_OPTIONS} --tag thebrokenrail/minecraft-pi:server -f Dockerfile.server . +#docker build ${DOCKER_BUILD_OPTIONS} --tag thebrokenrail/minecraft-pi:server -f Dockerfile.server . diff --git a/scripts/package.sh b/scripts/package.sh index 653c642..8f0503d 100755 --- a/scripts/package.sh +++ b/scripts/package.sh @@ -9,8 +9,18 @@ chmod -R g-s debian rm -rf out mkdir -p out/deb -# Generate DEB -dpkg -b debian/client out/deb +# Package Client DEBs +package_client() { + rm -rf debian/tmp + rsync -r debian/client/common/ debian/tmp + rsync -r "debian/client/$1/" debian/tmp + dpkg -b debian/tmp out/deb + rm -rf debian/tmp +} +package_client virgl +package_client native + +# Package Server DEB dpkg -b debian/server out/deb # Export Libraries