From c8eb0f587438ab236045f3a41bfd1e00b0ebeb22 Mon Sep 17 00:00:00 2001 From: Geoff Bourne Date: Tue, 11 Sep 2018 20:38:54 -0500 Subject: [PATCH] mc: enhance the WORLD option to allow for directory sources #247 --- minecraft-server/README.md | 13 +++++++++++++ minecraft-server/start-finalSetup01World | 21 ++++++++++++++++----- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/minecraft-server/README.md b/minecraft-server/README.md index b8e6e407..75fab2d8 100644 --- a/minecraft-server/README.md +++ b/minecraft-server/README.md @@ -674,6 +674,19 @@ will be deleted when the container is deleted. you should use an IP address or a globally resolveable FQDN, or else the name of a linked container. +### Cloning world from a container path + +The `WORLD` option can also be used to reference a directory that will be used +as a source to clone the world directory. + +For example, the following would initially clone the world's content +from `/worlds/basic`. Also notice in the example that you can use a +read-only volume attachment to ensure the clone source remains pristine. + +``` +docker run ... -v $HOME/worlds:/worlds:ro -e WORLD=/worlds/basic +``` + ### Downloadable mod/plugin pack for Forge, Bukkit, and Spigot Servers Like the `WORLD` option above, you can specify the URL of a "mod pack" diff --git a/minecraft-server/start-finalSetup01World b/minecraft-server/start-finalSetup01World index 667ed542..d6c526a1 100755 --- a/minecraft-server/start-finalSetup01World +++ b/minecraft-server/start-finalSetup01World @@ -1,5 +1,7 @@ #!/bin/bash +worldDest=/data/$LEVEL + # If supplied with a URL for a world, download it and unpack if [[ "$WORLD" ]]; then case "X$WORLD" in @@ -9,25 +11,34 @@ case "X$WORLD" in echo "Unzipping world" unzip -o -q /data/world.zip rm -f /data/world.zip - if [ ! -d /data/world ]; then + if [ ! -d $worldDest ]; 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 + mv -f "$d" $worldDest 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" + [ -d "$worldDest/DIM1" ] && mv -f "$worldDest/DIM1" "/data/${LEVEL}_the_end" + [ -d "$worldDest/DIM-1" ] && mv -f "$worldDest/DIM-1" "/data/${LEVEL}_nether" fi ;; *) - echo "Invalid URL given for world: Must be HTTP or HTTPS and a ZIP file" + if [[ -d $WORLD ]]; then + if [[ ! -d $worldDest ]]; then + echo "Cloning world directory from $WORLD ..." + cp -r $WORLD $worldDest + else + echo "Skipping clone from $WORLD since $worldDest exists" + fi + else + echo "Invalid URL given for world: Must be HTTP or HTTPS and a ZIP file" + fi ;; esac fi