Improve Launch
This commit is contained in:
parent
e7d0d66e54
commit
4d8c8ae3c1
@ -5,7 +5,7 @@ ENV DEBIAN_FRONTEND noninteractive
|
|||||||
RUN \
|
RUN \
|
||||||
# Install Runtime Dependencies
|
# Install Runtime Dependencies
|
||||||
apt-get update && \
|
apt-get update && \
|
||||||
apt-get install -y --no-install-recommends tini libgles1 libx11-6 libsdl1.2debian zlib1g libfreeimage3 libglfw3 xinput libxfixes3 && \
|
apt-get install -y --no-install-recommends tini libgles1 libx11-6 libsdl1.2debian zlib1g libfreeimage3 libglfw3 xinput libxfixes3 gosu && \
|
||||||
rm -rf /var/lib/apt/lists/*
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# Compile Environment
|
# Compile Environment
|
||||||
@ -51,4 +51,4 @@ COPY --from=build /app/minecraft-pi /app/minecraft-pi
|
|||||||
WORKDIR /app/minecraft-pi
|
WORKDIR /app/minecraft-pi
|
||||||
|
|
||||||
ENTRYPOINT ["/usr/bin/tini", "--"]
|
ENTRYPOINT ["/usr/bin/tini", "--"]
|
||||||
CMD ["./launcher"]
|
CMD ["./run.sh"]
|
||||||
|
7
debian/client/common/usr/bin/minecraft-pi
vendored
7
debian/client/common/usr/bin/minecraft-pi
vendored
@ -39,7 +39,12 @@ xhost local:root
|
|||||||
|
|
||||||
# Prepare Environment
|
# Prepare Environment
|
||||||
export USER_HOME="${HOME}"
|
export USER_HOME="${HOME}"
|
||||||
export USER_UID="$(id -u):$(getent group video | cut -d : -f 3)"
|
export USER_UID="$(id -u)"
|
||||||
|
export USER_GID="$(id -g)"
|
||||||
|
get_gid() {
|
||||||
|
echo "$(getent group "$1" | cut -d : -f 3)"
|
||||||
|
}
|
||||||
|
export USER_OTHER_GIDS="$(get_gid video) $(get_gid render)"
|
||||||
|
|
||||||
# Run
|
# Run
|
||||||
set +e
|
set +e
|
||||||
|
@ -3,7 +3,6 @@ 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'
|
||||||
@ -11,9 +10,11 @@ services:
|
|||||||
devices:
|
devices:
|
||||||
- '/dev/dri:/dev/dri'
|
- '/dev/dri:/dev/dri'
|
||||||
environment:
|
environment:
|
||||||
- 'HOME=/home'
|
|
||||||
- 'DISPLAY=unix${DISPLAY}'
|
- 'DISPLAY=unix${DISPLAY}'
|
||||||
- 'MCPI_FEATURES=${MCPI_FEATURES}'
|
- 'MCPI_FEATURES=${MCPI_FEATURES}'
|
||||||
- 'MCPI_RENDER_DISTANCE=${MCPI_RENDER_DISTANCE}'
|
- 'MCPI_RENDER_DISTANCE=${MCPI_RENDER_DISTANCE}'
|
||||||
- 'MCPI_USERNAME=${MCPI_USERNAME}'
|
- 'MCPI_USERNAME=${MCPI_USERNAME}'
|
||||||
- 'MCPI_MODE=native'
|
- 'MCPI_MODE=native'
|
||||||
|
- 'USER_UID=${USER_UID}'
|
||||||
|
- 'USER_GID=${USER_GID}'
|
||||||
|
- 'USER_OTHER_GIDS=${USER_OTHER_GIDS}'
|
||||||
|
@ -13,6 +13,6 @@ RET=$?
|
|||||||
set -e
|
set -e
|
||||||
|
|
||||||
# Kill VirGL
|
# Kill VirGL
|
||||||
kill ${VIRGL_PID}
|
kill ${VIRGL_PID} > /dev/null 2>&1
|
||||||
|
|
||||||
exit ${RET}
|
exit ${RET}
|
@ -3,16 +3,17 @@ 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'
|
||||||
- '${USER_HOME}/.minecraft-pi:/home/.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_RENDER_DISTANCE=${MCPI_RENDER_DISTANCE}'
|
- 'MCPI_RENDER_DISTANCE=${MCPI_RENDER_DISTANCE}'
|
||||||
- 'MCPI_USERNAME=${MCPI_USERNAME}'
|
- 'MCPI_USERNAME=${MCPI_USERNAME}'
|
||||||
- 'MCPI_MODE=virgl'
|
- 'MCPI_MODE=virgl'
|
||||||
|
- 'USER_UID=${USER_UID}'
|
||||||
|
- 'USER_GID=${USER_GID}'
|
||||||
|
- 'USER_OTHER_GIDS=${USER_OTHER_GIDS}'
|
||||||
|
3
debian/server/usr/bin/minecraft-pi-server
vendored
3
debian/server/usr/bin/minecraft-pi-server
vendored
@ -4,7 +4,8 @@ set -e
|
|||||||
|
|
||||||
# Prepare Environment
|
# Prepare Environment
|
||||||
export MCPI_ROOT="${PWD}"
|
export MCPI_ROOT="${PWD}"
|
||||||
export USER_UID="${UID}"
|
export USER_UID="$(id -u)"
|
||||||
|
export USER_GID="$(id -g)"
|
||||||
|
|
||||||
# Launch Minecraft
|
# Launch Minecraft
|
||||||
DOCKER_COMPOSE_YML='/usr/share/minecraft-pi/server/docker-compose.yml'
|
DOCKER_COMPOSE_YML='/usr/share/minecraft-pi/server/docker-compose.yml'
|
||||||
|
@ -3,9 +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}:/home/.minecraft'
|
- '${MCPI_ROOT}:/home/.minecraft'
|
||||||
environment:
|
environment:
|
||||||
- 'HOME=/home'
|
- 'USER_UID=${USER_UID}'
|
||||||
|
- 'USER_GID=${USER_GID}'
|
||||||
|
@ -8,3 +8,4 @@ add_executable(launcher src/launcher.c)
|
|||||||
|
|
||||||
# Install
|
# Install
|
||||||
install(TARGETS launcher DESTINATION /)
|
install(TARGETS launcher DESTINATION /)
|
||||||
|
install(PROGRAMS src/run.sh DESTINATION /)
|
@ -7,6 +7,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
static int starts_with(const char *s, const char *t) {
|
static int starts_with(const char *s, const char *t) {
|
||||||
return strncmp(s, t, strlen(t)) == 0;
|
return strncmp(s, t, strlen(t)) == 0;
|
||||||
@ -71,7 +72,7 @@ static void load(char **ld_path, char **ld_preload, char *folder) {
|
|||||||
}
|
}
|
||||||
} else if (errno != 0) {
|
} else if (errno != 0) {
|
||||||
// Error Reading Contents Of Folder
|
// Error Reading Contents Of Folder
|
||||||
fprintf(stderr, "Error Reading Directory: %s\n", strerror(errno));
|
fprintf(stderr, "Error Reading Directory: %s: %s\n", folder, strerror(errno));
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
@ -85,15 +86,15 @@ static void load(char **ld_path, char **ld_preload, char *folder) {
|
|||||||
return;
|
return;
|
||||||
} else if (errno == ENOENT) {
|
} else if (errno == ENOENT) {
|
||||||
// Folder Doesn't Exists, Attempt Creation
|
// Folder Doesn't Exists, Attempt Creation
|
||||||
char *cmd = NULL;
|
int ret = mkdir(folder, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
|
||||||
asprintf(&cmd, "mkdir -p %s", folder);
|
|
||||||
int ret = system(cmd);
|
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
exit(ret);
|
// Unable To Create Folder
|
||||||
|
fprintf(stderr, "Error Creating Directory: %s: %s\n", folder, strerror(errno));
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Unable To Open Folder
|
// Unable To Open Folder
|
||||||
fprintf(stderr, "Error Opening Directory: %s\n", strerror(errno));
|
fprintf(stderr, "Error Opening Directory: %s: %s\n", folder, strerror(errno));
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -102,11 +103,23 @@ static void load(char **ld_path, char **ld_preload, char *folder) {
|
|||||||
int main(__attribute__((unused)) int argc, char *argv[]) {
|
int main(__attribute__((unused)) int argc, char *argv[]) {
|
||||||
fprintf(stderr, "Configuring Game...\n");
|
fprintf(stderr, "Configuring Game...\n");
|
||||||
|
|
||||||
// Create Screenshots Folder
|
// Minecraft Folder
|
||||||
char *screenshots_cmd = NULL;
|
char *minecraft_folder = NULL;
|
||||||
asprintf(&screenshots_cmd, "mkdir -p %s/.minecraft/screenshots", getenv("HOME"));
|
asprintf(&minecraft_folder, "%s/.minecraft", getenv("HOME"));
|
||||||
system(screenshots_cmd);
|
{
|
||||||
free(screenshots_cmd);
|
// Check Minecraft Folder
|
||||||
|
struct stat obj;
|
||||||
|
if (stat(minecraft_folder, &obj) != 0 || !S_ISDIR(obj.st_mode)) {
|
||||||
|
// Create Minecraft Folder
|
||||||
|
int ret = mkdir(minecraft_folder, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
|
||||||
|
if (ret != 0) {
|
||||||
|
// Unable To Create Folder
|
||||||
|
fprintf(stderr, "Error Creating Directory: %s: %s\n", minecraft_folder, strerror(errno));
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free(minecraft_folder);
|
||||||
|
|
||||||
char *ld_path = NULL;
|
char *ld_path = NULL;
|
||||||
|
|
||||||
|
32
launcher/src/run.sh
Executable file
32
launcher/src/run.sh
Executable file
@ -0,0 +1,32 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Check Root
|
||||||
|
if [ ! "$(id -u)" = '0' ]; then
|
||||||
|
echo 'Must Run As Root' 1>&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Create User Groups
|
||||||
|
if [ -z "${USER_GID+x}" ]; then
|
||||||
|
USER_GID='1000'
|
||||||
|
fi
|
||||||
|
groupadd --force --gid "${USER_GID}" user
|
||||||
|
|
||||||
|
# Create User
|
||||||
|
if [ -z "${USER_UID+x}" ]; then
|
||||||
|
USER_UID='1000'
|
||||||
|
fi
|
||||||
|
useradd --shell /bin/sh --home-dir /home --no-create-home --uid "${USER_UID}" --gid "${USER_GID}" user
|
||||||
|
|
||||||
|
# Add Other Groups
|
||||||
|
if [ ! -z "${USER_OTHER_GIDS+x}" ]; then
|
||||||
|
for gid in ${USER_OTHER_GIDS}; do
|
||||||
|
groupadd --force --gid "${gid}" "group-${gid}"
|
||||||
|
usermod -aG "${gid}" user
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Start
|
||||||
|
exec gosu "${USER_UID}" ./launcher
|
@ -4,6 +4,9 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include <FreeImage.h>
|
#include <FreeImage.h>
|
||||||
|
|
||||||
@ -13,7 +16,7 @@
|
|||||||
|
|
||||||
#include "screenshot.h"
|
#include "screenshot.h"
|
||||||
|
|
||||||
// 4 (Year + 1 (Hyphen) + 2 (Month) + 1 (Hyphen) + 2 (Day) + 1 (Underscore) + 2 (Hour) + 1 (Period) + 2 (Minute) + 1 (Period) + 2 (Second) + 1 (Terminator)
|
// 4 (Year) + 1 (Hyphen) + 2 (Month) + 1 (Hyphen) + 2 (Day) + 1 (Underscore) + 2 (Hour) + 1 (Period) + 2 (Minute) + 1 (Period) + 2 (Second) + 1 (Null Terminator)
|
||||||
#define TIME_SIZE 20
|
#define TIME_SIZE 20
|
||||||
|
|
||||||
// Take Screenshot
|
// Take Screenshot
|
||||||
@ -73,7 +76,25 @@ void take_screenshot() {
|
|||||||
free(screenshots);
|
free(screenshots);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init FreeImage
|
// Init
|
||||||
__attribute__((constructor)) static void init() {
|
__attribute__((constructor)) static void init() {
|
||||||
|
// Init FreeImage
|
||||||
FreeImage_Initialise(0);
|
FreeImage_Initialise(0);
|
||||||
|
|
||||||
|
// Screenshots Folder
|
||||||
|
char *screenshots_folder = NULL;
|
||||||
|
asprintf(&screenshots_folder, "%s/.minecraft/screenshots", getenv("HOME"));
|
||||||
|
{
|
||||||
|
// Check Screenshots Folder
|
||||||
|
struct stat obj;
|
||||||
|
if (stat(screenshots_folder, &obj) != 0 || !S_ISDIR(obj.st_mode)) {
|
||||||
|
// Create Screenshots Folder
|
||||||
|
int ret = mkdir(screenshots_folder, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
|
||||||
|
if (ret != 0) {
|
||||||
|
// Unable To Create Folder
|
||||||
|
ERR("Error Creating Directory: %s: %s", screenshots_folder, strerror(errno));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free(screenshots_folder);
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user