From b0c1b0749935d4b27e557cda84da9f66e2d6e11d Mon Sep 17 00:00:00 2001 From: Jeremy McClure Date: Wed, 18 Jun 2025 07:52:11 -0400 Subject: [PATCH] Loader version option --- compose.yaml | 15 ++++++--- scripts/init | 89 +++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 81 insertions(+), 23 deletions(-) diff --git a/compose.yaml b/compose.yaml index b1ac483..bffc82c 100644 --- a/compose.yaml +++ b/compose.yaml @@ -5,12 +5,19 @@ services: stdin_open: true tty: true environment: - - MC_LOADER=paper # paper, fabric or forge - - MC_VERSION=1.21.4 + - MC_VERSION=1.20.1 + + - MC_LOADER=fabric # paper, fabric or forge + - MC_LOADER_VERSION=0.16.14 # build number or blank for latest + - JAVA_VERSION=temurin@21 - JAR=server.jar - - MEMORY=2G + + - MEMORY=4G - ADD_ARGS= + + - PUID=1000 + - PGID=1000 build: dockerfile: Dockerfile context: . @@ -21,5 +28,5 @@ services: deploy: resources: limits: - memory: 2G + memory: 4G restart: unless-stopped diff --git a/scripts/init b/scripts/init index a247a58..6f7e695 100644 --- a/scripts/init +++ b/scripts/init @@ -1,11 +1,16 @@ #!/bin/env bash +MC_VERSION=${MC_VERSION} + +MC_LOADER=${MC_LOADER=} +MC_LOADER_VERSION=${MC_LOADER_VERSION} + JAVA_VERSION=${JAVA_VERSION:-"temurin@21"} JAVA_HOME=/data/java/${JAVA_VERSION} +JAR=${JAR:-"server.jar"} -JAR=server.jar -ADD_ARGS=${ADD_ARGS:-""} MEM=${MEMORY:-2G} +ADD_ARGS=${ADD_ARGS:-""} PUID="${PUID:-1000}" PGID="${PGID:-1000}" @@ -36,8 +41,10 @@ crash() { # Set Eula setEula() { - echo "#By changing the setting below to TRUE you are indicating your agreement to our EULA (https://aka.ms/MinecraftEULA)." >eula.txt - echo "eula=true" >>eula.txt + cat < eula.txt +#By changing the setting below to TRUE you are indicating your agreement to our EULA (https://aka.ms/MinecraftEULA). +eula=true +EOF } # Check for Java, and install if neccesary @@ -66,20 +73,22 @@ javaCheck() { # Paper Server getPaper() { SERVER_TYPE="Paper Minecraft" - LATEST_BUILD=$(curl -s https://api.papermc.io/v2/projects/${MC_LOADER}/versions/${MC_VERSION}/builds | - jq -r '.builds | map(select(.channel == "default") | .build) | .[-1]') + if [[ ! -f server.jar ]]; then + LATEST_BUILD=$(curl -s https://api.papermc.io/v2/projects/${MC_LOADER}/versions/${MC_VERSION}/builds | + jq -r '.builds | map(select(.channel == "default") | .build) | .[-1]') - if [ "$LATEST_BUILD" != "null" ]; then - JAR_NAME=${MC_LOADER}-${MC_VERSION}-${LATEST_BUILD}.jar - PAPERMC_URL="https://api.papermc.io/v2/projects/${MC_LOADER}/versions/${MC_VERSION}/builds/${LATEST_BUILD}/downloads/${JAR_NAME}" + if [ "$LATEST_BUILD" != "null" ]; then + JAR_NAME=${MC_LOADER}-${MC_VERSION}-${LATEST_BUILD}.jar + PAPERMC_URL="https://api.papermc.io/v2/projects/${MC_LOADER}/versions/${MC_VERSION}/builds/${LATEST_BUILD}/downloads/${JAR_NAME}" - # Download the latest Paper version - curl -o server.jar $PAPERMC_URL - echo "Download completed" - echo "Minecraft Version: ${MC_VERSION}" - echo "Paper Version: ${LATEST_BUILD}" - else - echo "No stable build for version $MC_VERSION found :(" + # Download the latest Paper version + curl -o server.jar $PAPERMC_URL + echo "Download completed" + echo "Minecraft Version: ${MC_VERSION}" + echo "Paper Version: ${LATEST_BUILD}" + else + echo "No stable build for version $MC_VERSION found :(" + fi fi } @@ -88,7 +97,20 @@ getFabric() { SERVER_TYPE="Fabric Minecraft" LATEST_BUILD=$(curl -s https://meta.fabricmc.net/v2/versions/loader/${MC_VERSION} | jq -s '.[] .[0] .loader .version' | tr -d '"') LATEST_INSTALLER=$(curl -s https://maven.fabricmc.net/net/fabricmc/fabric-installer/maven-metadata.xml | xmllint --xpath "/metadata/versioning/latest/text()" -) - DL_URL=https://meta.fabricmc.net/v2/versions/loader/${MC_VERSION}/${LATEST_BUILD}/${LATEST_INSTALLER}/server/jar + + if [ "$MC_VERSION" != "null" ]; then + VER=$MC_VERSION + else + echo "Minecraft version not set" + exit 1 + fi + + if [ "$MC_LOADER_VERSION" == "null" ]; then + DL_URL=https://meta.fabricmc.net/v2/versions/loader/${MC_VERSION}/${LATEST_BUILD}/${LATEST_INSTALLER}/server/jar + else + DL_URL=https://meta.fabricmc.net/v2/versions/loader/${MC_VERSION}/${MC_LOADER_VERSION}/${LATEST_INSTALLER}/server/jar + fi + if [ "$LATEST_BUILD" != "null" ]; then echo "$DL_URL" curl -o server.jar ${DL_URL} @@ -165,23 +187,52 @@ buildCommand setEula +serverInfoWrite() { + cat < server.info +MC_VERSION=$MC_VERSION + +MC_LOADER=$MC_LOADER +MC_LOADER_VERSION=$MC_LOADER_VERSION + +JAVA_VERSION=$JAVA_VERSION +JAR=$JAR + +MEMORY=$MEM +ADD_ARGS=$ADD_ARGS + +PUID=$PUID +PGID=$PGID +EOF +} + ## ----------------- SEND IT ----------------- ## while true; do cd /data/server + if [[ ! -f "server.properties" ]]; then touch "server.properties"; fi if [[ -f $JAR ]]; then echo -e "|_______________________________________________________|" echo -e "|##----------------- Server Starting -----------------##|" - echo -e "|#| Server Type: $SERVER_TYPE" + echo -e "|#| Minecraft Version: $MC_VERSION" + echo -e "|#| " + echo -e "|#| Loader Type: ${SERVER_TYPE:-$MC_LOADER}" + echo -e "|#| Loader Version: $MC_LOADER_VERSION" + echo -e "|#| " echo -e "|#| Java Version: $JAVA_VERSION" - echo -e "|#| Additional Arg: $ADD_ARGS" + echo -e "|#| Jar: $JAR" + echo -e "|#| Memory Allocated: $MEM" + echo -e "|#| Additional Args: $ADD_ARGS" + echo -e "|#| " echo -e "|#| Running as:" echo -e "|#| User: $PUID" echo -e "|#| Group: $PGID" + echo -e "|#| " echo -e "|#| Run Command:" echo -e "|#| java $RUN_STRING" echo -e "|##---------------------------------------------------##|" echo -e "|-------------------------------------------------------|" + echo -e " " + serverInfoWrite exec java $RUN_STRING else echo "Server Not Found."