| 1 | #!/bin/bash |
| 2 | |
| 3 | # Script to delete tiles that only contain water (usually in the |
| 4 | # middle of an ocean) in the higher numbered zoomlevels. These |
| 5 | # are trivial to regenerate (far less than one second) at any |
| 6 | # time. |
| 7 | |
| 8 | # Some settings |
| 9 | # Minimum Zoom in which we delete |
| 10 | MINZ=10 |
| 11 | |
| 12 | # Maximum Zoom in which we delete |
| 13 | MAXZ=20 |
| 14 | |
| 15 | # Age in days after which we delete |
| 16 | AGE=3 |
| 17 | |
| 18 | declare -A TMD5 |
| 19 | # the md5sum of a metatile containing only water? |
| 20 | TMD5[osmde]="c6501cefd852a2c5b16f297948ca309c" |
| 21 | TMD5[osmorg]="9d7ceeb7ab3a0905abf200f1a7608f92" |
| 22 | TMD5[osmhd]="d47bd18df80dbefb2f89b81a672cae92" |
| 23 | |
| 24 | declare -A TSIZE |
| 25 | # the size of a metatile containing only water? |
| 26 | TSIZE[osmde]=7124 |
| 27 | TSIZE[osmorg]=7124 |
| 28 | TSIZE[osmhd]=8596 |
| 29 | |
| 30 | declare -A TDIR |
| 31 | # Directory that contains the tiles? (with trailing slash!) |
| 32 | TDIR[osmde]="/mnt/tiles/tiles/osmde/" |
| 33 | TDIR[osmorg]="/mnt/tiles/tiles/osm/" |
| 34 | TDIR[osmhd]="/mnt/tiles/tiles/osmhd/" |
| 35 | |
| 36 | NDELETED=0 |
| 37 | for style in "osmde" "osmorg" "osmhd" |
| 38 | do |
| 39 | echo "Handling style: $style - looking for files with size ${TSIZE[$style]} and md5sum ${TMD5[$style]} in ${TDIR[$style]}" |
| 40 | for z in `seq $MINZ $MAXZ` |
| 41 | do |
| 42 | if [ ! -d "${TDIR[$style]}${z}" ] ; then |
| 43 | continue |
| 44 | fi |
| 45 | for tiles in `find ${TDIR[$style]}${z} -xdev -type f -name '*.meta' -size ${TSIZE[$style]}c -mtime +${AGE} -print` |
| 46 | do |
| 47 | # We need to skip the first 20 bytes of the file as they contain the metafile |
| 48 | # header that contains the x/y location of the tile. |
| 49 | TILEMD5=`tail -c +20 $tiles | md5sum -b | sed -e 's/ .*//g'` |
| 50 | if [ "$TILEMD5" == "${TMD5[$style]}" ] ; then |
| 51 | echo "Deleting $tiles" |
| 52 | rm $tiles |
| 53 | if [ $? -ne 0 ] ; then |
| 54 | echo "There was an error deleting $tiles." |
| 55 | echo "Aborting after deleting $NDELETED files." |
| 56 | exit 1 |
| 57 | fi |
| 58 | let "NDELETED=NDELETED+1" |
| 59 | #else |
| 60 | # echo "$tiles is not a water tile." |
| 61 | fi |
| 62 | done |
| 63 | done |
| 64 | done |
| 65 | |
| 66 | echo "$NDELETED files deleted." |
| 67 | |