#!/usr/bin/env bash # Build + run the self-hosted OSRM router over the NH+MA+CT+NY extract. # # Steps: deps.sh (bzip2/lua/tbb/boost/osmium, no sudo) → build OSRM 26.4.1 # → merge the 4 state PBFs → extract → partition → customize → serve :5000. # # Usage: scripts/setup-osrm.sh # everything, then serve # scripts/setup-osrm.sh --no-serve # build + extract, don't serve # # NOTE: /tmp is wiped on reboot. For a persistent install set W to a # durable dir (and the extract's ~8 GB lives under $W/data). # # PBFs are pre-downloaded in ../../osm/ (see router/README.md); ~1.1 GB. set -euo pipefail cd "$(dirname "$0")" W="${W:-/tmp/osm-build}" P="$W/prefix" OSM_DIR="$(cd ../.. && pwd)/osm" DATA_DIR="${DATA_DIR:-$W/data}" OSRM_SRC="$W/osrm-backend-26.4.1" OSRM_BIN="$W/build" SERVE=1 [ "${1:-}" = "--no-serve" ] && SERVE=0 mkdir -p "$DATA_DIR" step() { echo; echo "=== $1"; } step "1/6 dependencies (bzip2, lua, tbb, boost, osmium)" bash deps.sh step "2/6 OSRM 26.4.1" if [ ! -d "$OSRM_SRC" ]; then curl -sL -o "$W/osrm.tar.gz" https://github.com/Project-OSRM/osrm-backend/archive/refs/tags/v26.4.1.tar.gz tar -C "$W" -xzf "$W/osrm.tar.gz" fi if [ ! -x "$OSRM_BIN/osrm-extract" ]; then # -Wno-maybe-uninitialized: GCC 12 + boost 1.84 spirit X3 false positive # under OSRM's -Werror. cmake -S "$OSRM_SRC" -B "$OSRM_BIN" \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_PREFIX_PATH="$P" \ -DCMAKE_CXX_FLAGS="-Wno-maybe-uninitialized" cmake --build "$OSRM_BIN" -j"$(nproc)" fi ls -la "$OSRM_BIN"/osrm-extract "$OSRM_BIN"/osrm-routed step "3/6 OSM PBFs (NH+MA+CT+NY)" if [ ! -s "$OSM_DIR/us-new-hampshire.osm.pbf" ]; then echo "PBFs missing; downloading from the geofabrik HF mirror (~1.1 GB)..." for f in us-new-hampshire us-connecticut us-massachusetts us-new-york; do [ -s "$OSM_DIR/$f.osm.pbf" ] || curl -sL -o "$OSM_DIR/$f.osm.pbf" \ "https://huggingface.co/datasets/NoeFlandre/osm-geofabrik-raw-pbf-extracts/resolve/main/$f-latest.osm.pbf" done fi ls -la "$OSM_DIR"/us-*.osm.pbf step "4/6 merge PBFs (osrm-extract takes one input file)" MERGED="$DATA_DIR/northeast.osm.pbf" if [ ! -s "$MERGED" ]; then "$W/osmium-build/osmium" merge \ "$OSM_DIR/us-new-hampshire.osm.pbf" \ "$OSM_DIR/us-connecticut.osm.pbf" \ "$OSM_DIR/us-massachusetts.osm.pbf" \ "$OSM_DIR/us-new-york.osm.pbf" \ -o "$MERGED" fi ls -la "$MERGED" step "5/6 extract + partition + customize (extract needs ~9-12GB RAM)" if [ ! -s "$DATA_DIR/northeast.osrm.ebg" ]; then "$OSRM_BIN/osrm-extract" "$MERGED" \ -p "$OSRM_SRC/profiles/car.lua" \ -o "$DATA_DIR/northeast" fi if [ ! -s "$DATA_DIR/northeast.osrm.partition" ]; then "$OSRM_BIN/osrm-partition" "$DATA_DIR/northeast" fi if [ ! -s "$DATA_DIR/northeast.osrm.tld" ]; then # v26 bakes the profile into the extract; customize takes no -p. "$OSRM_BIN/osrm-customize" "$DATA_DIR/northeast" fi if [ "$SERVE" = 0 ]; then echo "done (not serving; start with: $OSRM_BIN/osrm-routed --algorithm mld --port 5000 $DATA_DIR/northeast.osrm)" exit 0 fi step "6/6 serve on :5000 (Ctrl-C to stop)" exec "$OSRM_BIN/osrm-routed" --algorithm mld --port 5000 "$DATA_DIR/northeast.osrm"