scripts: Modify map script to download and convert all available maps
This commit is contained in:
parent
50d9ee43b0
commit
4625d4e25b
62
scripts/convert_all.sh
Executable file
62
scripts/convert_all.sh
Executable file
@ -0,0 +1,62 @@
|
||||
#!/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
|
@ -1,53 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
MAPSERVER='https://lifomaps.de'
|
||||
TILESERVER="notsyncing.net:/srv/http/maps.linux-forks.de/tiles/"
|
||||
OUTDIR=`pwd`/out
|
||||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
|
||||
|
||||
FILE=`curl "$MAPSERVER" | sed -n 's/.*>\(world-[0-9\-]\+\.png\).*/\1/p' | tail -n 1`
|
||||
|
||||
if [[ "$FILE" == "" ]]; then
|
||||
echo "ERROR: Could not detect latest map file."
|
||||
exit
|
||||
fi
|
||||
|
||||
if [[ -f "$OUTDIR/uploaded" ]]; then
|
||||
echo "INFO: Latest map has already been converted."
|
||||
exit
|
||||
fi
|
||||
|
||||
REMOTE_URL="$MAPSERVER/$FILE"
|
||||
LOCAL_URL="$OUTDIR/$FILE"
|
||||
MAPNAME=`echo $LOCAL_URL | sed 's/.*\/\([^\.]\+\).*/\1/g'`
|
||||
|
||||
echo "# Downloading and converting $MAPNAME."
|
||||
|
||||
mkdir -p $OUTDIR
|
||||
cd $OUTDIR
|
||||
|
||||
if [ ! -f "$OUTDIR/converted" ]; then
|
||||
echo "Downloading latest map file..."
|
||||
curl -C - "$REMOTE_URL" -o "$LOCAL_URL"
|
||||
|
||||
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 "" > $OUTDIR/converted
|
||||
fi
|
||||
|
||||
echo "Uploading files..."
|
||||
|
||||
scp -r $OUTDIR/$MAPNAME $TILESERVER
|
||||
echo "" > $OUTDIR/uploaded
|
||||
|
||||
echo "Cleaning up..."
|
||||
read
|
||||
rm $RESIZED_URL
|
||||
rm $LOCAL_URL
|
Loading…
Reference in New Issue
Block a user