diff --git a/minecraft-server/Dockerfile b/minecraft-server/Dockerfile index ec909451..168fe6a4 100644 --- a/minecraft-server/Dockerfile +++ b/minecraft-server/Dockerfile @@ -56,6 +56,6 @@ ENV UID=1000 GID=1000 \ JVM_XX_OPTS="-XX:+UseG1GC" MEMORY="1G" \ TYPE=VANILLA VERSION=LATEST FORGEVERSION=RECOMMENDED SPONGEBRANCH=STABLE SPONGEVERSION= LEVEL=world \ PVP=true DIFFICULTY=easy ENABLE_RCON=true RCON_PORT=25575 RCON_PASSWORD=minecraft \ - LEVEL_TYPE=DEFAULT GENERATOR_SETTINGS= WORLD= MODPACK= SERVER_PORT=25565 ONLINE_MODE=TRUE CONSOLE=true + LEVEL_TYPE=DEFAULT GENERATOR_SETTINGS= WORLD= MODPACK= MODS= SERVER_PORT=25565 ONLINE_MODE=TRUE CONSOLE=true COPY start* / diff --git a/minecraft-server/README.md b/minecraft-server/README.md index d69f7f05..aba1cec3 100644 --- a/minecraft-server/README.md +++ b/minecraft-server/README.md @@ -699,6 +699,11 @@ To use this option pass the environment variable `MODPACK`, such as top level of the zip archive. Make sure the jars are compatible with the particular `TYPE` of server you are running. +You may also download individual mods using the `MODS` environment variable and supplying the URL +to the jar files. Multiple mods/plugins should be comma separated. + + docker run -d -e MODS=https://www.example.com/mods/mod1.jar,https://www.example.com/mods/mod2.jar ... + ### Remove old mods/plugins When the option above is specified (`MODPACK`) you can also instruct script to @@ -708,10 +713,8 @@ To use this option pass the environment variable `REMOVE_OLD_MODS="TRUE"`, such docker run -d -e REMOVE_OLD_MODS="TRUE" -e MODPACK=http://www.example.com/mods/modpack.zip ... -**NOTE:** This option will be taken into account only when option `MODPACK` is also used. - **WARNING:** All content of the `mods` or `plugins` directory will be deleted -before unpacking new content from the zip file. +before unpacking new content from the MODPACK or MODS. ### Online mode diff --git a/minecraft-server/start-finalSetup02Modpack b/minecraft-server/start-finalSetup02Modpack index 3f893892..3894a1bc 100755 --- a/minecraft-server/start-finalSetup02Modpack +++ b/minecraft-server/start-finalSetup02Modpack @@ -1,5 +1,14 @@ #!/bin/bash +# Remove old mods/plugins +if [ "$REMOVE_OLD_MODS" = "TRUE" ]; then + if [ "$TYPE" = "SPIGOT" ]; then + rm -rf /data/plugins/* + else + rm -rf /data/mods/* + fi +fi + # If supplied with a URL for a modpack (simple zip of jars), download it and unpack if [[ "$MODPACK" ]]; then case "X$MODPACK" in @@ -12,17 +21,11 @@ case "X$MODPACK" in 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" @@ -36,4 +39,33 @@ case "X$MODPACK" in esac fi +# If supplied with a URL for a plugin download it. +if [[ "$MODS" ]]; then +for i in ${MODS//,/ } +do + case "X$i" in + X[Hh][Tt][Tt][Pp]*.jar) + echo "Downloading mod/plugin via HTTP" + echo " from $i ..." + if ! curl -sSL -o /tmp/${i##*/} $i; then + echo "ERROR: failed to download from $i to /tmp/${i##*/}" + exit 2 + fi + + if [ "$TYPE" = "SPIGOT" ]; then + mkdir -p /data/plugins + mv /tmp/${i##*/} /data/plugins/${i##*/} + else + mkdir -p /data/mods + mv /tmp/${i##*/} /data/mods/${i##*/} + fi + rm -f /tmp/${i##*/} + ;; + *) + echo "Invalid URL given for modpack: Must be HTTP or HTTPS and a JAR file" + ;; + esac +done +fi + exec /start-finalSetup03Modconfig $@