docker-minecraft-server/scripts/start-setupWorld

85 lines
2.6 KiB
Plaintext
Raw Normal View History

2017-11-01 05:42:44 +00:00
#!/bin/bash
# shellcheck source=start-utils
. "${SCRIPTS:-/}start-utils"
set -e
isDebugging && set -x
2020-03-06 15:52:17 +00:00
if [ "$TYPE" = "CURSEFORGE" ]; then
worldDest=$FTB_DIR/${LEVEL:-world}
else
worldDest=/data/${LEVEL:-world}
fi
if [[ "$WORLD" ]] && ( isTrue "${FORCE_WORLD_COPY}" || [ ! -d "$worldDest" ] ); then
if isTrue "${FORCE_WORLD_COPY}"; then
log "Removing existing world data in $worldDest ${worldDest}_nether ${worldDest}_the_end"
rm -rf "$worldDest" \
"${worldDest}_nether" \
"${worldDest}_the_end"
fi
if isURL "$WORLD"; then
log "Downloading world from $WORLD"
if ! get -o /tmp/world.bin "$WORLD"; then
log "ERROR: failed to download world from $WORLD"
exit 1
fi
WORLD=/tmp/world.bin
fi
if [ -f "$WORLD" ]; then
log "Extracting world"
# Stage contents so that the correct subdirectory can be picked off
mkdir -p /tmp/world-data
if ! extract "$WORLD" /tmp/world-data; then
exit 1
fi
if [ "$FAMILY" = "SPIGOT" ]; then
baseDirs=$(find /tmp/world-data -name "level.dat" -not -path "*_nether*" -not -path "*_the_end*" -exec dirname "{}" \;)
else
baseDirs=$(find /tmp/world-data -name "level.dat" -exec dirname "{}" \;)
fi
if ! [[ $baseDirs ]]; then
log "ERROR world content is not valid since level.dat could not be found"
exit 2
fi
count=$(echo "$baseDirs" | wc -l)
if [[ $count -gt 1 ]]; then
baseDir="$(echo "$baseDirs" | sed -n ${WORLD_INDEX:-1}p)"
baseName=$(basename "$baseDir")
log "WARN multiple levels found, picking: $baseName"
elif [[ $count -gt 0 ]]; then
baseDir="$baseDirs"
else
log "ERROR invalid world content"
exit 1
fi
rsync --remove-source-files --recursive --delete "$baseDir/" "$worldDest"
if [ "$FAMILY" = "SPIGOT" ]; then
log "Copying end and nether ..."
[ -d "${baseDir}_nether" ] && rsync --remove-source-files --recursive --delete "${baseDir}_nether/" "${worldDest}_nether"
[ -d "${baseDir}_the_end" ] && rsync --remove-source-files --recursive --delete "${baseDir}_the_end/" "${worldDest}_the_end"
fi
elif [ -d "$WORLD" ]; then
log "Cloning world directory from $WORLD ..."
rsync --recursive --delete "${WORLD%/}"/ "$worldDest"
else
log "ERROR: world file/directory $WORLD is missing"
exit 1
fi
if [ "$FAMILY" = "SPIGOT" ]; then
# Reorganise if a Spigot server
log "Moving End and Nether maps to Spigot location"
[ -d "$worldDest/DIM1" ] && mv -f "$worldDest/DIM1" "${worldDest}_the_end"
[ -d "$worldDest/DIM-1" ] && mv -f "$worldDest/DIM-1" "${worldDest}_nether"
fi
2017-11-01 05:42:44 +00:00
fi
2022-01-04 03:59:19 +00:00
exec "${SCRIPTS:-/}start-setupVanillaTweaks" "$@"