My OSM vector tile script

I use the fantastic OpenMapTiles project to generate my OSM vector tiles. There’s nothing complicated or magical in my bash script I use to handle everything, but if you don’t bash, maybe it’ll be helpful.

I grab US South from Geofabrik, as it covers the extent I need, which I chop to size using osmconvert (available in the Arch User Repository if that applies to you). I drop the chopped PBF into the OpenMapTiles data folder with the name meck.osm.pbf, and then call meck.

When tiles.mbtiles file is ready, I use scp to move it to a server under a temporary name to avoid down time while it uploads. Then I use ssh to remotely swap the uploaded file into production (osm.mbtiles). The previous tile set is retained until the next upload in case something terrible happened.

The MBTiles file is ~160MB, which for a multi-state area still blows my mind, and the whole process on my i3 desktop with 32GB of RAM takes 15-20 minutes, depending on how fast Time Warner is feeling.

#! /bin/bash

set -e -o pipefail

echo "Removing us-south..."
if [ -f us-south-latest.osm.pbf ] ; then
 rm us-south-latest.osm.pbf

echo "Getting OSM data..."
wget -q --show-progress

echo "Removing meck.osm.pbf..."
if [ -f ~/workspace/openmaptiles/data/meck.osm.pbf ] ; then
 rm ~/workspace/openmaptiles/data/meck.osm.pbf

echo "Clipping PBF..."
osmconvert us-south-latest.osm.pbf -b=-82.641,34.125,-79.008,36.762 --complex-ways -o=openmaptiles/data/meck.osm.pbf

echo "Get to the right place..."
cd ~/workspace/openmaptiles

echo "Run OpenMapTiles..."
./ meck

echo "Move tiles to your server in temp location..."
scp ./data/tiles.mbtiles

echo "Swap active tiles on server..."
ssh "rm /opt/apps/node/mbtiles-server/osm.mbtiles.old && mv /opt/apps/node/mbtiles-server/osm.mbtiles /opt/apps/node/mbtiles-server/osm.mbtiles.old && mv /opt/apps/node/mbtiles-server/tiles.mbtiles /opt/apps/node/mbtiles-server/osm.mbtiles"