mc: enhance the WORLD option to allow for directory sources

#247
This commit is contained in:
Geoff Bourne 2018-09-11 20:38:54 -05:00
parent 90907f7b1e
commit c8eb0f5874
2 changed files with 29 additions and 5 deletions

View File

@ -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 you should use an IP address or a globally resolveable FQDN, or else the
name of a linked container. 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 ### Downloadable mod/plugin pack for Forge, Bukkit, and Spigot Servers
Like the `WORLD` option above, you can specify the URL of a "mod pack" Like the `WORLD` option above, you can specify the URL of a "mod pack"

View File

@ -1,5 +1,7 @@
#!/bin/bash #!/bin/bash
worldDest=/data/$LEVEL
# If supplied with a URL for a world, download it and unpack # If supplied with a URL for a world, download it and unpack
if [[ "$WORLD" ]]; then if [[ "$WORLD" ]]; then
case "X$WORLD" in case "X$WORLD" in
@ -9,25 +11,34 @@ case "X$WORLD" in
echo "Unzipping world" echo "Unzipping world"
unzip -o -q /data/world.zip unzip -o -q /data/world.zip
rm -f /data/world.zip rm -f /data/world.zip
if [ ! -d /data/world ]; then if [ ! -d $worldDest ]; then
echo World directory not found echo World directory not found
for i in /data/*/level.dat; do for i in /data/*/level.dat; do
if [ -f "$i" ]; then if [ -f "$i" ]; then
d=`dirname "$i"` d=`dirname "$i"`
echo Renaming world directory from $d echo Renaming world directory from $d
mv -f "$d" /data/world mv -f "$d" $worldDest
fi fi
done done
fi fi
if [ "$TYPE" = "SPIGOT" ]; then if [ "$TYPE" = "SPIGOT" ]; then
# Reorganise if a Spigot server # Reorganise if a Spigot server
echo "Moving End and Nether maps to Spigot location" echo "Moving End and Nether maps to Spigot location"
[ -d "/data/world/DIM1" ] && mv -f "/data/world/DIM1" "/data/world_the_end" [ -d "$worldDest/DIM1" ] && mv -f "$worldDest/DIM1" "/data/${LEVEL}_the_end"
[ -d "/data/world/DIM-1" ] && mv -f "/data/world/DIM-1" "/data/world_nether" [ -d "$worldDest/DIM-1" ] && mv -f "$worldDest/DIM-1" "/data/${LEVEL}_nether"
fi fi
;; ;;
*) *)
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" echo "Invalid URL given for world: Must be HTTP or HTTPS and a ZIP file"
fi
;; ;;
esac esac
fi fi