lifomapserver/scripts/convert_all.sh

63 lines
1.6 KiB
Bash
Raw Normal View History

#!/bin/bash
OUTDIR=`pwd`/tiles
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
mode="$1"
if [ "$mode" == "legacy" ]; then
MAPSERVER='http://old-maps.li-fo.de/'
FILES=`curl "$MAPSERVER" | sed -n 's/.*<a href="\([^\.]\+\.png\).*/\1/p'`
else
MAPSERVER='https://lifomaps.de'
FILES=`curl "$MAPSERVER" | sed -n 's/.*>\(world-[0-9\-]\+\.png\).*/\1/p'`
fi
if [[ "$FILES" == "" ]]; then
echo "ERROR: Could not detect latest map file."
exit
fi
for FILE in $FILES; do
REMOTE_URL="$MAPSERVER/$FILE"
LOCAL_FILE="`echo $FILE | sed 's#.*/##'`"
LOCAL_URL="$OUTDIR/$LOCAL_FILE"
MAPNAME=`echo $LOCAL_URL | sed 's/.*\/\([^\.]\+\).*/\1/g'`
echo "# Downloading and converting $MAPNAME."
mkdir -p $OUTDIR
cd $OUTDIR
if [ ! -d "$OUTDIR/$MAPNAME" ]; then
echo "Downloading latest map file..."
curl -C - "$REMOTE_URL" -o "$LOCAL_URL"
if [ "$mode" == "legacy" ]; then
echo "Patching map (for map exports prior to 2019-07-09)..."
OSIZE=`file $LOCAL_URL | sed -n 's/.*PNG image data, \([0-9]\+\).*/\1/p'`
NSIZE=$(($OSIZE+1008))
RESIZED_URL="$LOCAL_URL-temp.png"
convert $LOCAL_URL -gravity SouthEast -extent ${NSIZE}x${NSIZE} $RESIZED_URL
rm $LOCAL_URL
mv $RESIZED_URL $LOCAL_URL
fi
echo "Resizing map..."
OSIZE=`file $LOCAL_URL | sed -n 's/.*PNG image data, \([0-9]\+\).*/\1/p'`
NSIZE=$((2**6 * 256))
RESIZED_URL="$LOCAL_URL-resized.png"
convert $LOCAL_URL -extent ${NSIZE}x${NSIZE} -gravity NorthWest $RESIZED_URL
echo "Converting map..."
$SCRIPT_DIR/convert_maps.sh $MAPNAME $RESIZED_URL
echo "Cleaning up..."
rm $RESIZED_URL
rm $LOCAL_URL
else
echo "Skipping $MAPNAME."
fi
done