diff --git a/amd64.Dockerfile b/amd64.Dockerfile index 7b802d5..3900241 100644 --- a/amd64.Dockerfile +++ b/amd64.Dockerfile @@ -2,17 +2,32 @@ # Author: James A. Chambers - https://jamesachambers.com/minecraft-java-bedrock-server-together-geyser-floodgate/ # GitHub Repository: https://github.com/TheRemote/Legendary-Java-Minecraft-Geyser-Floodgate -# Use Ubuntu rolling version for builder -FROM ubuntu:rolling AS builder - -# Update apt -RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install qemu-user-static binfmt-support apt-utils -yqq && rm -rf /var/cache/apt/* - # Use Ubuntu rolling version FROM --platform=linux/amd64 ubuntu:rolling # Fetch dependencies -RUN apt update && DEBIAN_FRONTEND=noninteractive apt-get install openjdk-21-jre-headless tzdata sudo curl unzip net-tools gawk openssl findutils pigz libcurl4 libc6 libcrypt1 apt-utils libcurl4-openssl-dev ca-certificates binfmt-support nano -yqq && rm -rf /var/cache/apt/* +RUN apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get install -yqq \ + apt-utils \ + binfmt-support \ + ca-certificates \ + curl \ + gawk \ + findutils \ + jq \ + libcurl4 \ + libcurl4-openssl-dev \ + libc6 \ + libcrypt1 \ + net-tools \ + nano \ + openjdk-21-jre-headless \ + openssl \ + pigz \ + tzdata \ + unzip \ + vim && \ + rm -rf /var/cache/apt/* # Set port environment variable ENV Port=25565 @@ -21,7 +36,7 @@ ENV Port=25565 ENV BedrockPort=19132 # Optional maximum memory Minecraft is allowed to use -ENV MaxMemory= +ENV MaxMemory="" # Optional Paper Minecraft Version override ENV Version="1.21.3" @@ -49,12 +64,21 @@ EXPOSE 25565/tcp EXPOSE 19132/tcp EXPOSE 19132/udp -# Copy scripts to minecraftbe folder and make them executable +# Copy files into image and make the scripts executable RUN mkdir /scripts COPY *.sh /scripts/ COPY *.yml /scripts/ COPY server.properties /scripts/ RUN chmod -R +x /scripts/*.sh +# Create the minecraft user/group and set the container to run as the minecraft user +RUN groupadd -g 999 minecraft && \ + useradd -m -u 999 -g 999 -s /bin/bash minecraft && \ + mkdir /minecraft && \ + chown minecraft:minecraft /minecraft && \ + chmod 777 /minecraft +USER minecraft +WORKDIR /minecraft + # Set entrypoint to start.sh script ENTRYPOINT ["/bin/bash", "/scripts/start.sh"] diff --git a/arm64v8.Dockerfile b/arm64v8.Dockerfile index c5bffd5..fb2b79e 100644 --- a/arm64v8.Dockerfile +++ b/arm64v8.Dockerfile @@ -5,8 +5,10 @@ # Use Ubuntu rolling version for builder FROM ubuntu:rolling AS builder -# Update apt -RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install qemu-user-static binfmt-support apt-utils -yqq && rm -rf /var/cache/apt/* +# Prep qemu files +RUN apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get install -yqq apt-utils binfmt-support qemu-user-static && \ + rm -rf /var/cache/apt/* # Use Ubuntu rolling version FROM --platform=linux/arm64/v8 ubuntu:rolling @@ -15,7 +17,28 @@ FROM --platform=linux/arm64/v8 ubuntu:rolling COPY --from=builder /usr/bin/qemu-aarch64-static /usr/bin/ # Fetch dependencies -RUN apt update && DEBIAN_FRONTEND=noninteractive apt-get install openjdk-21-jre-headless tzdata sudo curl unzip net-tools gawk openssl findutils pigz libcurl4 libc6 libcrypt1 apt-utils libcurl4-openssl-dev ca-certificates binfmt-support nano -yqq && rm -rf /var/cache/apt/* +RUN apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get install -yqq \ + apt-utils \ + binfmt-support \ + ca-certificates \ + curl \ + gawk \ + findutils \ + jq \ + libcurl4 \ + libcurl4-openssl-dev \ + libc6 \ + libcrypt1 \ + net-tools \ + nano \ + openjdk-21-jre-headless \ + openssl \ + pigz \ + tzdata \ + unzip \ + vim && \ + rm -rf /var/cache/apt/* # Set port environment variable ENV Port=25565 @@ -24,7 +47,7 @@ ENV Port=25565 ENV BedrockPort=19132 # Optional maximum memory Minecraft is allowed to use -ENV MaxMemory= +ENV MaxMemory="" # Optional Paper Minecraft Version override ENV Version="1.21.3" @@ -52,12 +75,21 @@ EXPOSE 25565/tcp EXPOSE 19132/tcp EXPOSE 19132/udp -# Copy scripts to minecraftbe folder and make them executable +# Copy files into image and make the scripts executable RUN mkdir /scripts COPY *.sh /scripts/ COPY *.yml /scripts/ COPY server.properties /scripts/ RUN chmod -R +x /scripts/*.sh +# Create the minecraft user/group and set the container to run as the minecraft user +RUN groupadd -g 999 minecraft && \ + useradd -m -u 999 -g 999 -s /bin/bash minecraft && \ + mkdir /minecraft && \ + chown minecraft:minecraft /minecraft && \ + chmod 777 /minecraft +USER minecraft +WORKDIR /minecraft + # Set entrypoint to start.sh script ENTRYPOINT ["/bin/bash", "/scripts/start.sh"] diff --git a/armv7.Dockerfile b/armv7.Dockerfile index 4893c50..c01a82b 100644 --- a/armv7.Dockerfile +++ b/armv7.Dockerfile @@ -5,8 +5,10 @@ # Use Ubuntu rolling version for builder FROM ubuntu:rolling AS builder -# Update apt -RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install qemu-user-static binfmt-support apt-utils -yqq && rm -rf /var/cache/apt/* +# Prep qemu files +RUN apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get install -yqq apt-utils binfmt-support qemu-user-static && \ + rm -rf /var/cache/apt/* # Use Ubuntu rolling version FROM --platform=linux/arm/v7 ubuntu:rolling @@ -15,7 +17,28 @@ FROM --platform=linux/arm/v7 ubuntu:rolling COPY --from=builder /usr/bin/qemu-arm-static /usr/bin/ # Fetch dependencies -RUN apt update && DEBIAN_FRONTEND=noninteractive apt-get install openjdk-21-jre-headless tzdata sudo curl unzip net-tools gawk openssl findutils pigz libcurl4t64 libc6 libcrypt1 apt-utils libcurl4-openssl-dev ca-certificates binfmt-support nano -yqq && rm -rf /var/cache/apt/* +RUN apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get install -yqq \ + apt-utils \ + binfmt-support \ + ca-certificates \ + curl \ + gawk \ + findutils \ + jq \ + libcurl4 \ + libcurl4-openssl-dev \ + libc6 \ + libcrypt1 \ + net-tools \ + nano \ + openjdk-21-jre-headless \ + openssl \ + pigz \ + tzdata \ + unzip \ + vim && \ + rm -rf /var/cache/apt/* # Set port environment variable ENV Port=25565 @@ -24,7 +47,7 @@ ENV Port=25565 ENV BedrockPort=19132 # Optional maximum memory Minecraft is allowed to use -ENV MaxMemory= +ENV MaxMemory="" # Optional Paper Minecraft Version override ENV Version="1.21.3" @@ -52,12 +75,21 @@ EXPOSE 25565/tcp EXPOSE 19132/tcp EXPOSE 19132/udp -# Copy scripts to minecraftbe folder and make them executable +# Copy files into image and make the scripts executable RUN mkdir /scripts COPY *.sh /scripts/ COPY *.yml /scripts/ COPY server.properties /scripts/ RUN chmod -R +x /scripts/*.sh +# Create the minecraft user/group and set the container to run as the minecraft user +RUN groupadd -g 999 minecraft && \ + useradd -m -u 999 -g 999 -s /bin/bash minecraft && \ + mkdir /minecraft && \ + chown minecraft:minecraft /minecraft && \ + chmod 777 /minecraft +USER minecraft +WORKDIR /minecraft + # Set entrypoint to start.sh script ENTRYPOINT ["/bin/bash", "/scripts/start.sh"] diff --git a/ppc64le.Dockerfile b/ppc64le.Dockerfile index dbedb94..ea8e35c 100644 --- a/ppc64le.Dockerfile +++ b/ppc64le.Dockerfile @@ -2,11 +2,13 @@ # Author: James A. Chambers - https://jamesachambers.com/minecraft-java-bedrock-server-together-geyser-floodgate/ # GitHub Repository: https://github.com/TheRemote/Legendary-Java-Minecraft-Geyser-Floodgate -# Use latest Ubuntu version for builder +# Use Ubuntu rolling version for builder FROM ubuntu:rolling AS builder -# Update apt -RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install qemu-user-static binfmt-support apt-utils -yqq && rm -rf /var/cache/apt/* +# Prep qemu files +RUN apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get install -yqq apt-utils binfmt-support qemu-user-static && \ + rm -rf /var/cache/apt/* # Use Ubuntu rolling version FROM --platform=linux/ppc64le ubuntu:rolling @@ -15,7 +17,28 @@ FROM --platform=linux/ppc64le ubuntu:rolling COPY --from=builder /usr/bin/qemu-ppc64le-static /usr/bin/ # Fetch dependencies -RUN apt update && DEBIAN_FRONTEND=noninteractive apt-get install openjdk-21-jre-headless tzdata sudo curl unzip net-tools gawk openssl findutils pigz libcurl4 libc6 libcrypt1 apt-utils libcurl4-openssl-dev ca-certificates binfmt-support nano -yqq && rm -rf /var/cache/apt/* +RUN apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get install -yqq \ + apt-utils \ + binfmt-support \ + ca-certificates \ + curl \ + gawk \ + findutils \ + jq \ + libcurl4 \ + libcurl4-openssl-dev \ + libc6 \ + libcrypt1 \ + net-tools \ + nano \ + openjdk-21-jre-headless \ + openssl \ + pigz \ + tzdata \ + unzip \ + vim && \ + rm -rf /var/cache/apt/* # Set port environment variable ENV Port=25565 @@ -24,7 +47,7 @@ ENV Port=25565 ENV BedrockPort=19132 # Optional maximum memory Minecraft is allowed to use -ENV MaxMemory= +ENV MaxMemory="" # Optional Paper Minecraft Version override ENV Version="1.21.3" @@ -52,12 +75,21 @@ EXPOSE 25565/tcp EXPOSE 19132/tcp EXPOSE 19132/udp -# Copy scripts to minecraftbe folder and make them executable +# Copy files into image and make the scripts executable RUN mkdir /scripts COPY *.sh /scripts/ COPY *.yml /scripts/ COPY server.properties /scripts/ RUN chmod -R +x /scripts/*.sh +# Create the minecraft user/group and set the container to run as the minecraft user +RUN groupadd -g 999 minecraft && \ + useradd -m -u 999 -g 999 -s /bin/bash minecraft && \ + mkdir /minecraft && \ + chown minecraft:minecraft /minecraft && \ + chmod 777 /minecraft +USER minecraft +WORKDIR /minecraft + # Set entrypoint to start.sh script ENTRYPOINT ["/bin/bash", "/scripts/start.sh"] diff --git a/riscv64.Dockerfile b/riscv64.Dockerfile index ab87dd3..9f75ef9 100644 --- a/riscv64.Dockerfile +++ b/riscv64.Dockerfile @@ -2,20 +2,43 @@ # Author: James A. Chambers - https://jamesachambers.com/minecraft-java-bedrock-server-together-geyser-floodgate/ # GitHub Repository: https://github.com/TheRemote/Legendary-Java-Minecraft-Geyser-Floodgate -# Use latest Ubuntu version for builder +# Use Ubuntu rolling version for builder FROM ubuntu:rolling AS builder -# Update apt -RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install qemu-user-static binfmt-support apt-utils -yqq && rm -rf /var/cache/apt/* +# Prep qemu files +RUN apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get install -yqq apt-utils binfmt-support qemu-user-static && \ + rm -rf /var/cache/apt/* -# Use current Ubuntu LTS version +# Use Ubuntu rolling version FROM --platform=linux/riscv64 ubuntu:rolling # Add QEMU COPY --from=builder /usr/bin/qemu-riscv64-static /usr/bin/ # Fetch dependencies -RUN apt update && DEBIAN_FRONTEND=noninteractive apt-get install openjdk-21-jre-headless tzdata sudo curl unzip net-tools gawk openssl findutils pigz libcurl4 libc6 libcrypt1 apt-utils libcurl4-openssl-dev ca-certificates binfmt-support nano -yqq && rm -rf /var/cache/apt/* +RUN apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get install -yqq \ + apt-utils \ + binfmt-support \ + ca-certificates \ + curl \ + gawk \ + findutils \ + jq \ + libcurl4 \ + libcurl4-openssl-dev \ + libc6 \ + libcrypt1 \ + net-tools \ + nano \ + openjdk-21-jre-headless \ + openssl \ + pigz \ + tzdata \ + unzip \ + vim && \ + rm -rf /var/cache/apt/* # Set port environment variable ENV Port=25565 @@ -24,7 +47,7 @@ ENV Port=25565 ENV BedrockPort=19132 # Optional maximum memory Minecraft is allowed to use -ENV MaxMemory= +ENV MaxMemory="" # Optional Paper Minecraft Version override ENV Version="1.21.3" @@ -52,12 +75,21 @@ EXPOSE 25565/tcp EXPOSE 19132/tcp EXPOSE 19132/udp -# Copy scripts to minecraftbe folder and make them executable +# Copy files into image and make the scripts executable RUN mkdir /scripts COPY *.sh /scripts/ COPY *.yml /scripts/ COPY server.properties /scripts/ RUN chmod -R +x /scripts/*.sh +# Create the minecraft user/group and set the container to run as the minecraft user +RUN groupadd -g 999 minecraft && \ + useradd -m -u 999 -g 999 -s /bin/bash minecraft && \ + mkdir /minecraft && \ + chown minecraft:minecraft /minecraft && \ + chmod 777 /minecraft +USER minecraft +WORKDIR /minecraft + # Set entrypoint to start.sh script ENTRYPOINT ["/bin/bash", "/scripts/start.sh"] diff --git a/s390x.Dockerfile b/s390x.Dockerfile index cea20ce..a54192c 100644 --- a/s390x.Dockerfile +++ b/s390x.Dockerfile @@ -5,8 +5,10 @@ # Use Ubuntu rolling version for builder FROM ubuntu:rolling AS builder -# Update apt -RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install qemu-user-static binfmt-support apt-utils -yqq && rm -rf /var/cache/apt/* +# Prep qemu files +RUN apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get install -yqq apt-utils binfmt-support qemu-user-static && \ + rm -rf /var/cache/apt/* # Use Ubuntu rolling version FROM --platform=linux/s390x ubuntu:rolling @@ -15,7 +17,28 @@ FROM --platform=linux/s390x ubuntu:rolling COPY --from=builder /usr/bin/qemu-s390x-static /usr/bin/ # Fetch dependencies -RUN apt update && DEBIAN_FRONTEND=noninteractive apt-get install openjdk-21-jre-headless tzdata sudo curl unzip net-tools gawk openssl findutils pigz libcurl4 libc6 libcrypt1 apt-utils libcurl4-openssl-dev ca-certificates binfmt-support nano -yqq && rm -rf /var/cache/apt/* +RUN apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get install -yqq \ + apt-utils \ + binfmt-support \ + ca-certificates \ + curl \ + gawk \ + findutils \ + jq \ + libcurl4 \ + libcurl4-openssl-dev \ + libc6 \ + libcrypt1 \ + net-tools \ + nano \ + openjdk-21-jre-headless \ + openssl \ + pigz \ + tzdata \ + unzip \ + vim && \ + rm -rf /var/cache/apt/* # Set port environment variable ENV Port=25565 @@ -24,7 +47,7 @@ ENV Port=25565 ENV BedrockPort=19132 # Optional maximum memory Minecraft is allowed to use -ENV MaxMemory= +ENV MaxMemory="" # Optional Paper Minecraft Version override ENV Version="1.21.3" @@ -52,12 +75,21 @@ EXPOSE 25565/tcp EXPOSE 19132/tcp EXPOSE 19132/udp -# Copy scripts to minecraftbe folder and make them executable +# Copy files into image and make the scripts executable RUN mkdir /scripts COPY *.sh /scripts/ COPY *.yml /scripts/ COPY server.properties /scripts/ RUN chmod -R +x /scripts/*.sh +# Create the minecraft user/group and set the container to run as the minecraft user +RUN groupadd -g 999 minecraft && \ + useradd -m -u 999 -g 999 -s /bin/bash minecraft && \ + mkdir /minecraft && \ + chown minecraft:minecraft /minecraft && \ + chmod 777 /minecraft +USER minecraft +WORKDIR /minecraft + # Set entrypoint to start.sh script ENTRYPOINT ["/bin/bash", "/scripts/start.sh"] diff --git a/start.sh b/start.sh index 835ec33..c4f40ca 100755 --- a/start.sh +++ b/start.sh @@ -3,45 +3,45 @@ # Author: James A. Chambers - https://jamesachambers.com/minecraft-java-bedrock-server-together-geyser-floodgate/ # GitHub Repository: https://github.com/TheRemote/Legendary-Java-Minecraft-Geyser-Floodgate -# If running as root, create 'minecraft' user and restart script as 'minecraft' user -if [ "$(id -u)" = '0' ]; then - echo "Script is running as root, switching to 'minecraft' user..." +CurlArgs=( + -H "Accept-Encoding: identity" + -H "Accept-Language: en" + -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4.212 Safari/537.36" + -L +) - if ! id minecraft >/dev/null 2>&1; then - echo "Creating 'minecraft' user..." - useradd -m -r -s /bin/bash minecraft - fi +# If running as root, fix ownership of all files and restart script as 'minecraft' user +if [ "$(id -u)" = '0' ]; then + echo "Script is running as '$(whoami)', switching to 'minecraft' user ..." - chown -R minecraft:minecraft /minecraft + echo " Changing ownership of all files in /minecraft to 'minecraft:minecraft' ..." + chown -R minecraft:minecraft /minecraft >/dev/null - exec su minecraft -c "$0 $@" + echo " Restarting script as 'minecraft' user." + exec su minecraft -c "$0" "$@" fi +echo "################################################################################################################" echo "Paper Minecraft Java Server Docker + Geyser/Floodgate script by James A. Chambers" +echo "################################################################################################################" echo "Latest version always at https://github.com/TheRemote/Legendary-Java-Minecraft-Geyser-Floodgate" -echo "Don't forget to set up port forwarding on your router! The default port is 25565 and the Bedrock port is 19132" +echo "Don't forget to set up port forwarding on your router! The default port is 25565 and the Bedrock port is 19132." -if [ ! -d '/minecraft' ]; then +echo "" +echo "************************************************************************" +echo "Prepare Environment" +echo "************************************************************************" +echo "Checking volume mount ..." +if ! df -h | grep -q /minecraft; then echo "ERROR: A named volume was not specified for the minecraft server data. Please create one with: docker volume create yourvolumename" echo "Please pass the new volume to docker like this: docker run -it -v yourvolumename:/minecraft" exit 1 +else + echo " Volume mount found for /minecraft" fi -# Randomizer for user agent -RandNum=$(echo $((1 + $RANDOM % 5000))) - -if [ -z "$Port" ]; then - Port="25565" -fi -echo "Port used: $Port" - -if [ -z "$BedrockPort" ]; then - Port="19132" -fi -echo "Bedrock port used: $BedrockPort" - # Change directory to server directory -cd /minecraft +cd /minecraft || exit # Create backups/downloads folder if it doesn't exist if [ ! -d "/minecraft/downloads" ]; then @@ -58,14 +58,18 @@ if [ ! -d "/minecraft/plugins/Geyser-Spigot" ]; then fi # Check if network interfaces are up -NetworkChecks=0 +echo "Checking network interface status ..." if [ -e '/sbin/route' ]; then DefaultRoute=$(/sbin/route -n | awk '$4 == "UG" {print $2}') else DefaultRoute=$(route -n | awk '$4 == "UG" {print $2}') fi +if [ -n "$DefaultRoute" ]; then + echo " Network interface is up." +fi +NetworkChecks=0 while [ -z "$DefaultRoute" ]; do - echo "Network interface not up, will try again in 1 second" + echo " Network interface not up, will try again in 1 second ..." sleep 1 if [ -e '/sbin/route' ]; then DefaultRoute=$(/sbin/route -n | awk '$4 == "UG" {print $2}') @@ -74,53 +78,67 @@ while [ -z "$DefaultRoute" ]; do fi NetworkChecks=$((NetworkChecks + 1)) if [ $NetworkChecks -gt 20 ]; then - echo "Waiting for network interface to come up timed out - starting server without network connection ..." + echo "ERROR: Waiting for network interface to come up timed out - starting server without network connection." break fi + if [ -n "$DefaultRoute" ]; then + echo " Network interface is up." + fi done -# Take ownership of server files and set correct permissions +# Check ownership of server files if [ -z "$NoPermCheck" ]; then - echo "Taking ownership of all server files/folders in /minecraft..." - sudo -n chown -R $(whoami) /minecraft >/dev/null 2>&1 - echo "Complete" + echo "Checking ownership of all server files/folders in /minecraft for user:group - '$(whoami):$(whoami)' ..." + chown -R minecraft:minecraft /minecraft >/dev/null + echo " Ownership check complete. Any errors above could indicate an issue." else - echo "Skipping permissions check due to NoPermCheck flag" + echo "Skipping ownership check due to NoPermCheck flag." fi # Back up server if [ -d "world" ]; then - if [ -n "$(which pigz)" ]; then - echo "Backing up server (all cores) to cd minecraft/backups folder" - tarArgs=(-I pigz --exclude='./backups' --exclude='./cache' --exclude='./logs' --exclude='./paperclip.jar') + echo "Running backup ..." + # Build tar args + tarExcludes=( + --exclude='./backups' + --exclude='./cache' + --exclude='./logs' + --exclude='./paperclip.jar' + ) + if [ -n "$NoBackup" ]; then + echo " Excluding the following extra items from backups: ${NoBackup}" IFS=',' read -ra ADDR <<< "$NoBackup" for i in "${ADDR[@]}"; do - tarArgs+=(--exclude="./$i") + tarExcludes+=(--exclude="./$i") done - tarArgs+=(-pvcf backups/$(date +%Y.%m.%d.%H.%M.%S).tar.gz ./*) - tar "${tarArgs[@]}" + fi + if [ -n "$(which pigz)" ]; then + tarCompression="-I pigz" + coresMsg="all cores" else - echo "Backing up server (single core, pigz not found) to cd minecraft/backups folder" - tarArgs=(--exclude='./backups' --exclude='./cache' --exclude='./logs' --exclude='./paperclip.jar') - IFS=',' - read -ra ADDR <<< "$NoBackup" - for i in "${ADDR[@]}"; do - tarArgs+=(--exclude="./$i") - done - tarArgs+=(-pvcf backups/$(date +%Y.%m.%d.%H.%M.%S).tar.gz ./*) - tar "${tarArgs[@]}" + tarCompression="" + coresMsg="single core, pigz not found" fi + echo " Backing up server ($coresMsg) to /minecraft/backups folder..." + tar "${tarExcludes[@]}" \ + "$tarCompression" \ + --totals \ + -pcf \ + "backups/$(date +%Y.%m.%d.%H.%M.%S).tar.gz" \ + . 2>&1 | sed 's/^Total bytes written:/ Total bytes written:/' fi # Rotate backups -if [ -d /minecraft/backups ]; then - Rotate=$( - pushd /minecraft/backups - ls -1tr | head -n -$BackupCount | xargs -d '\n' rm -f -- - popd - ) +if [ -d /minecraft/backups ] && [ -n "$BackupCount" ]; then + ( + pushd /minecraft/backups || exit + find . -type f -printf "%T@ %p\n" | sort -n | head -n -"$BackupCount" | cut -d' ' -f2- | xargs -d '\n' rm -f -- + popd || exit + ) > /dev/null fi +# Ensure we are back in the server directory +cd /minecraft > /dev/null || exit # Copy config files if this is a brand new server if [ ! -e "/minecraft/bukkit.yml" ]; then @@ -139,95 +157,118 @@ if [ ! -e "/minecraft/plugins/Geyser-Spigot/config.yml" ]; then cp /scripts/config.yml /minecraft/plugins/Geyser-Spigot/config.yml fi -# Test internet connectivity first # Update paperclip.jar -echo "Updating to most recent paperclip version ..." +echo "Updating to most recent Paper server version ..." -# Test internet connectivity first -if [ -z "$QuietCurl" ]; then - curl -H "Accept-Encoding: identity" -H "Accept-Language: en" -L -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4.212 Safari/537.36" -s https://papermc.io -o /dev/null +# Test update website connectivity first +if ! curl "${CurlArgs[@]}" \ + -s \ + https://api.papermc.io \ + -o /dev/null; then + echo "ERROR: Unable to connect to update website (internet connection may be down). Skipping server and plugin updates." else - curl --no-progress-meter -H "Accept-Encoding: identity" -H "Accept-Language: en" -L -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4.212 Safari/537.36" -s https://papermc.io -o /dev/null -fi + # Get latest build number + BuildJSON=$(curl --no-progress-meter \ + "${CurlArgs[@]}" \ + https://api.papermc.io/v2/projects/paper/versions/"${Version:?}"/builds + ) + Build=$(echo "$BuildJSON" | jq '.builds | if map(select(.channel == "default")) | length > 0 then map(select(.channel == "default") | .build) | . else map(select(.channel == "experimental") | .build) | . end | .[-1]') + Build=$((Build + 0)) -if [ "$?" != 0 ]; then - echo "Unable to connect to update website (internet connection may be down). Skipping update ..." -else - # Get latest build - BuildJSON=$(curl --no-progress-meter -H "Accept-Encoding: identity" -H "Accept-Language: en" -L -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4.212 Safari/537.36" https://papermc.io/api/v2/projects/paper/versions/$Version) - Build=$(echo "$BuildJSON" | rev | cut -d, -f 1 | cut -d']' -f 2 | cut -d'[' -f 1 | rev) - Build=$(($Build + 0)) + # Download latest build for the targeted version if [[ $Build != 0 ]]; then - echo "Latest paperclip build found: $Build" - if [ -z "$QuietCurl" ]; then - curl -H "Accept-Encoding: identity" -H "Accept-Language: en" -L -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4.212 Safari/537.36" -o /minecraft/paperclip.jar "https://papermc.io/api/v2/projects/paper/versions/$Version/builds/$Build/downloads/paper-$Version-$Build.jar" - else - curl --no-progress-meter -H "Accept-Encoding: identity" -H "Accept-Language: en" -L -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4.212 Safari/537.36" -o /minecraft/paperclip.jar "https://papermc.io/api/v2/projects/paper/versions/$Version/builds/$Build/downloads/paper-$Version-$Build.jar" - fi + echo " Found latest Paper build $Build for version $Version" + curl ${QuietCurl:+"--no-progress-meter"} \ + "${CurlArgs[@]}" \ + -o /minecraft/paperclip.jar \ + "https://api.papermc.io/v2/projects/paper/versions/$Version/builds/$Build/downloads/paper-$Version-$Build.jar" else - echo "Unable to retrieve latest Paper build (got result of $Build)" + echo " Unable to retrieve latest Paper build (got result of: $Build)" fi # Update Floodgate - echo "Updating Floodgate..." - if [ -z "$QuietCurl" ]; then - curl -H "Accept-Encoding: identity" -H "Accept-Language: en" -L -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4.212 Safari/537.36" -o /minecraft/plugins/Floodgate-Spigot.jar "https://download.geysermc.org/v2/projects/floodgate/versions/latest/builds/latest/downloads/spigot" - else - curl --no-progress-meter -H "Accept-Encoding: identity" -H "Accept-Language: en" -L -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4.212 Safari/537.36" -o /minecraft/plugins/Floodgate-Spigot.jar "https://download.geysermc.org/v2/projects/floodgate/versions/latest/builds/latest/downloads/spigot" - fi + echo "Updating Floodgate ..." + curl ${QuietCurl:+"--no-progress-meter"} \ + "${CurlArgs[@]}" \ + -o /minecraft/plugins/Floodgate-Spigot.jar \ + "https://download.geysermc.org/v2/projects/floodgate/versions/latest/builds/latest/downloads/spigot" # Update Geyser - echo "Updating Geyser..." - if [ -z "$QuietCurl" ]; then - curl -H "Accept-Encoding: identity" -H "Accept-Language: en" -L -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4.212 Safari/537.36" -o /minecraft/plugins/Geyser-Spigot.jar "https://download.geysermc.org/v2/projects/geyser/versions/latest/builds/latest/downloads/spigot" - else - curl --no-progress-meter -H "Accept-Encoding: identity" -H "Accept-Language: en" -L -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4.212 Safari/537.36" -o /minecraft/plugins/Geyser-Spigot.jar "https://download.geysermc.org/v2/projects/geyser/versions/latest/builds/latest/downloads/spigot" - fi + echo "Updating Geyser ..." + curl ${QuietCurl:+"--no-progress-meter"} \ + "${CurlArgs[@]}" \ + -o /minecraft/plugins/Geyser-Spigot.jar \ + "https://download.geysermc.org/v2/projects/geyser/versions/latest/builds/latest/downloads/spigot" + echo "Updating ViaVersion ..." if [ -z "$NoViaVersion" ]; then # Update ViaVersion if new version is available - ViaVersionVersion=$(curl --no-progress-meter -k -L -H "Accept-Encoding: identity" -H "Accept-Language: en" -L -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4.212 Safari/537.36" https://ci.viaversion.com/job/ViaVersion/lastBuild/artifact/build/libs/ | grep -P '(?<=href=")ViaVersion[^"]+' -o --max-count=1 | head -n1) - if [ -n "$ViaVersionVersion" ]; then - ViaVersionMD5=$(curl --no-progress-meter -k -L -H "Accept-Encoding: identity" -H "Accept-Language: en" -L -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4.212 Safari/537.36" "https://ci.viaversion.com/job/ViaVersion/lastBuild/artifact/build/libs/$ViaVersionVersion/*fingerprint*/" | grep breadcrumbs | cut -d'_' -f24- | cut -d'<' -f2 | cut -d'>' -f2) - if [ -n "$ViaVersionMD5" ]; then - LocalMD5=$(md5sum plugins/ViaVersion.jar | cut -d' ' -f1) - if [ -e /minecraft/plugins/ViaVersion.jar ] && [ "$LocalMD5" = "$ViaVersionMD5" ]; then - echo "ViaVersion is up to date" + echo " Checking the latest version of ViaVersion ..." + ViaVersionLatestVersion=$(curl --no-progress-meter \ + "${CurlArgs[@]}" \ + -k \ + https://ci.viaversion.com/job/ViaVersion/lastBuild/artifact/build/libs/ \ + | grep -P '(?<=href=")ViaVersion[^"]+' -o --max-count=1 | head -n1 + ) + if [ -n "$ViaVersionLatestVersion" ]; then + ViaVersionLatestMD5=$(curl --no-progress-meter \ + "${CurlArgs[@]}" \ + -k \ + "https://ci.viaversion.com/job/ViaVersion/lastBuild/artifact/build/libs/$ViaVersionLatestVersion/*fingerprint*/" \ + | grep breadcrumbs | cut -d'_' -f24- | cut -d'<' -f2 | cut -d'>' -f2 + ) + if [ -n "$ViaVersionLatestMD5" ]; then + ViaVersionLocalMD5=$(md5sum plugins/ViaVersion.jar | cut -d' ' -f1) + if [ -e /minecraft/plugins/ViaVersion.jar ] && [ "$ViaVersionLocalMD5" = "$ViaVersionLatestMD5" ]; then + echo " ViaVersion is up to date: $ViaVersionLatestVersion" else - echo "Updating ViaVersion..." - if [ -z "$QuietCurl" ]; then - curl -H "Accept-Encoding: identity" -H "Accept-Language: en" -L -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4.212 Safari/537.36" -o /minecraft/plugins/ViaVersion.jar "https://ci.viaversion.com/job/ViaVersion/lastBuild/artifact/build/libs/$ViaVersionVersion" - else - curl --no-progress-meter -H "Accept-Encoding: identity" -H "Accept-Language: en" -L -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4.212 Safari/537.36" -o /minecraft/plugins/ViaVersion.jar "https://ci.viaversion.com/job/ViaVersion/lastBuild/artifact/build/libs/$ViaVersionVersion" - fi + echo " Downloading new version: $ViaVersionLatestVersion" + curl ${QuietCurl:+"--no-progress-meter"} \ + "${CurlArgs[@]}" \ + -k \ + -o /minecraft/plugins/ViaVersion.jar \ + "https://ci.viaversion.com/job/ViaVersion/lastBuild/artifact/build/libs/$ViaVersionLatestVersion" fi else - echo "Unable to check for updates to ViaVersion!" + echo "ERROR: Unable to check for updates to ViaVersion!" fi fi else - echo "ViaVersion is disabled -- skipping" + echo " ViaVersion is disabled -- skipping" fi fi # Accept EULA -AcceptEULA=$(echo eula=true >eula.txt) +echo "Accepting EULA ..." +echo eula=true > eula.txt # Change ports in server.properties +echo "Setting server ports ..." +if [ -z "$Port" ]; then + Port="25565" +fi +echo " Java port used: $Port" sed -i "/server-port=/c\server-port=$Port" /minecraft/server.properties sed -i "/query\.port=/c\query\.port=$Port" /minecraft/server.properties # Change Bedrock port in Geyser config +if [ -z "$BedrockPort" ]; then + Port="19132" +fi +echo " Bedrock port used: $BedrockPort" if [ -e /minecraft/plugins/Geyser-Spigot/config.yml ]; then sed -i -z "s/ port: [0-9]*/ port: $BedrockPort/" /minecraft/plugins/Geyser-Spigot/config.yml fi # Start server -echo "Starting Minecraft server..." - +echo "" +echo "************************************************************************" +echo "Launch Minecraft" +echo "************************************************************************" +echo "Starting Minecraft server ..." if [[ -z "$MaxMemory" ]] || [[ "$MaxMemory" -le 0 ]]; then exec java -XX:+UnlockDiagnosticVMOptions -XX:-UseAESCTRIntrinsics -DPaper.IgnoreJavaVersion=true -Xms400M -jar /minecraft/paperclip.jar else - exec java -XX:+UnlockDiagnosticVMOptions -XX:-UseAESCTRIntrinsics -DPaper.IgnoreJavaVersion=true -Xms400M -Xmx${MaxMemory}M -jar /minecraft/paperclip.jar + exec java -XX:+UnlockDiagnosticVMOptions -XX:-UseAESCTRIntrinsics -DPaper.IgnoreJavaVersion=true -Xms400M -Xmx"${MaxMemory}"M -jar /minecraft/paperclip.jar fi # Exit container