From c68aca4a12b75bb80aa3ebd005e0cb0abb20aab7 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Sun, 10 Nov 2024 13:00:23 +0100 Subject: [PATCH] Add scripts for installing Minecraft --- .../services/minecraft/docker-compose.yml | 32 ++++++++ .../docker/services/minecraft/main.fish | 74 +++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 scripts/Common/Software/docker/services/minecraft/docker-compose.yml create mode 100644 scripts/Common/Software/docker/services/minecraft/main.fish diff --git a/scripts/Common/Software/docker/services/minecraft/docker-compose.yml b/scripts/Common/Software/docker/services/minecraft/docker-compose.yml new file mode 100644 index 00000000..f5a95b37 --- /dev/null +++ b/scripts/Common/Software/docker/services/minecraft/docker-compose.yml @@ -0,0 +1,32 @@ +services: + legacy: + image: itzg/minecraft-server + restart: unless-stopped + environment: + UID: 1337 + GID: 1337 + EULA: "TRUE" + ports: + - 25565:25565 + volumes: + - /etc/localtime:/etc/localtime:ro + - ./mods:/mods + - ./config/legacy:/config + - ./data/legacy:/data + - ./worlds/legacy:/data/worlds + - ./legacy.properties:/data/server.properties + bedrock: + image: itzg/minecraft-bedrock-server + restart: unless-stopped + environment: + UID: 1337 + GID: 1337 + EULA: "TRUE" + ports: + - 19132:19132/udp + - 19133:19133/udp + volumes: + - /etc/localtime:/etc/localtime:ro + - ./data/bedrock:/data + - ./worlds/bedrock:/data/worlds + - ./bedrock.properties:/data/server.properties diff --git a/scripts/Common/Software/docker/services/minecraft/main.fish b/scripts/Common/Software/docker/services/minecraft/main.fish new file mode 100644 index 00000000..1690ee9e --- /dev/null +++ b/scripts/Common/Software/docker/services/minecraft/main.fish @@ -0,0 +1,74 @@ +#!/bin/env fish +begin + set -l dir (status dirname) + set -l user "minecraft" + source "$dir/../service.fish" + + function installSW -V dir -V domain -V server -V service + initializeServiceInstallation $argv + sudo cp "$dir/docker-compose.yml" (getServiceRoot $argv) + installDockerService $argv + end + + function configureSW -V dir -V user -V service + set -l uid + set -l gid + set -l file (mktemp) + set -l root (getServiceRoot $argv) + set -l dirs "$root"/{mods,{data,config,worlds}/{legacy,bedrock}} + set -l files "$root"/{legacy,bedrock}.properties + set -l config "$root/docker-compose.yml" + configureDockerService $argv + + and sudo useradd \ + --system \ + --shell /bin/false \ + --comment 'Minecraft server' \ + --groups docker \ + $user + + set uid (id -u $user) + set gid (id -g $user) + + for service in (yq --raw-output0 ".services | keys[]" "$config" | string split0) + set -l envKey "$(getServiceKey "$service").environment" + cp "$config" "$file" + + and yq "$envKey.UID = $uid" "$file" | \ + yq "$envKey.GID = $gid" | \ + yq -y . | \ + sudo tee "$config" >/dev/null + end + + and for dir in $dirs + sudo mkdir -p "$dir" + end + + and begin + set -l file + + for file in $files + sudo mkdir -p (dirname "$file") + sudo touch "$file" + end + end + + and for item in $dirs $files + sudo chown -R $uid:$gid "$item" + end + + rm "$file" + end + + function getServiceServers -V server + end + + function getServiceLocations + end + + function getBackupArgs + printf "%s\n" --hidden --no-ignore "config|data|mods|worlds|\.properties\$" --exclude "docker-compose.yml" (getServiceRoot $argv) + end + + runInstaller --force $argv +end