mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-10-25 18:40:06 -04:00
Drop .pgpass handling, Postgres ownership repairs, and the docker db container viewability rules. Update comments and pi-gen map docs for SQLite/PMTiles. Help submodule documents the new database layout.
86 lines
3 KiB
Bash
Executable file
86 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 legacy Postgres client credentials (no longer used).
|
|
rm -f /home/wrolpi/.pgpass
|
|
|
|
# --- 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."
|