summaryrefslogtreecommitdiff
path: root/scripts/convert_all.sh
diff options
context:
space:
mode:
authorMarkus Koch <markus@notsyncing.net>2021-11-02 16:45:22 +0100
committerMarkus Koch <markus@notsyncing.net>2021-11-02 16:45:22 +0100
commit4625d4e25b5ebe98acc2bad69bed95dccd6037fd (patch)
tree1daab9d447ed275b543e05b2eda0e60ef2a424e2 /scripts/convert_all.sh
parent50d9ee43b0baf5ce6be688aa7ea8932fb67242d5 (diff)
downloadlifomapserver-4625d4e25b5ebe98acc2bad69bed95dccd6037fd.tar.gz
lifomapserver-4625d4e25b5ebe98acc2bad69bed95dccd6037fd.tar.bz2
lifomapserver-4625d4e25b5ebe98acc2bad69bed95dccd6037fd.zip
scripts: Modify map script to download and convert all available maps
Diffstat (limited to 'scripts/convert_all.sh')
-rwxr-xr-xscripts/convert_all.sh62
1 files changed, 62 insertions, 0 deletions
diff --git a/scripts/convert_all.sh b/scripts/convert_all.sh
new file mode 100755
index 0000000..cf566ad
--- /dev/null
+++ b/scripts/convert_all.sh
@@ -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