Library sync OsmAnd-style: brick is the server, a client (the car's maptool, SYNC_SERVER_URL) syncs on its Sync button — pulls the server's rows, pushes its own with the source files the server lacks, newer updated_at wins; /api/sync/* guarded by SYNC_TOKEN (written into brick's .env by CI). TRUSTED_NETWORKS logs in the car's LAN (no Gitea offline); TAKEOUT_HOST_DIR for a server without the Takeout; bin/pull-maps.sh pulls map data one way while at home
This commit is contained in:
1 parent
850a5946ad
commit
dbe742321a
13 files changed
+460
-5
No files matched your search
Executable
+37
@@ -0,0 +1,37 @@
|
||||
#!/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
|
||||
Reference in new issue
Block a user