wrolpi/scripts/install_protomaps.sh
lrnselfreliance 899ab13964
Consolidate map-tool install into wrolpi/scripts/install_map_tools.sh (#538)
The pmtiles CLI + tippecanoe install was duplicated across three places
(scripts/install_protomaps.sh, the Debian Live hook, and pi-gen), so a version
bump or logic change had to be made in all of them in lockstep. Move it into a
single shared, version-guarded, SHA-pinned installer and have all three callers
invoke it.

- New wrolpi/scripts/install_map_tools.sh: installs pmtiles (per-arch binary,
  SHA-pinned for amd64 and arm64) and builds tippecanoe (source tarball,
  arch-independent SHA). Version-guarded, so an image that already baked in the
  pinned versions makes the on-device run a no-op until a version bumps.
- pi-gen 03-run-chroot.sh, the Debian hook, and install_protomaps.sh now just
  call the shared script. This also adds SHA pinning to the on-device pmtiles
  path (previously unpinned).

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-15 15:55:06 -06:00

88 lines
3 KiB
Bash
Executable file

#!/usr/bin/env bash
# Installs PMTiles tools and migrates from the old Leaflet/renderd/Apache2 map stack.
# This script is idempotent — safe to run multiple times.
# Called by upgrade.sh during the upgrade process.
set -e
set -x
# --- Install/upgrade the map toolchain (pmtiles CLI + tippecanoe) ---
# Shared with the pi-gen and Debian Live image builds so the versions and hash
# pins live in one place. Version-guarded, so this is a no-op when the running
# image already baked in the current versions.
/opt/wrolpi/wrolpi/scripts/install_map_tools.sh || echo "Map tool installation failed, continuing..."
# --- Migrate from old map stack (runs once) ---
MARKER_FILE="/opt/wrolpi/.protomaps_installed"
if [ -f "${MARKER_FILE}" ]; then
echo "Protomaps migration already completed."
exit 0
fi
echo "Migrating map stack to Protomaps (MapLibre GL JS + PMTiles)..."
# --- Step 1: Stop and disable old map services ---
echo "Stopping old map services..."
systemctl stop renderd 2>/dev/null || :
systemctl stop apache2 2>/dev/null || :
systemctl stop postgresql@15-map.service 2>/dev/null || :
systemctl disable renderd 2>/dev/null || :
systemctl disable apache2 2>/dev/null || :
systemctl disable postgresql@15-map.service 2>/dev/null || :
# --- Step 2: Uninstall old map packages ---
echo "Removing old map packages..."
apt-get remove -y --purge apache2 apache2-dev apache2-doc libapache2-mod-tile renderd osm2pgsql 2>/dev/null || :
apt-get autoremove -y 2>/dev/null || :
# --- Step 3: Drop the map PostgreSQL cluster ---
echo "Removing map PostgreSQL cluster..."
if pg_lsclusters 2>/dev/null | grep -q "15.*map"; then
pg_dropcluster --stop 15 map 2>/dev/null || :
fi
# Remove the map database blob (no longer needed, saves ~1.2 GB).
if [ -f /opt/wrolpi-blobs/map-db-gis.dump ]; then
chattr -i /opt/wrolpi-blobs/map-db-gis.dump 2>/dev/null || :
rm -f /opt/wrolpi-blobs/map-db-gis.dump
echo "Removed map-db-gis.dump blob."
fi
# --- Step 4: Clean up old config files ---
rm -f /etc/renderd.conf
rm -f /etc/apache2/ports.conf
rm -f /etc/apache2/conf-available/mod_tile.conf
rm -f /etc/apache2/sites-available/000-default.conf
rm -rf /etc/systemd/system/postgresql@15-map.service.d
rm -f /var/www/html/leaflet.js /var/www/html/leaflet.css
# Remove old .pgpass entry for the map database.
if [ -f /home/wrolpi/.pgpass ]; then
sed -i '/5433/d' /home/wrolpi/.pgpass
fi
# --- Step 5: Update wrolpi.target to remove old services ---
# The target file is copied from the repo by repair.sh, but update the installed copy now.
if [ -f /etc/systemd/system/wrolpi.target ]; then
sed -i 's/ renderd\.service//' /etc/systemd/system/wrolpi.target
sed -i 's/ apache2\.service//' /etc/systemd/system/wrolpi.target
sed -i 's/ postgresql@15-map\.service//' /etc/systemd/system/wrolpi.target
fi
systemctl daemon-reload
# --- Step 6: Mark migration as complete ---
touch "${MARKER_FILE}"
chown wrolpi:wrolpi "${MARKER_FILE}"
echo "Protomaps migration completed successfully."
echo "Map files (.pmtiles) should be placed in /media/wrolpi/map/"
echo "The map viewer is served by Caddy on port 8084."