trips/router/scripts/setup-osrm.sh
Greg Pomerantz 3da04c111e Move runtime artifacts out of the source tree to ~/trips
The dev directory now holds source code + compiled binaries only:
  ~/trips/osm/          OSM PBF extracts (was osm/, 1.4 GB)
  ~/trips/tilecache/    mock tile cache (was mock/.tilecache)
  ~/trips/store/mock/   per-trip uploads + chat logs (was mock/store, PII)
  ~/trips/logs/         server.log
  ~/trips/stale-osm-build/  stale source/tarball dup of ~/osm-build
                           (repo osm/build had no binaries; the live OSRM
                           toolchain + graphs already lived in ~/osm-build)

Code now points at the new locations, all overridable via env:
- mock/server.js: TRIPS_HOME (default ~/trips) for tile cache + store
- setup-osrm.sh / setup-osrm-colombia.sh: OSM_DIR (default ~/trips/osm)
- spatial/compose+import.sh: OSM_DIR (default ~/trips/osm)
- .gitignore: rewritten — no artifact paths remain in-tree
2026-09-10 10:03:04 -04:00

95 lines
3.4 KiB
Bash
Executable File

#!/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
#
# Artifacts live in $W (default: $HOME/osm-build — durable; the extract
# is ~8 GB under $W/data). Raw PBFs live in ~/trips/osm (~1.1 GB; the dev
# tree holds source only — override with OSM_DIR).
set -euo pipefail
cd "$(dirname "$0")"
W="${W:-$HOME/osm-build}"
P="$W/prefix"
OSM_DIR="${OSM_DIR:-$HOME/trips/osm}" # raw PBFs live outside the dev tree
mkdir -p "$OSM_DIR"
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
# The built OSRM binaries carry an RPATH baked in at configure time;
# if $W ever moves, this keeps them finding their TBB/boost libs.
export LD_LIBRARY_PATH="$P/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
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"