#!/bin/bash # -------------------------------------------------------------------------- # Intaleq Map Platform - 10-Day Update Script # سكربت تحديث خرائط انطلاقة - التحديث الدوري (كل 10 أيام) # -------------------------------------------------------------------------- set -e # Exit on error echo "🚀 Starting 10-day map update..." # 1. Configuration (From .env or defaults) PBF_FILE="/data/jordan-latest.osm.pbf" SOURCE_URL="https://download.geofabrik.de/asia/jordan-latest.osm.pbf" APP_DIR="/home/hamzadoctor/app" cd "$APP_DIR" # 2. Download latest OSM data (Running on Host) # تحميل أحدث البيانات للأردن وسوريا echo "🌍 Downloading latest OpenStreetMap data for Jordan & Syria..." wget -O "infrastructure/osm-data/jordan-latest.osm.pbf.new" "https://download.geofabrik.de/asia/jordan-latest.osm.pbf" wget -O "infrastructure/osm-data/syria-latest.osm.pbf.new" "https://download.geofabrik.de/asia/syria-latest.osm.pbf" mv "infrastructure/osm-data/jordan-latest.osm.pbf.new" "infrastructure/osm-data/jordan-latest.osm.pbf" mv "infrastructure/osm-data/syria-latest.osm.pbf.new" "infrastructure/osm-data/syria-latest.osm.pbf" # 3. Import new data to PostGIS # استيراد البيانات إلى قاعدة البيانات echo "💾 Importing Jordan (Create)..." docker compose --profile import run --rm osm-import osm2pgsql --create --slim --cache 1000 --database mapdb --host db --user mapuser /data/jordan-latest.osm.pbf echo "💾 Importing Syria (Append)..." docker compose --profile import run --rm osm-import osm2pgsql --append --slim --cache 1000 --database mapdb --host db --user mapuser /data/syria-latest.osm.pbf # 4. Merge Data (Jordan + Syria) OSM_FILE="infrastructure/osm-data/region.osm.pbf" echo "🗺️ Merging Jordan and Syria data into $OSM_FILE..." osmium merge infrastructure/osm-data/jordan-latest.osm.pbf infrastructure/osm-data/syria-latest.osm.pbf -o $OSM_FILE --overwrite # 5. Spatial Integrity check for Geocoding (Landmarks) # Purge any legacy landmarks outside the expanded region echo "📍 Syncing user-submitted landmarks and purging invalid coordinates..." DELETED_COUNT=$(docker compose exec -T db psql -U mapuser -d mapdb -t -c "DELETE FROM places_syria WHERE longitude < 34 OR longitude > 43 OR latitude < 29 OR latitude > 38;") echo " ✅ Purged ${DELETED_COUNT//[[:space:]]/} invalid landmarks outside the expanded region." # Force Spatial Geometry Update docker compose exec -T db psql -U mapuser -d mapdb -c "UPDATE places_syria SET location = ST_SetSRID(ST_MakePoint(longitude, latitude), 4326) WHERE location IS NULL OR latitude IS NOT NULL;" # 6. Rebuild Routing Index (GraphHopper) echo "🚗 Rebuilding GraphHopper routing index (This may take ~5-8 minutes)..." docker compose stop routing # Delete old cache - VERY IMPORTANT to force full re-index rm -rf infrastructure/osm-data/graph-cache infrastructure/osm-data/default-gh docker compose up -d routing # 7. Final Cleanup & Cache Flush echo "🧹 Clearing Redis traffic cache..." docker compose exec -T redis redis-cli flushall echo "Done! Map platform is now fully synchronized with Jordan & Syria roads (including Damascus)."