scripts: Add script to easily convert the latest map
This commit is contained in:
parent
a91175fdd8
commit
8c7825d121
53
scripts/convert_latest.sh
Executable file
53
scripts/convert_latest.sh
Executable file
@ -0,0 +1,53 @@
|
|||||||
|
#!/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
|
@ -11,8 +11,8 @@
|
|||||||
# `convert $MAPFILE -extent ${crop}x${crop} -gravity NorthWest $MAPFILE.scaled.png`
|
# `convert $MAPFILE -extent ${crop}x${crop} -gravity NorthWest $MAPFILE.scaled.png`
|
||||||
|
|
||||||
TILESIZE=256
|
TILESIZE=256
|
||||||
MAPNAME="world-2020-04-09"
|
MAPNAME="$1"
|
||||||
MAPFILE="../$MAPNAME.png"
|
MAPFILE="$2"
|
||||||
|
|
||||||
width=`file "$MAPFILE" | sed -n "s/.* \([0-9]\+\) x \([0-9]\+\).*/\1/p"`
|
width=`file "$MAPFILE" | sed -n "s/.* \([0-9]\+\) x \([0-9]\+\).*/\1/p"`
|
||||||
crop=$TILESIZE
|
crop=$TILESIZE
|
||||||
|
Loading…
Reference in New Issue
Block a user