Files
maptool/bin/pull-maps.sh
T

38 lines
1.6 KiB
Bash
Executable File

#!/bin/bash
# Map data, one way: the home server (brick) builds it, the car's server
# pulls it — only while at home (brick reachable), never over LTE. The
# library goes both ways on its own (lib/maptool/sync.rb), not here.
#
# Run by maptool-pull-maps.timer on the car's server (docs/deployment.adoc).
# The key it uses is limited on brick to read-only rsync of the data dir:
# command="python3 /usr/share/doc/packages/rsync/support/rrsync -ro /srv/podman/maptool/data",restrict ssh-ed25519 …
# so paths below are relative to brick's data/.
set -euo pipefail
SOURCE=${MAP_SOURCE:-randy@10.17.240.2}
DATA=${MAP_DATA:-/srv/podman/maptool/data}
FILES="offline.pmtiles offline.pmtiles.meta.json terrain.pmtiles terrain.pmtiles.meta.json offline_regions.json"
DIRS="routing places hiking_trails kiwix nps"
host=${SOURCE#*@}
if ! timeout 5 bash -c "</dev/tcp/$host/22" 2>/dev/null; then
echo "pull-maps: $host not reachable (not at home), skipping"
exit 0
fi
changes=$(mktemp)
trap 'rm -f "$changes"' EXIT
# Into a temp file, renamed when complete (rsync's default): the app and
# Valhalla keep reading the old copy until restarted.
for f in $FILES; do
rsync -a --partial-dir=.rsync-partial --out-format='%n' "$SOURCE:$f" "$DATA/$f" >> "$changes" 2>/dev/null || true
done
for d in $DIRS; do
rsync -a --delete-delay --partial-dir=.rsync-partial --out-format='%n' "$SOURCE:$d/" "$DATA/$d/" >> "$changes"
done
if grep -qv '/$' "$changes"; then
echo "pull-maps: $(grep -cv '/$' "$changes") files updated, restarting maptool"
sudo systemctl restart podman-compose@maptool.service
fi