From a0e605814f42e1d8cd5e98efd9711390fd7581f8 Mon Sep 17 00:00:00 2001 From: Aitor Ramos Sasselli Date: Sat, 28 Oct 2017 10:04:52 +0200 Subject: [PATCH 1/3] Code refactorization --- minecraft-server/Dockerfile | 12 +- minecraft-server/start-configuration.sh | 82 +++ minecraft-server/start-deployBukkitSpigot.sh | 71 ++ minecraft-server/start-deployFTB.sh | 68 ++ minecraft-server/start-deployForge.sh | 118 +++ minecraft-server/start-deployPaper.sh | 41 ++ minecraft-server/start-deployVanilla.sh | 11 + minecraft-server/start-finalSetup01World.sh | 36 + minecraft-server/start-finalSetup02Modpack.sh | 39 + .../start-finalSetup03Modconfig.sh | 25 + .../start-finalSetup04ServerProperties.sh | 117 +++ minecraft-server/start-minecraft.sh | 670 ------------------ minecraft-server/start-minecraftFinalSetup.sh | 88 +++ minecraft-server/start.sh | 2 +- 14 files changed, 708 insertions(+), 672 deletions(-) create mode 100755 minecraft-server/start-configuration.sh create mode 100755 minecraft-server/start-deployBukkitSpigot.sh create mode 100755 minecraft-server/start-deployFTB.sh create mode 100755 minecraft-server/start-deployForge.sh create mode 100755 minecraft-server/start-deployPaper.sh create mode 100755 minecraft-server/start-deployVanilla.sh create mode 100755 minecraft-server/start-finalSetup01World.sh create mode 100755 minecraft-server/start-finalSetup02Modpack.sh create mode 100755 minecraft-server/start-finalSetup03Modconfig.sh create mode 100755 minecraft-server/start-finalSetup04ServerProperties.sh delete mode 100755 minecraft-server/start-minecraft.sh create mode 100755 minecraft-server/start-minecraftFinalSetup.sh diff --git a/minecraft-server/Dockerfile b/minecraft-server/Dockerfile index f8713424..ada7d62b 100644 --- a/minecraft-server/Dockerfile +++ b/minecraft-server/Dockerfile @@ -32,7 +32,17 @@ EXPOSE 25565 25575 ADD https://github.com/itzg/restify/releases/download/1.0.4/restify_linux_amd64 /usr/local/bin/restify ADD https://github.com/itzg/rcon-cli/releases/download/1.3/rcon-cli_linux_amd64 /usr/local/bin/rcon-cli COPY start.sh /start -COPY start-minecraft.sh /start-minecraft +COPY start-configuration.sh /start-configuration +COPY start-deployVanilla.sh /start-deployVanilla +COPY start-deployForge.sh /start-deployForge +COPY start-deployBukkitSpigot.sh /start-deployBukkitSpigot +COPY start-deployPaper.sh /start-deployPaper +COPY start-deployFTB.sh /start-deployFTB +COPY start-finalSetup01World.sh /start-finalSetup01World +COPY start-finalSetup02Modpack.sh /start-finalSetup02Modpack +COPY start-finalSetup03Modconfig.sh /start-finalSetup03Modconfig +COPY start-finalSetup04ServerProperties.sh /start-finalSetup04ServerProperties +COPY start-minecraftFinalSetup.sh /start-minecraftFinalSetup COPY mcadmin.jq /usr/share RUN chmod +x /usr/local/bin/* diff --git a/minecraft-server/start-configuration.sh b/minecraft-server/start-configuration.sh new file mode 100755 index 00000000..b799eedc --- /dev/null +++ b/minecraft-server/start-configuration.sh @@ -0,0 +1,82 @@ +#!/bin/bash + +shopt -s nullglob + +#umask 002 +export HOME=/data + +if [ ! -e /data/eula.txt ]; then + if [ "$EULA" != "" ]; then + echo "# Generated via Docker on $(date)" > eula.txt + echo "eula=$EULA" >> eula.txt + if [ $? != 0 ]; then + echo "ERROR: unable to write eula to /data. Please make sure attached directory is writable by uid=${UID}" + exit 2 + fi + else + echo "" + echo "Please accept the Minecraft EULA at" + echo " https://account.mojang.com/documents/minecraft_eula" + echo "by adding the following immediately after 'docker run':" + echo " -e EULA=TRUE" + echo "" + exit 1 + fi +fi + +if ! touch /data/.verify_access; then + echo "ERROR: /data doesn't seem to be writable. Please make sure attached directory is writable by uid=${UID} " + exit 2 +fi + +export SERVER_PROPERTIES=/data/server.properties +export FTB_DIR=/data/FeedTheBeast +export VERSIONS_JSON=https://launchermeta.mojang.com/mc/game/version_manifest.json + +echo "Checking version information." +case "X$VERSION" in + X|XLATEST|Xlatest) + export VANILLA_VERSION=`curl -fsSL $VERSIONS_JSON | jq -r '.latest.release'` + ;; + XSNAPSHOT|Xsnapshot) + export VANILLA_VERSION=`curl -fsSL $VERSIONS_JSON | jq -r '.latest.snapshot'` + ;; + X[1-9]*) + export VANILLA_VERSION=$VERSION + ;; + *) + export VANILLA_VERSION=`curl -fsSL $VERSIONS_JSON | jq -r '.latest.release'` + ;; +esac + +cd /data + +echo "Checking type information." +case "$TYPE" in + *BUKKIT|*bukkit|SPIGOT|spigot) + su-exec minecraft /start-deployBukkitSpigot $@ + ;; + + PAPER|paper) + su-exec minecraft /start-deployPaper $@ + ;; + + FORGE|forge) + su-exec minecraft /start-deployForge $@ + ;; + + FTB|ftb) + su-exec minecraft /start-deployFTB $@ + ;; + + VANILLA|vanilla) + su-exec minecraft /start-deployVanilla $@ + ;; + + *) + echo "Invalid type: '$TYPE'" + echo "Must be: VANILLA, FORGE, BUKKIT, SPIGOT, PAPER, FTB" + exit 1 + ;; + +esac diff --git a/minecraft-server/start-deployBukkitSpigot.sh b/minecraft-server/start-deployBukkitSpigot.sh new file mode 100755 index 00000000..681fe629 --- /dev/null +++ b/minecraft-server/start-deployBukkitSpigot.sh @@ -0,0 +1,71 @@ +#!/bin/bash + +function buildSpigotFromSource { + echo "Building Spigot $VANILLA_VERSION from source, might take a while, get some coffee" + mkdir /data/temp + cd /data/temp + wget -q -P /data/temp https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar && \ + java -jar /data/temp/BuildTools.jar --rev $VANILLA_VERSION 2>&1 |tee /data/spigot_build.log| while read l; do echo -n .; done; echo "done" + mv spigot-*.jar /data/spigot_server.jar + mv craftbukkit-*.jar /data/craftbukkit_server.jar + echo "Cleaning up" + rm -rf /data/temp + cd /data +} + +function downloadSpigot { + local match + case "$TYPE" in + *BUKKIT|*bukkit) + match="Craftbukkit" + downloadUrl=${BUKKIT_DOWNLOAD_URL} + ;; + *) + match="Spigot" + downloadUrl=${SPIGOT_DOWNLOAD_URL} + ;; + esac + + if [[ -z $downloadUrl ]]; then + downloadUrl=$(restify --class=jar-div https://mcadmin.net/ | \ + jq --arg version "$match $VANILLA_VERSION" -r -f /usr/share/mcadmin.jq) + if [[ -z $downloadUrl ]]; then + echo "ERROR: Version $VANILLA_VERSION is not supported for $TYPE" + echo " Refer to https://mcadmin.net/ for supported versions" + exit 2 + fi + fi + + echo "Downloading $match" + curl -kfsSL -o $SERVER "$downloadUrl" + status=$? + if [ ! -f $SERVER ]; then + echo "ERROR: failed to download from $downloadUrl (status=$status)" + exit 3 + fi + +} + + +case "$TYPE" in + *BUKKIT|*bukkit) + export SERVER=craftbukkit_server.jar + ;; + *) + export SERVER=spigot_server.jar + ;; +esac + +if [ ! -f $SERVER ]; then + if [[ "$BUILD_SPIGOT_FROM_SOURCE" = TRUE || "$BUILD_SPIGOT_FROM_SOURCE" = true || "$BUILD_FROM_SOURCE" = TRUE || "$BUILD_FROM_SOURCE" = true ]]; then + buildSpigotFromSource + else + downloadSpigot + fi +fi + +# Normalize on Spigot for operations below +export TYPE=SPIGOT + +# Continue to Final Setup +su-exec minecraft /start-finalSetup01World $@ diff --git a/minecraft-server/start-deployFTB.sh b/minecraft-server/start-deployFTB.sh new file mode 100755 index 00000000..12cbfbf8 --- /dev/null +++ b/minecraft-server/start-deployFTB.sh @@ -0,0 +1,68 @@ +#!/bin/bash + +export TYPE=FEED-THE-BEAST + +function isURL { + local value=$1 + + if [[ ${value:0:8} == "https://" || ${value:0:7} = "http://" ]]; then + return 0 + else + return 1 + fi +} + +echo "Looking for Feed-The-Beast server modpack." +if [[ -z $FTB_SERVER_MOD ]]; then + echo "Environment variable FTB_SERVER_MOD not set." + echo "Set FTB_SERVER_MOD to the file name of the FTB server modpack." + echo "(And place the modpack in the /data directory.)" + exit 2 +fi +srv_modpack=${FTB_SERVER_MOD} +if isURL ${srv_modpack}; then + case $srv_modpack in + https://www.feed-the-beast.com/*/download) + break;; + https://www.feed-the-beast.com/*) + srv_modpack=${srv_modpack}/download;; + esac + file=$(basename $(dirname $srv_modpack)) + downloaded=/data/${file}.zip + if [ ! -e $downloaded ]; then + echo "Downloading FTB modpack... +$srv_modpack -> $downloaded" + curl -sSL -o $downloaded $srv_modpack + fi + srv_modpack=$downloaded +fi +if [[ ${srv_modpack:0:5} == "data/" ]]; then + # Prepend with "/" + srv_modpack=/${srv_modpack} +fi +if [[ ! ${srv_modpack:0:1} == "/" ]]; then + # If not an absolute path, assume file is in "/data" + srv_modpack=/data/${srv_modpack} +fi +if [[ ! -f ${srv_modpack} ]]; then + echo "FTB server modpack ${srv_modpack} not found." + exit 2 +fi +if [[ ! ${srv_modpack: -4} == ".zip" ]]; then + echo "FTB server modpack ${srv_modpack} is not a zip archive." + echo "Please set FTB_SERVER_MOD to a file with a .zip extension." + exit 2 +fi + +if [ ! -d ${FTB_DIR} ]; then + echo "Unpacking FTB server modpack ${srv_modpack} ..." + mkdir -p ${FTB_DIR} + unzip -o ${srv_modpack} -d ${FTB_DIR} + cp -f /data/eula.txt ${FTB_DIR}/eula.txt +fi +export FTB_SERVER_START=${FTB_DIR}/ServerStart.sh +chmod a+x ${FTB_SERVER_START} +sed -i "s/-jar/-Dfml.queryResult=confirm -jar/" ${FTB_SERVER_START} + +# Continue to Final Setup +su-exec minecraft /start-finalSetup01World $@ diff --git a/minecraft-server/start-deployForge.sh b/minecraft-server/start-deployForge.sh new file mode 100755 index 00000000..eecb8e1e --- /dev/null +++ b/minecraft-server/start-deployForge.sh @@ -0,0 +1,118 @@ +#!/bin/bash + +export TYPE=FORGE + +if [[ -z $FORGE_INSTALLER && -z $FORGE_INSTALLER_URL ]]; then + norm=$VANILLA_VERSION + + case $VANILLA_VERSION in + *.*.*) + norm=$VANILLA_VERSION ;; + *.*) + norm=${VANILLA_VERSION}.0 ;; + esac + + echo "Checking Forge version information." + case $FORGEVERSION in + RECOMMENDED) + curl -fsSL -o /tmp/forge.json http://files.minecraftforge.net/maven/net/minecraftforge/forge/promotions_slim.json + FORGE_VERSION=$(cat /tmp/forge.json | jq -r ".promos[\"$VANILLA_VERSION-recommended\"]") + if [ $FORGE_VERSION = null ]; then + FORGE_VERSION=$(cat /tmp/forge.json | jq -r ".promos[\"$VANILLA_VERSION-latest\"]") + if [ $FORGE_VERSION = null ]; then + echo "ERROR: Version $VANILLA_VERSION is not supported by Forge" + echo " Refer to http://files.minecraftforge.net/ for supported versions" + exit 2 + fi + fi + ;; + + *) + FORGE_VERSION=$FORGEVERSION + ;; + esac + + normForgeVersion=$VANILLA_VERSION-$FORGE_VERSION-$norm + shortForgeVersion=$VANILLA_VERSION-$FORGE_VERSION + + FORGE_INSTALLER="/tmp/forge-$shortForgeVersion-installer.jar" +elif [[ -z $FORGE_INSTALLER ]]; then + FORGE_INSTALLER="/tmp/forge-installer.jar" +elif [[ ! -e $FORGE_INSTALLER ]]; then + echo "ERROR: the given Forge installer doesn't exist : $FORGE_INSTALLER" + exit 2 +fi + +installMarker=".forge-installed-$shortForgeVersion" + +if [ ! -e $installMarker ]; then + if [ ! -e $FORGE_INSTALLER ]; then + + if [[ -z $FORGE_INSTALLER_URL ]]; then + echo "Downloading $normForgeVersion" + + forgeFileNames=" + $normForgeVersion/forge-$normForgeVersion-installer.jar + $shortForgeVersion/forge-$shortForgeVersion-installer.jar + END + " + for fn in $forgeFileNames; do + if [ $fn == END ]; then + echo "Unable to compute URL for $normForgeVersion" + exit 2 + fi + downloadUrl=http://files.minecraftforge.net/maven/net/minecraftforge/forge/$fn + echo "...trying $downloadUrl" + if curl -o $FORGE_INSTALLER -fsSL $downloadUrl; then + break + fi + done + else + echo "Downloading $FORGE_INSTALLER_URL ..." + if ! curl -o $FORGE_INSTALLER -fsSL $FORGE_INSTALLER_URL; then + echo "Failed to download from given location $FORGE_INSTALLER_URL" + exit 2 + fi + fi + fi + + echo "Installing Forge $shortForgeVersion using $FORGE_INSTALLER" + mkdir -p mods + tries=3 + while ((--tries >= 0)); do + java -jar $FORGE_INSTALLER --installServer + if [ $? == 0 ]; then + break + fi + done + if (($tries < 0)); then + echo "Forge failed to install after several tries." >&2 + exit 10 + fi + # NOTE $shortForgeVersion will be empty if installer location was given to us + echo "Finding installed server jar..." + for j in *forge*.jar; do + echo "...$j" + case $j in + *installer*) + ;; + *) + export SERVER=$j + break + ;; + esac + done + if [[ -z $SERVER ]]; then + echo "Unable to derive server jar for Forge" + exit 2 + fi + + echo "Using server $SERVER" + echo $SERVER > $installMarker + +else + export SERVER=$(cat $installMarker) +fi + +# Continue to Final Setup +su-exec minecraft /start-finalSetup01World $@ diff --git a/minecraft-server/start-deployPaper.sh b/minecraft-server/start-deployPaper.sh new file mode 100755 index 00000000..06f9b8fc --- /dev/null +++ b/minecraft-server/start-deployPaper.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +export SERVER=paper_server.jar +if [ ! -f $SERVER ]; then + local build + case "$VERSION" in + latest|LATEST|1.10) + build="lastSuccessfulBuild";; + 1.9.4) + build="773";; + 1.9.2) + build="727";; + 1.9) + build="612";; + 1.8.8) + build="443";; + *) + build="nosupp";; + esac + + if [ $build != "nosupp" ]; then + rm $SERVER + downloadUrl=${PAPER_DOWNLOAD_URL:-https://ci.destroystokyo.com/job/PaperSpigot/$build/artifact/paperclip.jar} + curl -fsSL -o $SERVER "$downloadUrl" + if [ ! -f $SERVER ]; then + echo "ERROR: failed to download from $downloadUrl (status=$?)" + exit 3 + fi + else + echo "ERROR: Version $VERSION is not supported for $TYPE" + echo " Refer to https://ci.destroystokyo.com/job/PaperSpigot/" + echo " for supported versions" + exit 2 + fi +fi + +# Normalize on Spigot for operations below +export TYPE=SPIGOT + +# Continue to Final Setup +su-exec minecraft /start-finalSetup01World $@ diff --git a/minecraft-server/start-deployVanilla.sh b/minecraft-server/start-deployVanilla.sh new file mode 100755 index 00000000..de7aee1c --- /dev/null +++ b/minecraft-server/start-deployVanilla.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +export SERVER="minecraft_server.$VANILLA_VERSION.jar" + +if [ ! -e $SERVER ]; then + echo "Downloading $SERVER ..." + wget -q https://s3.amazonaws.com/Minecraft.Download/versions/$VANILLA_VERSION/$SERVER +fi + +# Continue to Final Setup +su-exec minecraft /start-finalSetup01World $@ diff --git a/minecraft-server/start-finalSetup01World.sh b/minecraft-server/start-finalSetup01World.sh new file mode 100755 index 00000000..02338abd --- /dev/null +++ b/minecraft-server/start-finalSetup01World.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +# If supplied with a URL for a world, download it and unpack +if [[ "$WORLD" ]]; then +case "X$WORLD" in + X[Hh][Tt][Tt][Pp]*) + echo "Downloading world via HTTP" + echo "$WORLD" + wget -q -O - "$WORLD" > /data/world.zip + echo "Unzipping word" + unzip -q /data/world.zip + rm -f /data/world.zip + if [ ! -d /data/world ]; then + echo World directory not found + for i in /data/*/level.dat; do + if [ -f "$i" ]; then + d=`dirname "$i"` + echo Renaming world directory from $d + mv -f "$d" /data/world + fi + done + fi + if [ "$TYPE" = "SPIGOT" ]; then + # Reorganise if a Spigot server + echo "Moving End and Nether maps to Spigot location" + [ -d "/data/world/DIM1" ] && mv -f "/data/world/DIM1" "/data/world_the_end" + [ -d "/data/world/DIM-1" ] && mv -f "/data/world/DIM-1" "/data/world_nether" + fi + ;; + *) + echo "Invalid URL given for world: Must be HTTP or HTTPS and a ZIP file" + ;; +esac +fi + +su-exec minecraft /start-finalSetup02Modpack $@ diff --git a/minecraft-server/start-finalSetup02Modpack.sh b/minecraft-server/start-finalSetup02Modpack.sh new file mode 100755 index 00000000..95166d5b --- /dev/null +++ b/minecraft-server/start-finalSetup02Modpack.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +# If supplied with a URL for a modpack (simple zip of jars), download it and unpack +if [[ "$MODPACK" ]]; then +case "X$MODPACK" in + X[Hh][Tt][Tt][Pp]*.zip) + echo "Downloading mod/plugin pack via HTTP" + echo " from $MODPACK ..." + if ! curl -sSL -o /tmp/modpack.zip "$MODPACK"; then + echo "ERROR: failed to download from $MODPACK" + exit 2 + fi + + if [ "$TYPE" = "SPIGOT" ]; then + if [ "$REMOVE_OLD_MODS" = "TRUE" ]; then + rm -rf /data/plugins/* + fi + mkdir -p /data/plugins + if ! unzip -o -d /data/plugins /tmp/modpack.zip; then + echo "ERROR: failed to unzip the modpack from $MODPACK" + fi + else + if [ "$REMOVE_OLD_MODS" = "TRUE" ]; then + rm -rf /data/mods/* + fi + mkdir -p /data/mods + if ! unzip -o -d /data/mods /tmp/modpack.zip; then + echo "ERROR: failed to unzip the modpack from $MODPACK" + fi + fi + rm -f /tmp/modpack.zip + ;; + *) + echo "Invalid URL given for modpack: Must be HTTP or HTTPS and a ZIP file" + ;; +esac +fi + +su-exec minecraft /start-finalSetup03Modconfig $@ diff --git a/minecraft-server/start-finalSetup03Modconfig.sh b/minecraft-server/start-finalSetup03Modconfig.sh new file mode 100755 index 00000000..84e17460 --- /dev/null +++ b/minecraft-server/start-finalSetup03Modconfig.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +# If supplied with a URL for a config (simple zip of configurations), download it and unpack +if [[ "$MODCONFIG" ]]; then +case "X$MODCONFIG" in + X[Hh][Tt][Tt][Pp]*[Zz][iI][pP]) + echo "Downloading mod/plugin configs via HTTP" + echo " from $MODCONFIG ..." + curl -sSL -o /tmp/modconfig.zip "$MODCONFIG" + if [ "$TYPE" = "SPIGOT" ]; then + mkdir -p /data/plugins + unzip -o -d /data/plugins /tmp/modconfig.zip + else + mkdir -p /data/config + unzip -o -d /data/config /tmp/modconfig.zip + fi + rm -f /tmp/modconfig.zip + ;; + *) + echo "Invalid URL given for modconfig: Must be HTTP or HTTPS and a ZIP file" + ;; +esac +fi + +su-exec minecraft /start-finalSetup04ServerProperties $@ diff --git a/minecraft-server/start-finalSetup04ServerProperties.sh b/minecraft-server/start-finalSetup04ServerProperties.sh new file mode 100755 index 00000000..b7112164 --- /dev/null +++ b/minecraft-server/start-finalSetup04ServerProperties.sh @@ -0,0 +1,117 @@ +#!/bin/bash + +# FUNCTIONS +function setServerProp { + local prop=$1 + local var=$2 + if [ -n "$var" ]; then + echo "Setting $prop to $var" + sed -i "/$prop\s*=/ c $prop=$var" /data/server.properties + fi +} + +# Deploy server.properties file +if [ ! -e server.properties ]; then + echo "Creating server.properties" + cp /tmp/server.properties . + + if [ -n "$WHITELIST" ]; then + echo "Creating whitelist" + sed -i "/whitelist\s*=/ c whitelist=true" /data/server.properties + sed -i "/white-list\s*=/ c white-list=true" /data/server.properties + fi + + setServerProp "motd" "$MOTD" + setServerProp "allow-nether" "$ALLOW_NETHER" + setServerProp "announce-player-achievements" "$ANNOUNCE_PLAYER_ACHIEVEMENTS" + setServerProp "enable-command-block" "$ENABLE_COMMAND_BLOCK" + setServerProp "spawn-animals" "$SPAWN_ANIMALS" + setServerProp "spawn-monsters" "$SPAWN_MONSTERS" + setServerProp "spawn-npcs" "$SPAWN_NPCS" + setServerProp "generate-structures" "$GENERATE_STRUCTURES" + setServerProp "view-distance" "$VIEW_DISTANCE" + setServerProp "hardcore" "$HARDCORE" + setServerProp "max-build-height" "$MAX_BUILD_HEIGHT" + setServerProp "force-gamemode" "$FORCE_GAMEMODE" + setServerProp "hardmax-tick-timecore" "$MAX_TICK_TIME" + setServerProp "enable-query" "$ENABLE_QUERY" + setServerProp "query.port" "$QUERY_PORT" + setServerProp "enable-rcon" "$ENABLE_RCON" + setServerProp "rcon.password" "$RCON_PASSWORD" + setServerProp "rcon.port" "$RCON_PORT" + setServerProp "max-players" "$MAX_PLAYERS" + setServerProp "max-world-size" "$MAX_WORLD_SIZE" + setServerProp "level-name" "$LEVEL" + setServerProp "level-seed" "$SEED" + setServerProp "pvp" "$PVP" + setServerProp "generator-settings" "$GENERATOR_SETTINGS" + setServerProp "online-mode" "$ONLINE_MODE" + + if [ -n "$LEVEL_TYPE" ]; then + # normalize to uppercase + LEVEL_TYPE=$( echo ${LEVEL_TYPE} | tr '[:lower:]' '[:upper:]' ) + echo "Setting level type to $LEVEL_TYPE" + # check for valid values and only then set + case $LEVEL_TYPE in + DEFAULT|FLAT|LARGEBIOMES|AMPLIFIED|CUSTOMIZED|BIOMESOP|RTG) + sed -i "/level-type\s*=/ c level-type=$LEVEL_TYPE" /data/server.properties + ;; + *) + echo "Invalid LEVEL_TYPE: $LEVEL_TYPE" + exit 1 + ;; + esac + fi + + if [ -n "$DIFFICULTY" ]; then + case $DIFFICULTY in + peaceful|0) + DIFFICULTY=0 + ;; + easy|1) + DIFFICULTY=1 + ;; + normal|2) + DIFFICULTY=2 + ;; + hard|3) + DIFFICULTY=3 + ;; + *) + echo "DIFFICULTY must be peaceful, easy, normal, or hard." + exit 1 + ;; + esac + echo "Setting difficulty to $DIFFICULTY" + sed -i "/difficulty\s*=/ c difficulty=$DIFFICULTY" /data/server.properties + fi + + if [ -n "$MODE" ]; then + echo "Setting mode" + MODE_LC=$( echo $MODE | tr '[:upper:]' '[:lower:]' ) + case $MODE_LC in + 0|1|2|3) + ;; + su*) + MODE=0 + ;; + c*) + MODE=1 + ;; + a*) + MODE=2 + ;; + sp*) + MODE=3 + ;; + *) + echo "ERROR: Invalid game mode: $MODE" + exit 1 + ;; + esac + + sed -i "/^gamemode\s*=/ c gamemode=$MODE" $SERVER_PROPERTIES + fi +fi + +su-exec minecraft /start-minecraftFinalSetup $@ diff --git a/minecraft-server/start-minecraft.sh b/minecraft-server/start-minecraft.sh deleted file mode 100755 index 82973c5a..00000000 --- a/minecraft-server/start-minecraft.sh +++ /dev/null @@ -1,670 +0,0 @@ -#!/bin/bash - -shopt -s nullglob - -#umask 002 -export HOME=/data - -if [ ! -e /data/eula.txt ]; then - if [ "$EULA" != "" ]; then - echo "# Generated via Docker on $(date)" > eula.txt - echo "eula=$EULA" >> eula.txt - if [ $? != 0 ]; then - echo "ERROR: unable to write eula to /data. Please make sure attached directory is writable by uid=${UID}" - exit 2 - fi - else - echo "" - echo "Please accept the Minecraft EULA at" - echo " https://account.mojang.com/documents/minecraft_eula" - echo "by adding the following immediately after 'docker run':" - echo " -e EULA=TRUE" - echo "" - exit 1 - fi -fi - -if ! touch /data/.verify_access; then - echo "ERROR: /data doesn't seem to be writable. Please make sure attached directory is writable by uid=${UID} " - exit 2 -fi - -SERVER_PROPERTIES=/data/server.properties -FTB_DIR=/data/FeedTheBeast -VERSIONS_JSON=https://launchermeta.mojang.com/mc/game/version_manifest.json - -echo "Checking version information." -case "X$VERSION" in - X|XLATEST|Xlatest) - VANILLA_VERSION=`curl -fsSL $VERSIONS_JSON | jq -r '.latest.release'` - ;; - XSNAPSHOT|Xsnapshot) - VANILLA_VERSION=`curl -fsSL $VERSIONS_JSON | jq -r '.latest.snapshot'` - ;; - X[1-9]*) - VANILLA_VERSION=$VERSION - ;; - *) - VANILLA_VERSION=`curl -fsSL $VERSIONS_JSON | jq -r '.latest.release'` - ;; -esac - -cd /data - -function buildSpigotFromSource { - echo "Building Spigot $VANILLA_VERSION from source, might take a while, get some coffee" - mkdir /data/temp - cd /data/temp - wget -q -P /data/temp https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar && \ - java -jar /data/temp/BuildTools.jar --rev $VANILLA_VERSION 2>&1 |tee /data/spigot_build.log| while read l; do echo -n .; done; echo "done" - mv spigot-*.jar /data/spigot_server.jar - mv craftbukkit-*.jar /data/craftbukkit_server.jar - echo "Cleaning up" - rm -rf /data/temp - cd /data -} - -function downloadSpigot { - local match - case "$TYPE" in - *BUKKIT|*bukkit) - match="Craftbukkit" - downloadUrl=${BUKKIT_DOWNLOAD_URL} - ;; - *) - match="Spigot" - downloadUrl=${SPIGOT_DOWNLOAD_URL} - ;; - esac - - if [[ -z $downloadUrl ]]; then - downloadUrl=$(restify --class=jar-div https://mcadmin.net/ | \ - jq --arg version "$match $VANILLA_VERSION" -r -f /usr/share/mcadmin.jq) - if [[ -z $downloadUrl ]]; then - echo "ERROR: Version $VANILLA_VERSION is not supported for $TYPE" - echo " Refer to https://mcadmin.net/ for supported versions" - exit 2 - fi - fi - - echo "Downloading $match" - curl -kfsSL -o $SERVER "$downloadUrl" - status=$? - if [ ! -f $SERVER ]; then - echo "ERROR: failed to download from $downloadUrl (status=$status)" - exit 3 - fi - -} - -function downloadPaper { - local build - case "$VERSION" in - latest|LATEST|1.10) - build="lastSuccessfulBuild";; - 1.9.4) - build="773";; - 1.9.2) - build="727";; - 1.9) - build="612";; - 1.8.8) - build="443";; - *) - build="nosupp";; - esac - - if [ $build != "nosupp" ]; then - rm $SERVER - downloadUrl=${PAPER_DOWNLOAD_URL:-https://ci.destroystokyo.com/job/PaperSpigot/$build/artifact/paperclip.jar} - curl -fsSL -o $SERVER "$downloadUrl" - if [ ! -f $SERVER ]; then - echo "ERROR: failed to download from $downloadUrl (status=$?)" - exit 3 - fi - else - echo "ERROR: Version $VERSION is not supported for $TYPE" - echo " Refer to https://ci.destroystokyo.com/job/PaperSpigot/" - echo " for supported versions" - exit 2 - fi -} - -function installForge { - TYPE=FORGE - - if [[ -z $FORGE_INSTALLER && -z $FORGE_INSTALLER_URL ]]; then - norm=$VANILLA_VERSION - - case $VANILLA_VERSION in - *.*.*) - norm=$VANILLA_VERSION ;; - *.*) - norm=${VANILLA_VERSION}.0 ;; - esac - - echo "Checking Forge version information." - case $FORGEVERSION in - RECOMMENDED) - curl -fsSL -o /tmp/forge.json http://files.minecraftforge.net/maven/net/minecraftforge/forge/promotions_slim.json - FORGE_VERSION=$(cat /tmp/forge.json | jq -r ".promos[\"$VANILLA_VERSION-recommended\"]") - if [ $FORGE_VERSION = null ]; then - FORGE_VERSION=$(cat /tmp/forge.json | jq -r ".promos[\"$VANILLA_VERSION-latest\"]") - if [ $FORGE_VERSION = null ]; then - echo "ERROR: Version $VANILLA_VERSION is not supported by Forge" - echo " Refer to http://files.minecraftforge.net/ for supported versions" - exit 2 - fi - fi - ;; - - *) - FORGE_VERSION=$FORGEVERSION - ;; - esac - - normForgeVersion=$VANILLA_VERSION-$FORGE_VERSION-$norm - shortForgeVersion=$VANILLA_VERSION-$FORGE_VERSION - - FORGE_INSTALLER="/tmp/forge-$shortForgeVersion-installer.jar" - elif [[ -z $FORGE_INSTALLER ]]; then - FORGE_INSTALLER="/tmp/forge-installer.jar" - elif [[ ! -e $FORGE_INSTALLER ]]; then - echo "ERROR: the given Forge installer doesn't exist : $FORGE_INSTALLER" - exit 2 - fi - - installMarker=".forge-installed-$shortForgeVersion" - - if [ ! -e $installMarker ]; then - if [ ! -e $FORGE_INSTALLER ]; then - - if [[ -z $FORGE_INSTALLER_URL ]]; then - echo "Downloading $normForgeVersion" - - forgeFileNames=" - $normForgeVersion/forge-$normForgeVersion-installer.jar - $shortForgeVersion/forge-$shortForgeVersion-installer.jar - END - " - for fn in $forgeFileNames; do - if [ $fn == END ]; then - echo "Unable to compute URL for $normForgeVersion" - exit 2 - fi - downloadUrl=http://files.minecraftforge.net/maven/net/minecraftforge/forge/$fn - echo "...trying $downloadUrl" - if curl -o $FORGE_INSTALLER -fsSL $downloadUrl; then - break - fi - done - else - echo "Downloading $FORGE_INSTALLER_URL ..." - if ! curl -o $FORGE_INSTALLER -fsSL $FORGE_INSTALLER_URL; then - echo "Failed to download from given location $FORGE_INSTALLER_URL" - exit 2 - fi - fi - fi - - echo "Installing Forge $shortForgeVersion using $FORGE_INSTALLER" - mkdir -p mods - tries=3 - while ((--tries >= 0)); do - java -jar $FORGE_INSTALLER --installServer - if [ $? == 0 ]; then - break - fi - done - if (($tries < 0)); then - echo "Forge failed to install after several tries." >&2 - exit 10 - fi - - # NOTE $shortForgeVersion will be empty if installer location was given to us - echo "Finding installed server jar..." - for j in *forge*.jar; do - echo "...$j" - case $j in - *installer*) - ;; - *) - SERVER=$j - break - ;; - esac - done - if [[ -z $SERVER ]]; then - echo "Unable to derive server jar for Forge" - exit 2 - fi - - echo "Using server $SERVER" - echo $SERVER > $installMarker - - else - SERVER=$(cat $installMarker) - fi -} - -function isURL { - local value=$1 - - if [[ ${value:0:8} == "https://" || ${value:0:7} = "http://" ]]; then - return 0 - else - return 1 - fi -} - -function installFTB { - TYPE=FEED-THE-BEAST - - echo "Looking for Feed-The-Beast server modpack." - if [[ -z $FTB_SERVER_MOD ]]; then - echo "Environment variable FTB_SERVER_MOD not set." - echo "Set FTB_SERVER_MOD to the file name of the FTB server modpack." - echo "(And place the modpack in the /data directory.)" - exit 2 - fi - local srv_modpack=${FTB_SERVER_MOD} - if isURL ${srv_modpack}; then - case $srv_modpack in - https://www.feed-the-beast.com/*/download) - break;; - https://www.feed-the-beast.com/*) - srv_modpack=${srv_modpack}/download;; - esac - local file=$(basename $(dirname $srv_modpack)) - local downloaded=/data/${file}.zip - if [ ! -e $downloaded ]; then - echo "Downloading FTB modpack... - $srv_modpack -> $downloaded" - curl -sSL -o $downloaded $srv_modpack - fi - srv_modpack=$downloaded - fi - if [[ ${srv_modpack:0:5} == "data/" ]]; then - # Prepend with "/" - srv_modpack=/${srv_modpack} - fi - if [[ ! ${srv_modpack:0:1} == "/" ]]; then - # If not an absolute path, assume file is in "/data" - srv_modpack=/data/${srv_modpack} - fi - if [[ ! -f ${srv_modpack} ]]; then - echo "FTB server modpack ${srv_modpack} not found." - exit 2 - fi - if [[ ! ${srv_modpack: -4} == ".zip" ]]; then - echo "FTB server modpack ${srv_modpack} is not a zip archive." - echo "Please set FTB_SERVER_MOD to a file with a .zip extension." - exit 2 - fi - - if [ ! -d ${FTB_DIR} ]; then - echo "Unpacking FTB server modpack ${srv_modpack} ..." - mkdir -p ${FTB_DIR} - unzip -o ${srv_modpack} -d ${FTB_DIR} - cp -f /data/eula.txt ${FTB_DIR}/eula.txt - fi - FTB_SERVER_START=${FTB_DIR}/ServerStart.sh - chmod a+x ${FTB_SERVER_START} - sed -i "s/-jar/-Dfml.queryResult=confirm -jar/" ${FTB_SERVER_START} -} - -function installVanilla { - SERVER="minecraft_server.$VANILLA_VERSION.jar" - - if [ ! -e $SERVER ]; then - echo "Downloading $SERVER ..." - wget -q https://s3.amazonaws.com/Minecraft.Download/versions/$VANILLA_VERSION/$SERVER - fi -} - -echo "Checking type information." -case "$TYPE" in - *BUKKIT|*bukkit|SPIGOT|spigot) - case "$TYPE" in - *BUKKIT|*bukkit) - SERVER=craftbukkit_server.jar - ;; - *) - SERVER=spigot_server.jar - ;; - esac - - if [ ! -f $SERVER ]; then - if [[ "$BUILD_SPIGOT_FROM_SOURCE" = TRUE || "$BUILD_SPIGOT_FROM_SOURCE" = true || "$BUILD_FROM_SOURCE" = TRUE || "$BUILD_FROM_SOURCE" = true ]]; then - buildSpigotFromSource - else - downloadSpigot - fi - fi - # normalize on Spigot for operations below - TYPE=SPIGOT - ;; - - PAPER|paper) - SERVER=paper_server.jar - if [ ! -f $SERVER ]; then - downloadPaper - fi - # normalize on Spigot for operations below - TYPE=SPIGOT - ;; - - FORGE|forge) - TYPE=FORGE - installForge - ;; - - FTB|ftb) - TYPE=FEED-THE-BEAST - installFTB - ;; - - VANILLA|vanilla) - installVanilla - ;; - - *) - echo "Invalid type: '$TYPE'" - echo "Must be: VANILLA, FORGE, SPIGOT" - exit 1 - ;; - -esac - - -# If supplied with a URL for a world, download it and unpack -if [[ "$WORLD" ]]; then -case "X$WORLD" in - X[Hh][Tt][Tt][Pp]*) - echo "Downloading world via HTTP" - echo "$WORLD" - wget -q -O - "$WORLD" > /data/world.zip - echo "Unzipping word" - unzip -q /data/world.zip - rm -f /data/world.zip - if [ ! -d /data/world ]; then - echo World directory not found - for i in /data/*/level.dat; do - if [ -f "$i" ]; then - d=`dirname "$i"` - echo Renaming world directory from $d - mv -f "$d" /data/world - fi - done - fi - if [ "$TYPE" = "SPIGOT" ]; then - # Reorganise if a Spigot server - echo "Moving End and Nether maps to Spigot location" - [ -d "/data/world/DIM1" ] && mv -f "/data/world/DIM1" "/data/world_the_end" - [ -d "/data/world/DIM-1" ] && mv -f "/data/world/DIM-1" "/data/world_nether" - fi - ;; - *) - echo "Invalid URL given for world: Must be HTTP or HTTPS and a ZIP file" - ;; -esac -fi - -# If supplied with a URL for a modpack (simple zip of jars), download it and unpack -if [[ "$MODPACK" ]]; then -case "X$MODPACK" in - X[Hh][Tt][Tt][Pp]*.zip) - echo "Downloading mod/plugin pack via HTTP" - echo " from $MODPACK ..." - if ! curl -sSL -o /tmp/modpack.zip "$MODPACK"; then - echo "ERROR: failed to download from $MODPACK" - exit 2 - fi - - if [ "$TYPE" = "SPIGOT" ]; then - if [ "$REMOVE_OLD_MODS" = "TRUE" ]; then - rm -rf /data/plugins/* - fi - mkdir -p /data/plugins - if ! unzip -o -d /data/plugins /tmp/modpack.zip; then - echo "ERROR: failed to unzip the modpack from $MODPACK" - fi - else - if [ "$REMOVE_OLD_MODS" = "TRUE" ]; then - rm -rf /data/mods/* - fi - mkdir -p /data/mods - if ! unzip -o -d /data/mods /tmp/modpack.zip; then - echo "ERROR: failed to unzip the modpack from $MODPACK" - fi - fi - rm -f /tmp/modpack.zip - ;; - *) - echo "Invalid URL given for modpack: Must be HTTP or HTTPS and a ZIP file" - ;; -esac -fi - -# If supplied with a URL for a config (simple zip of configurations), download it and unpack -if [[ "$MODCONFIG" ]]; then -case "X$MODCONFIG" in - X[Hh][Tt][Tt][Pp]*[Zz][iI][pP]) - echo "Downloading mod/plugin configs via HTTP" - echo " from $MODCONFIG ..." - curl -sSL -o /tmp/modconfig.zip "$MODCONFIG" - if [ "$TYPE" = "SPIGOT" ]; then - mkdir -p /data/plugins - unzip -o -d /data/plugins /tmp/modconfig.zip - else - mkdir -p /data/config - unzip -o -d /data/config /tmp/modconfig.zip - fi - rm -f /tmp/modconfig.zip - ;; - *) - echo "Invalid URL given for modconfig: Must be HTTP or HTTPS and a ZIP file" - ;; -esac -fi - -function setServerProp { - local prop=$1 - local var=$2 - if [ -n "$var" ]; then - echo "Setting $prop to $var" - sed -i "/$prop\s*=/ c $prop=$var" /data/server.properties - fi - -} - -if [ ! -e server.properties ]; then - echo "Creating server.properties" - cp /tmp/server.properties . - - if [ -n "$WHITELIST" ]; then - echo "Creating whitelist" - sed -i "/whitelist\s*=/ c whitelist=true" /data/server.properties - sed -i "/white-list\s*=/ c white-list=true" /data/server.properties - fi - - setServerProp "motd" "$MOTD" - setServerProp "allow-nether" "$ALLOW_NETHER" - setServerProp "announce-player-achievements" "$ANNOUNCE_PLAYER_ACHIEVEMENTS" - setServerProp "enable-command-block" "$ENABLE_COMMAND_BLOCK" - setServerProp "spawn-animals" "$SPAWN_ANIMALS" - setServerProp "spawn-monsters" "$SPAWN_MONSTERS" - setServerProp "spawn-npcs" "$SPAWN_NPCS" - setServerProp "generate-structures" "$GENERATE_STRUCTURES" - setServerProp "view-distance" "$VIEW_DISTANCE" - setServerProp "hardcore" "$HARDCORE" - setServerProp "max-build-height" "$MAX_BUILD_HEIGHT" - setServerProp "force-gamemode" "$FORCE_GAMEMODE" - setServerProp "hardmax-tick-timecore" "$MAX_TICK_TIME" - setServerProp "enable-query" "$ENABLE_QUERY" - setServerProp "query.port" "$QUERY_PORT" - setServerProp "enable-rcon" "$ENABLE_RCON" - setServerProp "rcon.password" "$RCON_PASSWORD" - setServerProp "rcon.port" "$RCON_PORT" - setServerProp "max-players" "$MAX_PLAYERS" - setServerProp "max-world-size" "$MAX_WORLD_SIZE" - setServerProp "level-name" "$LEVEL" - setServerProp "level-seed" "$SEED" - setServerProp "pvp" "$PVP" - setServerProp "generator-settings" "$GENERATOR_SETTINGS" - setServerProp "online-mode" "$ONLINE_MODE" - - if [ -n "$LEVEL_TYPE" ]; then - # normalize to uppercase - LEVEL_TYPE=$( echo ${LEVEL_TYPE} | tr '[:lower:]' '[:upper:]' ) - echo "Setting level type to $LEVEL_TYPE" - # check for valid values and only then set - case $LEVEL_TYPE in - DEFAULT|FLAT|LARGEBIOMES|AMPLIFIED|CUSTOMIZED|BIOMESOP|RTG) - sed -i "/level-type\s*=/ c level-type=$LEVEL_TYPE" /data/server.properties - ;; - *) - echo "Invalid LEVEL_TYPE: $LEVEL_TYPE" - exit 1 - ;; - esac - fi - - if [ -n "$DIFFICULTY" ]; then - case $DIFFICULTY in - peaceful|0) - DIFFICULTY=0 - ;; - easy|1) - DIFFICULTY=1 - ;; - normal|2) - DIFFICULTY=2 - ;; - hard|3) - DIFFICULTY=3 - ;; - *) - echo "DIFFICULTY must be peaceful, easy, normal, or hard." - exit 1 - ;; - esac - echo "Setting difficulty to $DIFFICULTY" - sed -i "/difficulty\s*=/ c difficulty=$DIFFICULTY" /data/server.properties - fi - - if [ -n "$MODE" ]; then - echo "Setting mode" - MODE_LC=$( echo $MODE | tr '[:upper:]' '[:lower:]' ) - case $MODE_LC in - 0|1|2|3) - ;; - su*) - MODE=0 - ;; - c*) - MODE=1 - ;; - a*) - MODE=2 - ;; - sp*) - MODE=3 - ;; - *) - echo "ERROR: Invalid game mode: $MODE" - exit 1 - ;; - esac - - sed -i "/^gamemode\s*=/ c gamemode=$MODE" $SERVER_PROPERTIES - fi -fi - - -if [ -n "$OPS" -a ! -e ops.txt.converted ]; then - echo "Setting ops" - echo $OPS | awk -v RS=, '{print}' >> ops.txt -fi - -if [ -n "$WHITELIST" -a ! -e white-list.txt.converted ]; then - echo "Setting whitelist" - echo $WHITELIST | awk -v RS=, '{print}' >> white-list.txt -fi - -if [ -n "$ICON" -a ! -e server-icon.png ]; then - echo "Using server icon from $ICON..." - # Not sure what it is yet...call it "img" - wget -q -O /tmp/icon.img $ICON - specs=$(identify /tmp/icon.img | awk '{print $2,$3}') - if [ "$specs" = "PNG 64x64" ]; then - mv /tmp/icon.img /data/server-icon.png - else - echo "Converting image to 64x64 PNG..." - convert /tmp/icon.img -resize 64x64! /data/server-icon.png - fi -fi - -# Make sure files exist and are valid JSON (for pre-1.12 to 1.12 upgrades) -for j in *.json; do - if [[ $(python -c "print open('$j').read().strip()==''") = True ]]; then - echo "Fixing JSON $j" - echo '[]' > $j - fi -done - -# If any modules have been provided, copy them over -mkdir -p /data/mods -for m in /mods/*.{jar,zip} -do - if [ -f "$m" -a ! -f "/data/mods/$m" ]; then - echo Copying mod `basename "$m"` - cp "$m" /data/mods - fi -done -[ -d /data/config ] || mkdir /data/config -for c in /config/* -do - if [ -f "$c" ]; then - echo Copying configuration `basename "$c"` - cp -rf "$c" /data/config - fi -done - -if [ "$TYPE" = "SPIGOT" ]; then - if [ -d /plugins ]; then - echo Copying any Bukkit plugins over - cp -r /plugins /data - fi -fi - -EXTRA_ARGS="" -# Optional disable console -if [[ ${CONSOLE} = false || ${CONSOLE} = FALSE ]]; then - EXTRA_ARGS+="--noconsole" -fi - -# Optional disable GUI for headless servers -if [[ ${GUI} = false || ${GUI} = FALSE ]]; then - EXTRA_ARGS="${EXTRA_ARGS} nogui" -fi - -# put these prior JVM_OPTS at the end to give any memory settings there higher precedence -echo "Setting initial memory to ${INIT_MEMORY:-${MEMORY}} and max to ${MAX_MEMORY:-${MEMORY}}" -JVM_OPTS="-Xms${INIT_MEMORY:-${MEMORY}} -Xmx${MAX_MEMORY:-${MEMORY}} ${JVM_OPTS}" - -if [[ ${TYPE} == "FEED-THE-BEAST" ]]; then - cp -f $SERVER_PROPERTIES ${FTB_DIR}/server.properties - cp -f /data/{eula,ops,white-list}.txt ${FTB_DIR}/ - cd ${FTB_DIR} - echo "Running FTB server modpack start ..." - exec ${FTB_SERVER_START} -else - # If we have a bootstrap.txt file... feed that in to the server stdin - if [ -f /data/bootstrap.txt ]; - then - exec java $JVM_XX_OPTS $JVM_OPTS -jar $SERVER "$@" $EXTRA_ARGS < /data/bootstrap.txt - else - exec java $JVM_XX_OPTS $JVM_OPTS -jar $SERVER "$@" $EXTRA_ARGS - fi -fi diff --git a/minecraft-server/start-minecraftFinalSetup.sh b/minecraft-server/start-minecraftFinalSetup.sh new file mode 100755 index 00000000..dba9ad33 --- /dev/null +++ b/minecraft-server/start-minecraftFinalSetup.sh @@ -0,0 +1,88 @@ +#!/bin/bash + +if [ -n "$OPS" -a ! -e ops.txt.converted ]; then + echo "Setting ops" + echo $OPS | awk -v RS=, '{print}' >> ops.txt +fi + +if [ -n "$WHITELIST" -a ! -e white-list.txt.converted ]; then + echo "Setting whitelist" + echo $WHITELIST | awk -v RS=, '{print}' >> white-list.txt +fi + +if [ -n "$ICON" -a ! -e server-icon.png ]; then + echo "Using server icon from $ICON..." + # Not sure what it is yet...call it "img" + wget -q -O /tmp/icon.img $ICON + specs=$(identify /tmp/icon.img | awk '{print $2,$3}') + if [ "$specs" = "PNG 64x64" ]; then + mv /tmp/icon.img /data/server-icon.png + else + echo "Converting image to 64x64 PNG..." + convert /tmp/icon.img -resize 64x64! /data/server-icon.png + fi +fi + +# Make sure files exist and are valid JSON (for pre-1.12 to 1.12 upgrades) +for j in *.json; do + if [[ $(python -c "print open('$j').read().strip()==''") = True ]]; then + echo "Fixing JSON $j" + echo '[]' > $j + fi +done + +# If any modules have been provided, copy them over +mkdir -p /data/mods +for m in /mods/*.{jar,zip} +do + if [ -f "$m" -a ! -f "/data/mods/$m" ]; then + echo Copying mod `basename "$m"` + cp "$m" /data/mods + fi +done +[ -d /data/config ] || mkdir /data/config +for c in /config/* +do + if [ -f "$c" ]; then + echo Copying configuration `basename "$c"` + cp -rf "$c" /data/config + fi +done + +if [ "$TYPE" = "SPIGOT" ]; then + if [ -d /plugins ]; then + echo Copying any Bukkit plugins over + cp -r /plugins /data + fi +fi + +EXTRA_ARGS="" +# Optional disable console +if [[ ${CONSOLE} = false || ${CONSOLE} = FALSE ]]; then + EXTRA_ARGS+="--noconsole" +fi + +# Optional disable GUI for headless servers +if [[ ${GUI} = false || ${GUI} = FALSE ]]; then + EXTRA_ARGS="${EXTRA_ARGS} nogui" +fi + +# put these prior JVM_OPTS at the end to give any memory settings there higher precedence +echo "Setting initial memory to ${INIT_MEMORY:-${MEMORY}} and max to ${MAX_MEMORY:-${MEMORY}}" +JVM_OPTS="-Xms${INIT_MEMORY:-${MEMORY}} -Xmx${MAX_MEMORY:-${MEMORY}} ${JVM_OPTS}" + +if [[ ${TYPE} == "FEED-THE-BEAST" ]]; then + cp -f $SERVER_PROPERTIES ${FTB_DIR}/server.properties + cp -f /data/{eula,ops,white-list}.txt ${FTB_DIR}/ + cd ${FTB_DIR} + echo "Running FTB server modpack start ..." + exec ${FTB_SERVER_START} +else + # If we have a bootstrap.txt file... feed that in to the server stdin + if [ -f /data/bootstrap.txt ]; + then + exec java $JVM_XX_OPTS $JVM_OPTS -jar $SERVER "$@" $EXTRA_ARGS < /data/bootstrap.txt + else + exec java $JVM_XX_OPTS $JVM_OPTS -jar $SERVER "$@" $EXTRA_ARGS + fi +fi diff --git a/minecraft-server/start.sh b/minecraft-server/start.sh index 6081255d..51f0443c 100755 --- a/minecraft-server/start.sh +++ b/minecraft-server/start.sh @@ -19,4 +19,4 @@ if [ "$SKIP_OWNERSHIP_FIX" != "TRUE" ]; then fi echo "Switching to user 'minecraft'" -su-exec minecraft /start-minecraft $@ +su-exec minecraft /start-configuration $@ From 0c1c6d198c83f21f02f6717cf22e0152abe1cedf Mon Sep 17 00:00:00 2001 From: Aitor Ramos Sasselli Date: Wed, 1 Nov 2017 06:41:55 +0100 Subject: [PATCH 2/3] Repaired some bugs from refactor --- minecraft-server/Dockerfile | 17 +-- minecraft-server/start-configuration.sh | 82 ------------ minecraft-server/start-deployBukkitSpigot.sh | 71 ----------- minecraft-server/start-deployFTB.sh | 68 ---------- minecraft-server/start-deployForge.sh | 118 ------------------ minecraft-server/start-deployPaper.sh | 41 ------ minecraft-server/start-deployVanilla.sh | 11 -- minecraft-server/start-finalSetup01World.sh | 36 ------ minecraft-server/start-finalSetup02Modpack.sh | 39 ------ .../start-finalSetup03Modconfig.sh | 25 ---- .../start-finalSetup04ServerProperties.sh | 117 ----------------- minecraft-server/start-minecraftFinalSetup.sh | 88 ------------- minecraft-server/start.sh | 22 ---- 13 files changed, 3 insertions(+), 732 deletions(-) delete mode 100755 minecraft-server/start-configuration.sh delete mode 100755 minecraft-server/start-deployBukkitSpigot.sh delete mode 100755 minecraft-server/start-deployFTB.sh delete mode 100755 minecraft-server/start-deployForge.sh delete mode 100755 minecraft-server/start-deployPaper.sh delete mode 100755 minecraft-server/start-deployVanilla.sh delete mode 100755 minecraft-server/start-finalSetup01World.sh delete mode 100755 minecraft-server/start-finalSetup02Modpack.sh delete mode 100755 minecraft-server/start-finalSetup03Modconfig.sh delete mode 100755 minecraft-server/start-finalSetup04ServerProperties.sh delete mode 100755 minecraft-server/start-minecraftFinalSetup.sh delete mode 100755 minecraft-server/start.sh diff --git a/minecraft-server/Dockerfile b/minecraft-server/Dockerfile index ada7d62b..bd14043c 100644 --- a/minecraft-server/Dockerfile +++ b/minecraft-server/Dockerfile @@ -31,18 +31,7 @@ EXPOSE 25565 25575 ADD https://github.com/itzg/restify/releases/download/1.0.4/restify_linux_amd64 /usr/local/bin/restify ADD https://github.com/itzg/rcon-cli/releases/download/1.3/rcon-cli_linux_amd64 /usr/local/bin/rcon-cli -COPY start.sh /start -COPY start-configuration.sh /start-configuration -COPY start-deployVanilla.sh /start-deployVanilla -COPY start-deployForge.sh /start-deployForge -COPY start-deployBukkitSpigot.sh /start-deployBukkitSpigot -COPY start-deployPaper.sh /start-deployPaper -COPY start-deployFTB.sh /start-deployFTB -COPY start-finalSetup01World.sh /start-finalSetup01World -COPY start-finalSetup02Modpack.sh /start-finalSetup02Modpack -COPY start-finalSetup03Modconfig.sh /start-finalSetup03Modconfig -COPY start-finalSetup04ServerProperties.sh /start-finalSetup04ServerProperties -COPY start-minecraftFinalSetup.sh /start-minecraftFinalSetup +COPY start* / COPY mcadmin.jq /usr/share RUN chmod +x /usr/local/bin/* @@ -55,6 +44,6 @@ ENTRYPOINT [ "/start" ] ENV UID=1000 GID=1000 \ MOTD="A Minecraft Server Powered by Docker" \ JVM_XX_OPTS="-XX:+UseG1GC" MEMORY="1G" \ - TYPE=VANILLA VERSION=LATEST FORGEVERSION=RECOMMENDED LEVEL=world PVP=true DIFFICULTY=easy \ - ENABLE_RCON=true RCON_PORT=25575 RCON_PASSWORD=minecraft \ + TYPE=VANILLA VERSION=LATEST FORGEVERSION=RECOMMENDED SPONGEBRANCH=STABLE LEVEL=world PVP=true \ + DIFFICULTY=easy ENABLE_RCON=true RCON_PORT=25575 RCON_PASSWORD=minecraft \ LEVEL_TYPE=DEFAULT GENERATOR_SETTINGS= WORLD= MODPACK= ONLINE_MODE=TRUE CONSOLE=true diff --git a/minecraft-server/start-configuration.sh b/minecraft-server/start-configuration.sh deleted file mode 100755 index b799eedc..00000000 --- a/minecraft-server/start-configuration.sh +++ /dev/null @@ -1,82 +0,0 @@ -#!/bin/bash - -shopt -s nullglob - -#umask 002 -export HOME=/data - -if [ ! -e /data/eula.txt ]; then - if [ "$EULA" != "" ]; then - echo "# Generated via Docker on $(date)" > eula.txt - echo "eula=$EULA" >> eula.txt - if [ $? != 0 ]; then - echo "ERROR: unable to write eula to /data. Please make sure attached directory is writable by uid=${UID}" - exit 2 - fi - else - echo "" - echo "Please accept the Minecraft EULA at" - echo " https://account.mojang.com/documents/minecraft_eula" - echo "by adding the following immediately after 'docker run':" - echo " -e EULA=TRUE" - echo "" - exit 1 - fi -fi - -if ! touch /data/.verify_access; then - echo "ERROR: /data doesn't seem to be writable. Please make sure attached directory is writable by uid=${UID} " - exit 2 -fi - -export SERVER_PROPERTIES=/data/server.properties -export FTB_DIR=/data/FeedTheBeast -export VERSIONS_JSON=https://launchermeta.mojang.com/mc/game/version_manifest.json - -echo "Checking version information." -case "X$VERSION" in - X|XLATEST|Xlatest) - export VANILLA_VERSION=`curl -fsSL $VERSIONS_JSON | jq -r '.latest.release'` - ;; - XSNAPSHOT|Xsnapshot) - export VANILLA_VERSION=`curl -fsSL $VERSIONS_JSON | jq -r '.latest.snapshot'` - ;; - X[1-9]*) - export VANILLA_VERSION=$VERSION - ;; - *) - export VANILLA_VERSION=`curl -fsSL $VERSIONS_JSON | jq -r '.latest.release'` - ;; -esac - -cd /data - -echo "Checking type information." -case "$TYPE" in - *BUKKIT|*bukkit|SPIGOT|spigot) - su-exec minecraft /start-deployBukkitSpigot $@ - ;; - - PAPER|paper) - su-exec minecraft /start-deployPaper $@ - ;; - - FORGE|forge) - su-exec minecraft /start-deployForge $@ - ;; - - FTB|ftb) - su-exec minecraft /start-deployFTB $@ - ;; - - VANILLA|vanilla) - su-exec minecraft /start-deployVanilla $@ - ;; - - *) - echo "Invalid type: '$TYPE'" - echo "Must be: VANILLA, FORGE, BUKKIT, SPIGOT, PAPER, FTB" - exit 1 - ;; - -esac diff --git a/minecraft-server/start-deployBukkitSpigot.sh b/minecraft-server/start-deployBukkitSpigot.sh deleted file mode 100755 index 681fe629..00000000 --- a/minecraft-server/start-deployBukkitSpigot.sh +++ /dev/null @@ -1,71 +0,0 @@ -#!/bin/bash - -function buildSpigotFromSource { - echo "Building Spigot $VANILLA_VERSION from source, might take a while, get some coffee" - mkdir /data/temp - cd /data/temp - wget -q -P /data/temp https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar && \ - java -jar /data/temp/BuildTools.jar --rev $VANILLA_VERSION 2>&1 |tee /data/spigot_build.log| while read l; do echo -n .; done; echo "done" - mv spigot-*.jar /data/spigot_server.jar - mv craftbukkit-*.jar /data/craftbukkit_server.jar - echo "Cleaning up" - rm -rf /data/temp - cd /data -} - -function downloadSpigot { - local match - case "$TYPE" in - *BUKKIT|*bukkit) - match="Craftbukkit" - downloadUrl=${BUKKIT_DOWNLOAD_URL} - ;; - *) - match="Spigot" - downloadUrl=${SPIGOT_DOWNLOAD_URL} - ;; - esac - - if [[ -z $downloadUrl ]]; then - downloadUrl=$(restify --class=jar-div https://mcadmin.net/ | \ - jq --arg version "$match $VANILLA_VERSION" -r -f /usr/share/mcadmin.jq) - if [[ -z $downloadUrl ]]; then - echo "ERROR: Version $VANILLA_VERSION is not supported for $TYPE" - echo " Refer to https://mcadmin.net/ for supported versions" - exit 2 - fi - fi - - echo "Downloading $match" - curl -kfsSL -o $SERVER "$downloadUrl" - status=$? - if [ ! -f $SERVER ]; then - echo "ERROR: failed to download from $downloadUrl (status=$status)" - exit 3 - fi - -} - - -case "$TYPE" in - *BUKKIT|*bukkit) - export SERVER=craftbukkit_server.jar - ;; - *) - export SERVER=spigot_server.jar - ;; -esac - -if [ ! -f $SERVER ]; then - if [[ "$BUILD_SPIGOT_FROM_SOURCE" = TRUE || "$BUILD_SPIGOT_FROM_SOURCE" = true || "$BUILD_FROM_SOURCE" = TRUE || "$BUILD_FROM_SOURCE" = true ]]; then - buildSpigotFromSource - else - downloadSpigot - fi -fi - -# Normalize on Spigot for operations below -export TYPE=SPIGOT - -# Continue to Final Setup -su-exec minecraft /start-finalSetup01World $@ diff --git a/minecraft-server/start-deployFTB.sh b/minecraft-server/start-deployFTB.sh deleted file mode 100755 index 12cbfbf8..00000000 --- a/minecraft-server/start-deployFTB.sh +++ /dev/null @@ -1,68 +0,0 @@ -#!/bin/bash - -export TYPE=FEED-THE-BEAST - -function isURL { - local value=$1 - - if [[ ${value:0:8} == "https://" || ${value:0:7} = "http://" ]]; then - return 0 - else - return 1 - fi -} - -echo "Looking for Feed-The-Beast server modpack." -if [[ -z $FTB_SERVER_MOD ]]; then - echo "Environment variable FTB_SERVER_MOD not set." - echo "Set FTB_SERVER_MOD to the file name of the FTB server modpack." - echo "(And place the modpack in the /data directory.)" - exit 2 -fi -srv_modpack=${FTB_SERVER_MOD} -if isURL ${srv_modpack}; then - case $srv_modpack in - https://www.feed-the-beast.com/*/download) - break;; - https://www.feed-the-beast.com/*) - srv_modpack=${srv_modpack}/download;; - esac - file=$(basename $(dirname $srv_modpack)) - downloaded=/data/${file}.zip - if [ ! -e $downloaded ]; then - echo "Downloading FTB modpack... -$srv_modpack -> $downloaded" - curl -sSL -o $downloaded $srv_modpack - fi - srv_modpack=$downloaded -fi -if [[ ${srv_modpack:0:5} == "data/" ]]; then - # Prepend with "/" - srv_modpack=/${srv_modpack} -fi -if [[ ! ${srv_modpack:0:1} == "/" ]]; then - # If not an absolute path, assume file is in "/data" - srv_modpack=/data/${srv_modpack} -fi -if [[ ! -f ${srv_modpack} ]]; then - echo "FTB server modpack ${srv_modpack} not found." - exit 2 -fi -if [[ ! ${srv_modpack: -4} == ".zip" ]]; then - echo "FTB server modpack ${srv_modpack} is not a zip archive." - echo "Please set FTB_SERVER_MOD to a file with a .zip extension." - exit 2 -fi - -if [ ! -d ${FTB_DIR} ]; then - echo "Unpacking FTB server modpack ${srv_modpack} ..." - mkdir -p ${FTB_DIR} - unzip -o ${srv_modpack} -d ${FTB_DIR} - cp -f /data/eula.txt ${FTB_DIR}/eula.txt -fi -export FTB_SERVER_START=${FTB_DIR}/ServerStart.sh -chmod a+x ${FTB_SERVER_START} -sed -i "s/-jar/-Dfml.queryResult=confirm -jar/" ${FTB_SERVER_START} - -# Continue to Final Setup -su-exec minecraft /start-finalSetup01World $@ diff --git a/minecraft-server/start-deployForge.sh b/minecraft-server/start-deployForge.sh deleted file mode 100755 index eecb8e1e..00000000 --- a/minecraft-server/start-deployForge.sh +++ /dev/null @@ -1,118 +0,0 @@ -#!/bin/bash - -export TYPE=FORGE - -if [[ -z $FORGE_INSTALLER && -z $FORGE_INSTALLER_URL ]]; then - norm=$VANILLA_VERSION - - case $VANILLA_VERSION in - *.*.*) - norm=$VANILLA_VERSION ;; - *.*) - norm=${VANILLA_VERSION}.0 ;; - esac - - echo "Checking Forge version information." - case $FORGEVERSION in - RECOMMENDED) - curl -fsSL -o /tmp/forge.json http://files.minecraftforge.net/maven/net/minecraftforge/forge/promotions_slim.json - FORGE_VERSION=$(cat /tmp/forge.json | jq -r ".promos[\"$VANILLA_VERSION-recommended\"]") - if [ $FORGE_VERSION = null ]; then - FORGE_VERSION=$(cat /tmp/forge.json | jq -r ".promos[\"$VANILLA_VERSION-latest\"]") - if [ $FORGE_VERSION = null ]; then - echo "ERROR: Version $VANILLA_VERSION is not supported by Forge" - echo " Refer to http://files.minecraftforge.net/ for supported versions" - exit 2 - fi - fi - ;; - - *) - FORGE_VERSION=$FORGEVERSION - ;; - esac - - normForgeVersion=$VANILLA_VERSION-$FORGE_VERSION-$norm - shortForgeVersion=$VANILLA_VERSION-$FORGE_VERSION - - FORGE_INSTALLER="/tmp/forge-$shortForgeVersion-installer.jar" -elif [[ -z $FORGE_INSTALLER ]]; then - FORGE_INSTALLER="/tmp/forge-installer.jar" -elif [[ ! -e $FORGE_INSTALLER ]]; then - echo "ERROR: the given Forge installer doesn't exist : $FORGE_INSTALLER" - exit 2 -fi - -installMarker=".forge-installed-$shortForgeVersion" - -if [ ! -e $installMarker ]; then - if [ ! -e $FORGE_INSTALLER ]; then - - if [[ -z $FORGE_INSTALLER_URL ]]; then - echo "Downloading $normForgeVersion" - - forgeFileNames=" - $normForgeVersion/forge-$normForgeVersion-installer.jar - $shortForgeVersion/forge-$shortForgeVersion-installer.jar - END - " - for fn in $forgeFileNames; do - if [ $fn == END ]; then - echo "Unable to compute URL for $normForgeVersion" - exit 2 - fi - downloadUrl=http://files.minecraftforge.net/maven/net/minecraftforge/forge/$fn - echo "...trying $downloadUrl" - if curl -o $FORGE_INSTALLER -fsSL $downloadUrl; then - break - fi - done - else - echo "Downloading $FORGE_INSTALLER_URL ..." - if ! curl -o $FORGE_INSTALLER -fsSL $FORGE_INSTALLER_URL; then - echo "Failed to download from given location $FORGE_INSTALLER_URL" - exit 2 - fi - fi - fi - - echo "Installing Forge $shortForgeVersion using $FORGE_INSTALLER" - mkdir -p mods - tries=3 - while ((--tries >= 0)); do - java -jar $FORGE_INSTALLER --installServer - if [ $? == 0 ]; then - break - fi - done - if (($tries < 0)); then - echo "Forge failed to install after several tries." >&2 - exit 10 - fi - # NOTE $shortForgeVersion will be empty if installer location was given to us - echo "Finding installed server jar..." - for j in *forge*.jar; do - echo "...$j" - case $j in - *installer*) - ;; - *) - export SERVER=$j - break - ;; - esac - done - if [[ -z $SERVER ]]; then - echo "Unable to derive server jar for Forge" - exit 2 - fi - - echo "Using server $SERVER" - echo $SERVER > $installMarker - -else - export SERVER=$(cat $installMarker) -fi - -# Continue to Final Setup -su-exec minecraft /start-finalSetup01World $@ diff --git a/minecraft-server/start-deployPaper.sh b/minecraft-server/start-deployPaper.sh deleted file mode 100755 index 06f9b8fc..00000000 --- a/minecraft-server/start-deployPaper.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/bash - -export SERVER=paper_server.jar -if [ ! -f $SERVER ]; then - local build - case "$VERSION" in - latest|LATEST|1.10) - build="lastSuccessfulBuild";; - 1.9.4) - build="773";; - 1.9.2) - build="727";; - 1.9) - build="612";; - 1.8.8) - build="443";; - *) - build="nosupp";; - esac - - if [ $build != "nosupp" ]; then - rm $SERVER - downloadUrl=${PAPER_DOWNLOAD_URL:-https://ci.destroystokyo.com/job/PaperSpigot/$build/artifact/paperclip.jar} - curl -fsSL -o $SERVER "$downloadUrl" - if [ ! -f $SERVER ]; then - echo "ERROR: failed to download from $downloadUrl (status=$?)" - exit 3 - fi - else - echo "ERROR: Version $VERSION is not supported for $TYPE" - echo " Refer to https://ci.destroystokyo.com/job/PaperSpigot/" - echo " for supported versions" - exit 2 - fi -fi - -# Normalize on Spigot for operations below -export TYPE=SPIGOT - -# Continue to Final Setup -su-exec minecraft /start-finalSetup01World $@ diff --git a/minecraft-server/start-deployVanilla.sh b/minecraft-server/start-deployVanilla.sh deleted file mode 100755 index de7aee1c..00000000 --- a/minecraft-server/start-deployVanilla.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -export SERVER="minecraft_server.$VANILLA_VERSION.jar" - -if [ ! -e $SERVER ]; then - echo "Downloading $SERVER ..." - wget -q https://s3.amazonaws.com/Minecraft.Download/versions/$VANILLA_VERSION/$SERVER -fi - -# Continue to Final Setup -su-exec minecraft /start-finalSetup01World $@ diff --git a/minecraft-server/start-finalSetup01World.sh b/minecraft-server/start-finalSetup01World.sh deleted file mode 100755 index 02338abd..00000000 --- a/minecraft-server/start-finalSetup01World.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/bash - -# If supplied with a URL for a world, download it and unpack -if [[ "$WORLD" ]]; then -case "X$WORLD" in - X[Hh][Tt][Tt][Pp]*) - echo "Downloading world via HTTP" - echo "$WORLD" - wget -q -O - "$WORLD" > /data/world.zip - echo "Unzipping word" - unzip -q /data/world.zip - rm -f /data/world.zip - if [ ! -d /data/world ]; then - echo World directory not found - for i in /data/*/level.dat; do - if [ -f "$i" ]; then - d=`dirname "$i"` - echo Renaming world directory from $d - mv -f "$d" /data/world - fi - done - fi - if [ "$TYPE" = "SPIGOT" ]; then - # Reorganise if a Spigot server - echo "Moving End and Nether maps to Spigot location" - [ -d "/data/world/DIM1" ] && mv -f "/data/world/DIM1" "/data/world_the_end" - [ -d "/data/world/DIM-1" ] && mv -f "/data/world/DIM-1" "/data/world_nether" - fi - ;; - *) - echo "Invalid URL given for world: Must be HTTP or HTTPS and a ZIP file" - ;; -esac -fi - -su-exec minecraft /start-finalSetup02Modpack $@ diff --git a/minecraft-server/start-finalSetup02Modpack.sh b/minecraft-server/start-finalSetup02Modpack.sh deleted file mode 100755 index 95166d5b..00000000 --- a/minecraft-server/start-finalSetup02Modpack.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/bash - -# If supplied with a URL for a modpack (simple zip of jars), download it and unpack -if [[ "$MODPACK" ]]; then -case "X$MODPACK" in - X[Hh][Tt][Tt][Pp]*.zip) - echo "Downloading mod/plugin pack via HTTP" - echo " from $MODPACK ..." - if ! curl -sSL -o /tmp/modpack.zip "$MODPACK"; then - echo "ERROR: failed to download from $MODPACK" - exit 2 - fi - - if [ "$TYPE" = "SPIGOT" ]; then - if [ "$REMOVE_OLD_MODS" = "TRUE" ]; then - rm -rf /data/plugins/* - fi - mkdir -p /data/plugins - if ! unzip -o -d /data/plugins /tmp/modpack.zip; then - echo "ERROR: failed to unzip the modpack from $MODPACK" - fi - else - if [ "$REMOVE_OLD_MODS" = "TRUE" ]; then - rm -rf /data/mods/* - fi - mkdir -p /data/mods - if ! unzip -o -d /data/mods /tmp/modpack.zip; then - echo "ERROR: failed to unzip the modpack from $MODPACK" - fi - fi - rm -f /tmp/modpack.zip - ;; - *) - echo "Invalid URL given for modpack: Must be HTTP or HTTPS and a ZIP file" - ;; -esac -fi - -su-exec minecraft /start-finalSetup03Modconfig $@ diff --git a/minecraft-server/start-finalSetup03Modconfig.sh b/minecraft-server/start-finalSetup03Modconfig.sh deleted file mode 100755 index 84e17460..00000000 --- a/minecraft-server/start-finalSetup03Modconfig.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash - -# If supplied with a URL for a config (simple zip of configurations), download it and unpack -if [[ "$MODCONFIG" ]]; then -case "X$MODCONFIG" in - X[Hh][Tt][Tt][Pp]*[Zz][iI][pP]) - echo "Downloading mod/plugin configs via HTTP" - echo " from $MODCONFIG ..." - curl -sSL -o /tmp/modconfig.zip "$MODCONFIG" - if [ "$TYPE" = "SPIGOT" ]; then - mkdir -p /data/plugins - unzip -o -d /data/plugins /tmp/modconfig.zip - else - mkdir -p /data/config - unzip -o -d /data/config /tmp/modconfig.zip - fi - rm -f /tmp/modconfig.zip - ;; - *) - echo "Invalid URL given for modconfig: Must be HTTP or HTTPS and a ZIP file" - ;; -esac -fi - -su-exec minecraft /start-finalSetup04ServerProperties $@ diff --git a/minecraft-server/start-finalSetup04ServerProperties.sh b/minecraft-server/start-finalSetup04ServerProperties.sh deleted file mode 100755 index b7112164..00000000 --- a/minecraft-server/start-finalSetup04ServerProperties.sh +++ /dev/null @@ -1,117 +0,0 @@ -#!/bin/bash - -# FUNCTIONS -function setServerProp { - local prop=$1 - local var=$2 - if [ -n "$var" ]; then - echo "Setting $prop to $var" - sed -i "/$prop\s*=/ c $prop=$var" /data/server.properties - fi -} - -# Deploy server.properties file -if [ ! -e server.properties ]; then - echo "Creating server.properties" - cp /tmp/server.properties . - - if [ -n "$WHITELIST" ]; then - echo "Creating whitelist" - sed -i "/whitelist\s*=/ c whitelist=true" /data/server.properties - sed -i "/white-list\s*=/ c white-list=true" /data/server.properties - fi - - setServerProp "motd" "$MOTD" - setServerProp "allow-nether" "$ALLOW_NETHER" - setServerProp "announce-player-achievements" "$ANNOUNCE_PLAYER_ACHIEVEMENTS" - setServerProp "enable-command-block" "$ENABLE_COMMAND_BLOCK" - setServerProp "spawn-animals" "$SPAWN_ANIMALS" - setServerProp "spawn-monsters" "$SPAWN_MONSTERS" - setServerProp "spawn-npcs" "$SPAWN_NPCS" - setServerProp "generate-structures" "$GENERATE_STRUCTURES" - setServerProp "view-distance" "$VIEW_DISTANCE" - setServerProp "hardcore" "$HARDCORE" - setServerProp "max-build-height" "$MAX_BUILD_HEIGHT" - setServerProp "force-gamemode" "$FORCE_GAMEMODE" - setServerProp "hardmax-tick-timecore" "$MAX_TICK_TIME" - setServerProp "enable-query" "$ENABLE_QUERY" - setServerProp "query.port" "$QUERY_PORT" - setServerProp "enable-rcon" "$ENABLE_RCON" - setServerProp "rcon.password" "$RCON_PASSWORD" - setServerProp "rcon.port" "$RCON_PORT" - setServerProp "max-players" "$MAX_PLAYERS" - setServerProp "max-world-size" "$MAX_WORLD_SIZE" - setServerProp "level-name" "$LEVEL" - setServerProp "level-seed" "$SEED" - setServerProp "pvp" "$PVP" - setServerProp "generator-settings" "$GENERATOR_SETTINGS" - setServerProp "online-mode" "$ONLINE_MODE" - - if [ -n "$LEVEL_TYPE" ]; then - # normalize to uppercase - LEVEL_TYPE=$( echo ${LEVEL_TYPE} | tr '[:lower:]' '[:upper:]' ) - echo "Setting level type to $LEVEL_TYPE" - # check for valid values and only then set - case $LEVEL_TYPE in - DEFAULT|FLAT|LARGEBIOMES|AMPLIFIED|CUSTOMIZED|BIOMESOP|RTG) - sed -i "/level-type\s*=/ c level-type=$LEVEL_TYPE" /data/server.properties - ;; - *) - echo "Invalid LEVEL_TYPE: $LEVEL_TYPE" - exit 1 - ;; - esac - fi - - if [ -n "$DIFFICULTY" ]; then - case $DIFFICULTY in - peaceful|0) - DIFFICULTY=0 - ;; - easy|1) - DIFFICULTY=1 - ;; - normal|2) - DIFFICULTY=2 - ;; - hard|3) - DIFFICULTY=3 - ;; - *) - echo "DIFFICULTY must be peaceful, easy, normal, or hard." - exit 1 - ;; - esac - echo "Setting difficulty to $DIFFICULTY" - sed -i "/difficulty\s*=/ c difficulty=$DIFFICULTY" /data/server.properties - fi - - if [ -n "$MODE" ]; then - echo "Setting mode" - MODE_LC=$( echo $MODE | tr '[:upper:]' '[:lower:]' ) - case $MODE_LC in - 0|1|2|3) - ;; - su*) - MODE=0 - ;; - c*) - MODE=1 - ;; - a*) - MODE=2 - ;; - sp*) - MODE=3 - ;; - *) - echo "ERROR: Invalid game mode: $MODE" - exit 1 - ;; - esac - - sed -i "/^gamemode\s*=/ c gamemode=$MODE" $SERVER_PROPERTIES - fi -fi - -su-exec minecraft /start-minecraftFinalSetup $@ diff --git a/minecraft-server/start-minecraftFinalSetup.sh b/minecraft-server/start-minecraftFinalSetup.sh deleted file mode 100755 index dba9ad33..00000000 --- a/minecraft-server/start-minecraftFinalSetup.sh +++ /dev/null @@ -1,88 +0,0 @@ -#!/bin/bash - -if [ -n "$OPS" -a ! -e ops.txt.converted ]; then - echo "Setting ops" - echo $OPS | awk -v RS=, '{print}' >> ops.txt -fi - -if [ -n "$WHITELIST" -a ! -e white-list.txt.converted ]; then - echo "Setting whitelist" - echo $WHITELIST | awk -v RS=, '{print}' >> white-list.txt -fi - -if [ -n "$ICON" -a ! -e server-icon.png ]; then - echo "Using server icon from $ICON..." - # Not sure what it is yet...call it "img" - wget -q -O /tmp/icon.img $ICON - specs=$(identify /tmp/icon.img | awk '{print $2,$3}') - if [ "$specs" = "PNG 64x64" ]; then - mv /tmp/icon.img /data/server-icon.png - else - echo "Converting image to 64x64 PNG..." - convert /tmp/icon.img -resize 64x64! /data/server-icon.png - fi -fi - -# Make sure files exist and are valid JSON (for pre-1.12 to 1.12 upgrades) -for j in *.json; do - if [[ $(python -c "print open('$j').read().strip()==''") = True ]]; then - echo "Fixing JSON $j" - echo '[]' > $j - fi -done - -# If any modules have been provided, copy them over -mkdir -p /data/mods -for m in /mods/*.{jar,zip} -do - if [ -f "$m" -a ! -f "/data/mods/$m" ]; then - echo Copying mod `basename "$m"` - cp "$m" /data/mods - fi -done -[ -d /data/config ] || mkdir /data/config -for c in /config/* -do - if [ -f "$c" ]; then - echo Copying configuration `basename "$c"` - cp -rf "$c" /data/config - fi -done - -if [ "$TYPE" = "SPIGOT" ]; then - if [ -d /plugins ]; then - echo Copying any Bukkit plugins over - cp -r /plugins /data - fi -fi - -EXTRA_ARGS="" -# Optional disable console -if [[ ${CONSOLE} = false || ${CONSOLE} = FALSE ]]; then - EXTRA_ARGS+="--noconsole" -fi - -# Optional disable GUI for headless servers -if [[ ${GUI} = false || ${GUI} = FALSE ]]; then - EXTRA_ARGS="${EXTRA_ARGS} nogui" -fi - -# put these prior JVM_OPTS at the end to give any memory settings there higher precedence -echo "Setting initial memory to ${INIT_MEMORY:-${MEMORY}} and max to ${MAX_MEMORY:-${MEMORY}}" -JVM_OPTS="-Xms${INIT_MEMORY:-${MEMORY}} -Xmx${MAX_MEMORY:-${MEMORY}} ${JVM_OPTS}" - -if [[ ${TYPE} == "FEED-THE-BEAST" ]]; then - cp -f $SERVER_PROPERTIES ${FTB_DIR}/server.properties - cp -f /data/{eula,ops,white-list}.txt ${FTB_DIR}/ - cd ${FTB_DIR} - echo "Running FTB server modpack start ..." - exec ${FTB_SERVER_START} -else - # If we have a bootstrap.txt file... feed that in to the server stdin - if [ -f /data/bootstrap.txt ]; - then - exec java $JVM_XX_OPTS $JVM_OPTS -jar $SERVER "$@" $EXTRA_ARGS < /data/bootstrap.txt - else - exec java $JVM_XX_OPTS $JVM_OPTS -jar $SERVER "$@" $EXTRA_ARGS - fi -fi diff --git a/minecraft-server/start.sh b/minecraft-server/start.sh deleted file mode 100755 index 51f0443c..00000000 --- a/minecraft-server/start.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/sh - -set -e -sed -i "/^minecraft/s/:1000:1000:/:${UID}:${GID}:/g" /etc/passwd -sed -i "/^minecraft/s/:1000:/:${GID}:/g" /etc/group - -if [ "$SKIP_OWNERSHIP_FIX" != "TRUE" ]; then - fix_ownership() { - dir=$1 - if ! su-exec minecraft test -w $dir; then - echo "Correcting writability of $dir ..." - chown -R minecraft:minecraft $dir - chmod -R u+w $dir - fi - } - - fix_ownership /data - fix_ownership /home/minecraft -fi - -echo "Switching to user 'minecraft'" -su-exec minecraft /start-configuration $@ From ee5a95baa8acfb929a6dec3b2fc305462732ccd9 Mon Sep 17 00:00:00 2001 From: Aitor Ramos Sasselli Date: Wed, 1 Nov 2017 06:42:44 +0100 Subject: [PATCH 3/3] Repaired some bugs from refactor --- minecraft-server/start | 22 ++++ minecraft-server/start-configuration | 82 ++++++++++++ minecraft-server/start-deployBukkitSpigot | 71 +++++++++++ minecraft-server/start-deployFTB | 68 ++++++++++ minecraft-server/start-deployForge | 118 ++++++++++++++++++ minecraft-server/start-deployPaper | 41 ++++++ minecraft-server/start-deployVanilla | 11 ++ minecraft-server/start-finalSetup01World | 36 ++++++ minecraft-server/start-finalSetup02Modpack | 39 ++++++ minecraft-server/start-finalSetup03Modconfig | 25 ++++ .../start-finalSetup04ServerProperties | 117 +++++++++++++++++ minecraft-server/start-minecraftFinalSetup | 88 +++++++++++++ 12 files changed, 718 insertions(+) create mode 100755 minecraft-server/start create mode 100755 minecraft-server/start-configuration create mode 100755 minecraft-server/start-deployBukkitSpigot create mode 100755 minecraft-server/start-deployFTB create mode 100755 minecraft-server/start-deployForge create mode 100755 minecraft-server/start-deployPaper create mode 100755 minecraft-server/start-deployVanilla create mode 100755 minecraft-server/start-finalSetup01World create mode 100755 minecraft-server/start-finalSetup02Modpack create mode 100755 minecraft-server/start-finalSetup03Modconfig create mode 100755 minecraft-server/start-finalSetup04ServerProperties create mode 100755 minecraft-server/start-minecraftFinalSetup diff --git a/minecraft-server/start b/minecraft-server/start new file mode 100755 index 00000000..51f0443c --- /dev/null +++ b/minecraft-server/start @@ -0,0 +1,22 @@ +#!/bin/sh + +set -e +sed -i "/^minecraft/s/:1000:1000:/:${UID}:${GID}:/g" /etc/passwd +sed -i "/^minecraft/s/:1000:/:${GID}:/g" /etc/group + +if [ "$SKIP_OWNERSHIP_FIX" != "TRUE" ]; then + fix_ownership() { + dir=$1 + if ! su-exec minecraft test -w $dir; then + echo "Correcting writability of $dir ..." + chown -R minecraft:minecraft $dir + chmod -R u+w $dir + fi + } + + fix_ownership /data + fix_ownership /home/minecraft +fi + +echo "Switching to user 'minecraft'" +su-exec minecraft /start-configuration $@ diff --git a/minecraft-server/start-configuration b/minecraft-server/start-configuration new file mode 100755 index 00000000..f045bf08 --- /dev/null +++ b/minecraft-server/start-configuration @@ -0,0 +1,82 @@ +#!/bin/bash + +shopt -s nullglob + +#umask 002 +export HOME=/data + +if [ ! -e /data/eula.txt ]; then + if [ "$EULA" != "" ]; then + echo "# Generated via Docker on $(date)" > eula.txt + echo "eula=$EULA" >> eula.txt + if [ $? != 0 ]; then + echo "ERROR: unable to write eula to /data. Please make sure attached directory is writable by uid=${UID}" + exit 2 + fi + else + echo "" + echo "Please accept the Minecraft EULA at" + echo " https://account.mojang.com/documents/minecraft_eula" + echo "by adding the following immediately after 'docker run':" + echo " -e EULA=TRUE" + echo "" + exit 1 + fi +fi + +if ! touch /data/.verify_access; then + echo "ERROR: /data doesn't seem to be writable. Please make sure attached directory is writable by uid=${UID} " + exit 2 +fi + +export SERVER_PROPERTIES=/data/server.properties +export FTB_DIR=/data/FeedTheBeast +export VERSIONS_JSON=https://launchermeta.mojang.com/mc/game/version_manifest.json + +echo "Checking version information." +case "X$VERSION" in + X|XLATEST|Xlatest) + export VANILLA_VERSION=`curl -fsSL $VERSIONS_JSON | jq -r '.latest.release'` + ;; + XSNAPSHOT|Xsnapshot) + export VANILLA_VERSION=`curl -fsSL $VERSIONS_JSON | jq -r '.latest.snapshot'` + ;; + X[1-9]*) + export VANILLA_VERSION=$VERSION + ;; + *) + export VANILLA_VERSION=`curl -fsSL $VERSIONS_JSON | jq -r '.latest.release'` + ;; +esac + +cd /data + +echo "Checking type information." +case "$TYPE" in + *BUKKIT|*bukkit|SPIGOT|spigot) + exec /start-deployBukkitSpigot $@ + ;; + + PAPER|paper) + exec /start-deployPaper $@ + ;; + + FORGE|forge) + exec /start-deployForge $@ + ;; + + FTB|ftb) + exec /start-deployFTB $@ + ;; + + VANILLA|vanilla) + exec /start-deployVanilla $@ + ;; + + *) + echo "Invalid type: '$TYPE'" + echo "Must be: VANILLA, FORGE, BUKKIT, SPIGOT, PAPER, FTB, SPONGEVANILLA" + exit 1 + ;; + +esac diff --git a/minecraft-server/start-deployBukkitSpigot b/minecraft-server/start-deployBukkitSpigot new file mode 100755 index 00000000..1cff5bf9 --- /dev/null +++ b/minecraft-server/start-deployBukkitSpigot @@ -0,0 +1,71 @@ +#!/bin/bash + +function buildSpigotFromSource { + echo "Building Spigot $VANILLA_VERSION from source, might take a while, get some coffee" + mkdir /data/temp + cd /data/temp + wget -q -P /data/temp https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar && \ + java -jar /data/temp/BuildTools.jar --rev $VANILLA_VERSION 2>&1 |tee /data/spigot_build.log| while read l; do echo -n .; done; echo "done" + mv spigot-*.jar /data/spigot_server.jar + mv craftbukkit-*.jar /data/craftbukkit_server.jar + echo "Cleaning up" + rm -rf /data/temp + cd /data +} + +function downloadSpigot { + local match + case "$TYPE" in + *BUKKIT|*bukkit) + match="Craftbukkit" + downloadUrl=${BUKKIT_DOWNLOAD_URL} + ;; + *) + match="Spigot" + downloadUrl=${SPIGOT_DOWNLOAD_URL} + ;; + esac + + if [[ -z $downloadUrl ]]; then + downloadUrl=$(restify --class=jar-div https://mcadmin.net/ | \ + jq --arg version "$match $VANILLA_VERSION" -r -f /usr/share/mcadmin.jq) + if [[ -z $downloadUrl ]]; then + echo "ERROR: Version $VANILLA_VERSION is not supported for $TYPE" + echo " Refer to https://mcadmin.net/ for supported versions" + exit 2 + fi + fi + + echo "Downloading $match" + curl -kfsSL -o $SERVER "$downloadUrl" + status=$? + if [ ! -f $SERVER ]; then + echo "ERROR: failed to download from $downloadUrl (status=$status)" + exit 3 + fi + +} + + +case "$TYPE" in + *BUKKIT|*bukkit) + export SERVER=craftbukkit_server.jar + ;; + *) + export SERVER=spigot_server.jar + ;; +esac + +if [ ! -f $SERVER ]; then + if [[ "$BUILD_SPIGOT_FROM_SOURCE" = TRUE || "$BUILD_SPIGOT_FROM_SOURCE" = true || "$BUILD_FROM_SOURCE" = TRUE || "$BUILD_FROM_SOURCE" = true ]]; then + buildSpigotFromSource + else + downloadSpigot + fi +fi + +# Normalize on Spigot for operations below +export TYPE=SPIGOT + +# Continue to Final Setup +exec /start-finalSetup01World $@ diff --git a/minecraft-server/start-deployFTB b/minecraft-server/start-deployFTB new file mode 100755 index 00000000..6fbd53c6 --- /dev/null +++ b/minecraft-server/start-deployFTB @@ -0,0 +1,68 @@ +#!/bin/bash + +export TYPE=FEED-THE-BEAST + +function isURL { + local value=$1 + + if [[ ${value:0:8} == "https://" || ${value:0:7} = "http://" ]]; then + return 0 + else + return 1 + fi +} + +echo "Looking for Feed-The-Beast server modpack." +if [[ -z $FTB_SERVER_MOD ]]; then + echo "Environment variable FTB_SERVER_MOD not set." + echo "Set FTB_SERVER_MOD to the file name of the FTB server modpack." + echo "(And place the modpack in the /data directory.)" + exit 2 +fi +srv_modpack=${FTB_SERVER_MOD} +if isURL ${srv_modpack}; then + case $srv_modpack in + https://www.feed-the-beast.com/*/download) + break;; + https://www.feed-the-beast.com/*) + srv_modpack=${srv_modpack}/download;; + esac + file=$(basename $(dirname $srv_modpack)) + downloaded=/data/${file}.zip + if [ ! -e $downloaded ]; then + echo "Downloading FTB modpack... +$srv_modpack -> $downloaded" + curl -sSL -o $downloaded $srv_modpack + fi + srv_modpack=$downloaded +fi +if [[ ${srv_modpack:0:5} == "data/" ]]; then + # Prepend with "/" + srv_modpack=/${srv_modpack} +fi +if [[ ! ${srv_modpack:0:1} == "/" ]]; then + # If not an absolute path, assume file is in "/data" + srv_modpack=/data/${srv_modpack} +fi +if [[ ! -f ${srv_modpack} ]]; then + echo "FTB server modpack ${srv_modpack} not found." + exit 2 +fi +if [[ ! ${srv_modpack: -4} == ".zip" ]]; then + echo "FTB server modpack ${srv_modpack} is not a zip archive." + echo "Please set FTB_SERVER_MOD to a file with a .zip extension." + exit 2 +fi + +if [ ! -d ${FTB_DIR} ]; then + echo "Unpacking FTB server modpack ${srv_modpack} ..." + mkdir -p ${FTB_DIR} + unzip -o ${srv_modpack} -d ${FTB_DIR} + cp -f /data/eula.txt ${FTB_DIR}/eula.txt +fi +export FTB_SERVER_START=${FTB_DIR}/ServerStart.sh +chmod a+x ${FTB_SERVER_START} +sed -i "s/-jar/-Dfml.queryResult=confirm -jar/" ${FTB_SERVER_START} + +# Continue to Final Setup +exec /start-finalSetup01World $@ diff --git a/minecraft-server/start-deployForge b/minecraft-server/start-deployForge new file mode 100755 index 00000000..dfc773b9 --- /dev/null +++ b/minecraft-server/start-deployForge @@ -0,0 +1,118 @@ +#!/bin/bash + +export TYPE=FORGE + +if [[ -z $FORGE_INSTALLER && -z $FORGE_INSTALLER_URL ]]; then + norm=$VANILLA_VERSION + + case $VANILLA_VERSION in + *.*.*) + norm=$VANILLA_VERSION ;; + *.*) + norm=${VANILLA_VERSION}.0 ;; + esac + + echo "Checking Forge version information." + case $FORGEVERSION in + RECOMMENDED) + curl -fsSL -o /tmp/forge.json http://files.minecraftforge.net/maven/net/minecraftforge/forge/promotions_slim.json + FORGE_VERSION=$(cat /tmp/forge.json | jq -r ".promos[\"$VANILLA_VERSION-recommended\"]") + if [ $FORGE_VERSION = null ]; then + FORGE_VERSION=$(cat /tmp/forge.json | jq -r ".promos[\"$VANILLA_VERSION-latest\"]") + if [ $FORGE_VERSION = null ]; then + echo "ERROR: Version $VANILLA_VERSION is not supported by Forge" + echo " Refer to http://files.minecraftforge.net/ for supported versions" + exit 2 + fi + fi + ;; + + *) + FORGE_VERSION=$FORGEVERSION + ;; + esac + + normForgeVersion=$VANILLA_VERSION-$FORGE_VERSION-$norm + shortForgeVersion=$VANILLA_VERSION-$FORGE_VERSION + + FORGE_INSTALLER="/tmp/forge-$shortForgeVersion-installer.jar" +elif [[ -z $FORGE_INSTALLER ]]; then + FORGE_INSTALLER="/tmp/forge-installer.jar" +elif [[ ! -e $FORGE_INSTALLER ]]; then + echo "ERROR: the given Forge installer doesn't exist : $FORGE_INSTALLER" + exit 2 +fi + +installMarker=".forge-installed-$shortForgeVersion" + +if [ ! -e $installMarker ]; then + if [ ! -e $FORGE_INSTALLER ]; then + + if [[ -z $FORGE_INSTALLER_URL ]]; then + echo "Downloading $normForgeVersion" + + forgeFileNames=" + $normForgeVersion/forge-$normForgeVersion-installer.jar + $shortForgeVersion/forge-$shortForgeVersion-installer.jar + END + " + for fn in $forgeFileNames; do + if [ $fn == END ]; then + echo "Unable to compute URL for $normForgeVersion" + exit 2 + fi + downloadUrl=http://files.minecraftforge.net/maven/net/minecraftforge/forge/$fn + echo "...trying $downloadUrl" + if curl -o $FORGE_INSTALLER -fsSL $downloadUrl; then + break + fi + done + else + echo "Downloading $FORGE_INSTALLER_URL ..." + if ! curl -o $FORGE_INSTALLER -fsSL $FORGE_INSTALLER_URL; then + echo "Failed to download from given location $FORGE_INSTALLER_URL" + exit 2 + fi + fi + fi + + echo "Installing Forge $shortForgeVersion using $FORGE_INSTALLER" + mkdir -p mods + tries=3 + while ((--tries >= 0)); do + java -jar $FORGE_INSTALLER --installServer + if [ $? == 0 ]; then + break + fi + done + if (($tries < 0)); then + echo "Forge failed to install after several tries." >&2 + exit 10 + fi + # NOTE $shortForgeVersion will be empty if installer location was given to us + echo "Finding installed server jar..." + for j in *forge*.jar; do + echo "...$j" + case $j in + *installer*) + ;; + *) + export SERVER=$j + break + ;; + esac + done + if [[ -z $SERVER ]]; then + echo "Unable to derive server jar for Forge" + exit 2 + fi + + echo "Using server $SERVER" + echo $SERVER > $installMarker + +else + export SERVER=$(cat $installMarker) +fi + +# Continue to Final Setup +exec /start-finalSetup01World $@ diff --git a/minecraft-server/start-deployPaper b/minecraft-server/start-deployPaper new file mode 100755 index 00000000..9d1300a3 --- /dev/null +++ b/minecraft-server/start-deployPaper @@ -0,0 +1,41 @@ +#!/bin/bash + +export SERVER=paper_server.jar +if [ ! -f $SERVER ]; then + local build + case "$VERSION" in + latest|LATEST|1.10) + build="lastSuccessfulBuild";; + 1.9.4) + build="773";; + 1.9.2) + build="727";; + 1.9) + build="612";; + 1.8.8) + build="443";; + *) + build="nosupp";; + esac + + if [ $build != "nosupp" ]; then + rm $SERVER + downloadUrl=${PAPER_DOWNLOAD_URL:-https://ci.destroystokyo.com/job/PaperSpigot/$build/artifact/paperclip.jar} + curl -fsSL -o $SERVER "$downloadUrl" + if [ ! -f $SERVER ]; then + echo "ERROR: failed to download from $downloadUrl (status=$?)" + exit 3 + fi + else + echo "ERROR: Version $VERSION is not supported for $TYPE" + echo " Refer to https://ci.destroystokyo.com/job/PaperSpigot/" + echo " for supported versions" + exit 2 + fi +fi + +# Normalize on Spigot for operations below +export TYPE=SPIGOT + +# Continue to Final Setup +exec /start-finalSetup01World $@ diff --git a/minecraft-server/start-deployVanilla b/minecraft-server/start-deployVanilla new file mode 100755 index 00000000..550f15db --- /dev/null +++ b/minecraft-server/start-deployVanilla @@ -0,0 +1,11 @@ +#!/bin/bash + +export SERVER="minecraft_server.$VANILLA_VERSION.jar" + +if [ ! -e $SERVER ]; then + echo "Downloading $SERVER ..." + wget -q https://s3.amazonaws.com/Minecraft.Download/versions/$VANILLA_VERSION/$SERVER +fi + +# Continue to Final Setup +exec /start-finalSetup01World $@ diff --git a/minecraft-server/start-finalSetup01World b/minecraft-server/start-finalSetup01World new file mode 100755 index 00000000..0b765bdb --- /dev/null +++ b/minecraft-server/start-finalSetup01World @@ -0,0 +1,36 @@ +#!/bin/bash + +# If supplied with a URL for a world, download it and unpack +if [[ "$WORLD" ]]; then +case "X$WORLD" in + X[Hh][Tt][Tt][Pp]*) + echo "Downloading world via HTTP" + echo "$WORLD" + wget -q -O - "$WORLD" > /data/world.zip + echo "Unzipping word" + unzip -q /data/world.zip + rm -f /data/world.zip + if [ ! -d /data/world ]; then + echo World directory not found + for i in /data/*/level.dat; do + if [ -f "$i" ]; then + d=`dirname "$i"` + echo Renaming world directory from $d + mv -f "$d" /data/world + fi + done + fi + if [ "$TYPE" = "SPIGOT" ]; then + # Reorganise if a Spigot server + echo "Moving End and Nether maps to Spigot location" + [ -d "/data/world/DIM1" ] && mv -f "/data/world/DIM1" "/data/world_the_end" + [ -d "/data/world/DIM-1" ] && mv -f "/data/world/DIM-1" "/data/world_nether" + fi + ;; + *) + echo "Invalid URL given for world: Must be HTTP or HTTPS and a ZIP file" + ;; +esac +fi + +exec /start-finalSetup02Modpack $@ diff --git a/minecraft-server/start-finalSetup02Modpack b/minecraft-server/start-finalSetup02Modpack new file mode 100755 index 00000000..3f893892 --- /dev/null +++ b/minecraft-server/start-finalSetup02Modpack @@ -0,0 +1,39 @@ +#!/bin/bash + +# If supplied with a URL for a modpack (simple zip of jars), download it and unpack +if [[ "$MODPACK" ]]; then +case "X$MODPACK" in + X[Hh][Tt][Tt][Pp]*.zip) + echo "Downloading mod/plugin pack via HTTP" + echo " from $MODPACK ..." + if ! curl -sSL -o /tmp/modpack.zip "$MODPACK"; then + echo "ERROR: failed to download from $MODPACK" + exit 2 + fi + + if [ "$TYPE" = "SPIGOT" ]; then + if [ "$REMOVE_OLD_MODS" = "TRUE" ]; then + rm -rf /data/plugins/* + fi + mkdir -p /data/plugins + if ! unzip -o -d /data/plugins /tmp/modpack.zip; then + echo "ERROR: failed to unzip the modpack from $MODPACK" + fi + else + if [ "$REMOVE_OLD_MODS" = "TRUE" ]; then + rm -rf /data/mods/* + fi + mkdir -p /data/mods + if ! unzip -o -d /data/mods /tmp/modpack.zip; then + echo "ERROR: failed to unzip the modpack from $MODPACK" + fi + fi + rm -f /tmp/modpack.zip + ;; + *) + echo "Invalid URL given for modpack: Must be HTTP or HTTPS and a ZIP file" + ;; +esac +fi + +exec /start-finalSetup03Modconfig $@ diff --git a/minecraft-server/start-finalSetup03Modconfig b/minecraft-server/start-finalSetup03Modconfig new file mode 100755 index 00000000..1467f345 --- /dev/null +++ b/minecraft-server/start-finalSetup03Modconfig @@ -0,0 +1,25 @@ +#!/bin/bash + +# If supplied with a URL for a config (simple zip of configurations), download it and unpack +if [[ "$MODCONFIG" ]]; then +case "X$MODCONFIG" in + X[Hh][Tt][Tt][Pp]*[Zz][iI][pP]) + echo "Downloading mod/plugin configs via HTTP" + echo " from $MODCONFIG ..." + curl -sSL -o /tmp/modconfig.zip "$MODCONFIG" + if [ "$TYPE" = "SPIGOT" ]; then + mkdir -p /data/plugins + unzip -o -d /data/plugins /tmp/modconfig.zip + else + mkdir -p /data/config + unzip -o -d /data/config /tmp/modconfig.zip + fi + rm -f /tmp/modconfig.zip + ;; + *) + echo "Invalid URL given for modconfig: Must be HTTP or HTTPS and a ZIP file" + ;; +esac +fi + +exec /start-finalSetup04ServerProperties $@ diff --git a/minecraft-server/start-finalSetup04ServerProperties b/minecraft-server/start-finalSetup04ServerProperties new file mode 100755 index 00000000..bd946e2f --- /dev/null +++ b/minecraft-server/start-finalSetup04ServerProperties @@ -0,0 +1,117 @@ +#!/bin/bash + +# FUNCTIONS +function setServerProp { + local prop=$1 + local var=$2 + if [ -n "$var" ]; then + echo "Setting $prop to $var" + sed -i "/$prop\s*=/ c $prop=$var" /data/server.properties + fi +} + +# Deploy server.properties file +if [ ! -e server.properties ]; then + echo "Creating server.properties" + cp /tmp/server.properties . + + if [ -n "$WHITELIST" ]; then + echo "Creating whitelist" + sed -i "/whitelist\s*=/ c whitelist=true" /data/server.properties + sed -i "/white-list\s*=/ c white-list=true" /data/server.properties + fi + + setServerProp "motd" "$MOTD" + setServerProp "allow-nether" "$ALLOW_NETHER" + setServerProp "announce-player-achievements" "$ANNOUNCE_PLAYER_ACHIEVEMENTS" + setServerProp "enable-command-block" "$ENABLE_COMMAND_BLOCK" + setServerProp "spawn-animals" "$SPAWN_ANIMALS" + setServerProp "spawn-monsters" "$SPAWN_MONSTERS" + setServerProp "spawn-npcs" "$SPAWN_NPCS" + setServerProp "generate-structures" "$GENERATE_STRUCTURES" + setServerProp "view-distance" "$VIEW_DISTANCE" + setServerProp "hardcore" "$HARDCORE" + setServerProp "max-build-height" "$MAX_BUILD_HEIGHT" + setServerProp "force-gamemode" "$FORCE_GAMEMODE" + setServerProp "hardmax-tick-timecore" "$MAX_TICK_TIME" + setServerProp "enable-query" "$ENABLE_QUERY" + setServerProp "query.port" "$QUERY_PORT" + setServerProp "enable-rcon" "$ENABLE_RCON" + setServerProp "rcon.password" "$RCON_PASSWORD" + setServerProp "rcon.port" "$RCON_PORT" + setServerProp "max-players" "$MAX_PLAYERS" + setServerProp "max-world-size" "$MAX_WORLD_SIZE" + setServerProp "level-name" "$LEVEL" + setServerProp "level-seed" "$SEED" + setServerProp "pvp" "$PVP" + setServerProp "generator-settings" "$GENERATOR_SETTINGS" + setServerProp "online-mode" "$ONLINE_MODE" + + if [ -n "$LEVEL_TYPE" ]; then + # normalize to uppercase + LEVEL_TYPE=$( echo ${LEVEL_TYPE} | tr '[:lower:]' '[:upper:]' ) + echo "Setting level type to $LEVEL_TYPE" + # check for valid values and only then set + case $LEVEL_TYPE in + DEFAULT|FLAT|LARGEBIOMES|AMPLIFIED|CUSTOMIZED|BIOMESOP|RTG) + sed -i "/level-type\s*=/ c level-type=$LEVEL_TYPE" /data/server.properties + ;; + *) + echo "Invalid LEVEL_TYPE: $LEVEL_TYPE" + exit 1 + ;; + esac + fi + + if [ -n "$DIFFICULTY" ]; then + case $DIFFICULTY in + peaceful|0) + DIFFICULTY=0 + ;; + easy|1) + DIFFICULTY=1 + ;; + normal|2) + DIFFICULTY=2 + ;; + hard|3) + DIFFICULTY=3 + ;; + *) + echo "DIFFICULTY must be peaceful, easy, normal, or hard." + exit 1 + ;; + esac + echo "Setting difficulty to $DIFFICULTY" + sed -i "/difficulty\s*=/ c difficulty=$DIFFICULTY" /data/server.properties + fi + + if [ -n "$MODE" ]; then + echo "Setting mode" + MODE_LC=$( echo $MODE | tr '[:upper:]' '[:lower:]' ) + case $MODE_LC in + 0|1|2|3) + ;; + su*) + MODE=0 + ;; + c*) + MODE=1 + ;; + a*) + MODE=2 + ;; + sp*) + MODE=3 + ;; + *) + echo "ERROR: Invalid game mode: $MODE" + exit 1 + ;; + esac + + sed -i "/^gamemode\s*=/ c gamemode=$MODE" $SERVER_PROPERTIES + fi +fi + +exec /start-minecraftFinalSetup $@ diff --git a/minecraft-server/start-minecraftFinalSetup b/minecraft-server/start-minecraftFinalSetup new file mode 100755 index 00000000..dba9ad33 --- /dev/null +++ b/minecraft-server/start-minecraftFinalSetup @@ -0,0 +1,88 @@ +#!/bin/bash + +if [ -n "$OPS" -a ! -e ops.txt.converted ]; then + echo "Setting ops" + echo $OPS | awk -v RS=, '{print}' >> ops.txt +fi + +if [ -n "$WHITELIST" -a ! -e white-list.txt.converted ]; then + echo "Setting whitelist" + echo $WHITELIST | awk -v RS=, '{print}' >> white-list.txt +fi + +if [ -n "$ICON" -a ! -e server-icon.png ]; then + echo "Using server icon from $ICON..." + # Not sure what it is yet...call it "img" + wget -q -O /tmp/icon.img $ICON + specs=$(identify /tmp/icon.img | awk '{print $2,$3}') + if [ "$specs" = "PNG 64x64" ]; then + mv /tmp/icon.img /data/server-icon.png + else + echo "Converting image to 64x64 PNG..." + convert /tmp/icon.img -resize 64x64! /data/server-icon.png + fi +fi + +# Make sure files exist and are valid JSON (for pre-1.12 to 1.12 upgrades) +for j in *.json; do + if [[ $(python -c "print open('$j').read().strip()==''") = True ]]; then + echo "Fixing JSON $j" + echo '[]' > $j + fi +done + +# If any modules have been provided, copy them over +mkdir -p /data/mods +for m in /mods/*.{jar,zip} +do + if [ -f "$m" -a ! -f "/data/mods/$m" ]; then + echo Copying mod `basename "$m"` + cp "$m" /data/mods + fi +done +[ -d /data/config ] || mkdir /data/config +for c in /config/* +do + if [ -f "$c" ]; then + echo Copying configuration `basename "$c"` + cp -rf "$c" /data/config + fi +done + +if [ "$TYPE" = "SPIGOT" ]; then + if [ -d /plugins ]; then + echo Copying any Bukkit plugins over + cp -r /plugins /data + fi +fi + +EXTRA_ARGS="" +# Optional disable console +if [[ ${CONSOLE} = false || ${CONSOLE} = FALSE ]]; then + EXTRA_ARGS+="--noconsole" +fi + +# Optional disable GUI for headless servers +if [[ ${GUI} = false || ${GUI} = FALSE ]]; then + EXTRA_ARGS="${EXTRA_ARGS} nogui" +fi + +# put these prior JVM_OPTS at the end to give any memory settings there higher precedence +echo "Setting initial memory to ${INIT_MEMORY:-${MEMORY}} and max to ${MAX_MEMORY:-${MEMORY}}" +JVM_OPTS="-Xms${INIT_MEMORY:-${MEMORY}} -Xmx${MAX_MEMORY:-${MEMORY}} ${JVM_OPTS}" + +if [[ ${TYPE} == "FEED-THE-BEAST" ]]; then + cp -f $SERVER_PROPERTIES ${FTB_DIR}/server.properties + cp -f /data/{eula,ops,white-list}.txt ${FTB_DIR}/ + cd ${FTB_DIR} + echo "Running FTB server modpack start ..." + exec ${FTB_SERVER_START} +else + # If we have a bootstrap.txt file... feed that in to the server stdin + if [ -f /data/bootstrap.txt ]; + then + exec java $JVM_XX_OPTS $JVM_OPTS -jar $SERVER "$@" $EXTRA_ARGS < /data/bootstrap.txt + else + exec java $JVM_XX_OPTS $JVM_OPTS -jar $SERVER "$@" $EXTRA_ARGS + fi +fi