Files
planet/scripts/harness/install-earth-boundary-tools.sh
T

63 lines
2.7 KiB
Bash
Executable File

#!/usr/bin/env bash
# Install the Earth boundary PMTiles toolchain (tippecanoe + pmtiles) into a
# user prefix without sudo. Production images build the same tools in
# backend/Dockerfile; this script is only for local WSL/Linux development.
set -euo pipefail
PREFIX="${PLANET_TOOLS_PREFIX:-$HOME/.local}"
TIPPECANOE_REF="${TIPPECANOE_REF:-2.79.0}"
PMTILES_VERSION="${PMTILES_VERSION:-1.31.2}"
SQLITE_AMALGAMATION="${SQLITE_AMALGAMATION:-sqlite-amalgamation-3500400}"
SQLITE_YEAR="${SQLITE_YEAR:-2025}"
mkdir -p "$PREFIX/bin"
work="$(mktemp -d "${TMPDIR:-/tmp}/planet-earth-tools.XXXXXX")"
trap 'rm -rf "$work"' EXIT
have() { command -v "$1" >/dev/null 2>&1; }
if have tippecanoe && [ "${FORCE:-0}" != "1" ]; then
echo "ok: tippecanoe already installed ($(command -v tippecanoe))"
else
sqlite_flags=(PLANET_TOOLS_BUILD=1)
if [ ! -f /usr/include/sqlite3.h ]; then
echo "info: sqlite3 headers missing; building static sqlite amalgamation"
curl -fsSL "https://www.sqlite.org/${SQLITE_YEAR}/${SQLITE_AMALGAMATION}.zip" -o "$work/sqlite.zip"
(cd "$work" && python3 -m zipfile -e sqlite.zip .)
sqlite_dir="$work/$SQLITE_AMALGAMATION"
mkdir -p "$work/sqlite/include" "$work/sqlite/lib"
cp "$sqlite_dir/sqlite3.h" "$work/sqlite/include/"
cc -O2 -DSQLITE_THREADSAFE=1 -c "$sqlite_dir/sqlite3.c" -o "$work/sqlite/sqlite3.o"
ar rcs "$work/sqlite/lib/libsqlite3.a" "$work/sqlite/sqlite3.o"
# The tippecanoe Makefile appends to CFLAGS/CXXFLAGS/LDFLAGS inherited from env.
sqlite_flags=(
"CFLAGS=-I$work/sqlite/include"
"CXXFLAGS=-I$work/sqlite/include"
"LDFLAGS=-L$work/sqlite/lib -ldl"
)
fi
git clone --depth 1 --branch "$TIPPECANOE_REF" https://github.com/felt/tippecanoe.git "$work/tippecanoe"
env "${sqlite_flags[@]}" make -C "$work/tippecanoe" -j"$(nproc)" tippecanoe tile-join
install -m 0755 "$work/tippecanoe/tippecanoe" "$work/tippecanoe/tile-join" "$PREFIX/bin/"
echo "ok: installed tippecanoe into $PREFIX/bin"
fi
if have pmtiles && [ "${FORCE:-0}" != "1" ]; then
echo "ok: pmtiles already installed ($(command -v pmtiles))"
else
arch="$(uname -m)"
case "$arch" in
x86_64) arch="x86_64" ;;
aarch64|arm64) arch="arm64" ;;
*) echo "error: unsupported arch $arch" >&2; exit 1 ;;
esac
url="https://github.com/protomaps/go-pmtiles/releases/download/v${PMTILES_VERSION}/go-pmtiles_${PMTILES_VERSION}_Linux_${arch}.tar.gz"
curl -fsSL "$url" -o "$work/pmtiles.tar.gz"
tar -xzf "$work/pmtiles.tar.gz" -C "$work" pmtiles
install -m 0755 "$work/pmtiles" "$PREFIX/bin/pmtiles"
echo "ok: installed pmtiles into $PREFIX/bin"
fi
"$PREFIX/bin/tippecanoe" --version 2>&1 | head -1 || true
"$PREFIX/bin/pmtiles" version 2>&1 | head -1 || true