From 9198fff5b3563d2e99c9f8972fee5ecc2b04982d Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Thu, 1 Oct 2020 15:11:27 -0400 Subject: [PATCH] Fix Startup Script --- debian/DEBIAN/control | 2 +- debian/usr/bin/minecraft-pi | 29 ++++++++++++++----- .../usr/share/minecraft-pi/docker-compose.yml | 2 +- mods/src/extra.c | 2 +- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/debian/DEBIAN/control b/debian/DEBIAN/control index 8b4cbdb71..31945b06a 100644 --- a/debian/DEBIAN/control +++ b/debian/DEBIAN/control @@ -4,4 +4,4 @@ Maintainer: TheBrokenRail Description: Fun with Blocks Homepage: https://www.minecraft.net/en-us/edition/pi Architecture: amd64 -Depends: docker.io, docker-compose, virgl-server, zenity, policykit-1 +Depends: docker.io, docker-compose, virgl-server, zenity, policykit-1, adduser diff --git a/debian/usr/bin/minecraft-pi b/debian/usr/bin/minecraft-pi index 6f946cbc0..0dcf8ca32 100755 --- a/debian/usr/bin/minecraft-pi +++ b/debian/usr/bin/minecraft-pi @@ -2,21 +2,36 @@ set -e -FEATURES="$(zenity --class minecraft-pi --list --checklist --column 'Enabled' --column 'Feature' FALSE 'Touch GUI' FALSE 'Survival Mode' FALSE 'Fix Bow & Arrow' FALSE 'Fix Attacking' FALSE 'Mob Spawning')" -export FEATURES +# Ensure Features Are Selected +USER_LAUNCH=1 +if [ -z "${MCPI_FEATURES}" ]; then + MCPI_FEATURES="$(zenity --class minecraft-pi --list --checklist --column 'Enabled' --column 'Feature' FALSE 'Touch GUI' FALSE 'Survival Mode' FALSE 'Fix Bow & Arrow' FALSE 'Fix Attacking' FALSE 'Mob Spawning')" +else + USER_LAUNCH=0 +fi +export MCPI_FEATURES +# Start VirGL virgl_test_server & -PID="$!" +VIRGL_PID="$!" -if ! id -Gn "$(whoami)" | grep '\bdocker\b' > /dev/null; then - pkexec adduser "$(whoami)" docker +# Ensure Groups Are Correct +if [ "${USER_LAUNCH}" = "1" ]; then + if ! id -Gn "$(whoami)" | grep '\bdocker\b' > /dev/null; then + pkexec adduser "$(whoami)" docker + fi + + su -p "$(whoami)" "$(realpath -e "$0")" + exit "$?" fi +# Allow X11 Connections From Root xhost local:root +# Launch Minecraft DOCKER_COMPOSE="docker-compose -f /usr/share/minecraft-pi/docker-compose.yml" - ${DOCKER_COMPOSE} up ${DOCKER_COMPOSE} down -kill "${PID}" +# Kill VirGL +kill "${VIRGL_PID}" diff --git a/debian/usr/share/minecraft-pi/docker-compose.yml b/debian/usr/share/minecraft-pi/docker-compose.yml index 53ee669d7..f51e6534c 100644 --- a/debian/usr/share/minecraft-pi/docker-compose.yml +++ b/debian/usr/share/minecraft-pi/docker-compose.yml @@ -9,4 +9,4 @@ services: - '~/.minecraft-pi:/root/.minecraft' environment: - 'DISPLAY=unix${DISPLAY}' - - 'FEATURES=${FEATURES}' + - 'MCPI_FEATURES=${MCPI_FEATURES}' diff --git a/mods/src/extra.c b/mods/src/extra.c index 56ca25b6d..a116dc635 100644 --- a/mods/src/extra.c +++ b/mods/src/extra.c @@ -68,7 +68,7 @@ static void handleClick_injection(unsigned char *this, unsigned char *param_2, u } static int has_feature(const char *name) { - char *env = getenv("FEATURES"); + char *env = getenv("MCPI_FEATURES"); char *features = strdup(env != NULL ? env : ""); char *tok = strtok(features, "|"); int ret = 0;