Skip to content

Instantly share code, notes, and snippets.

@avrahamappel
Created May 10, 2026 17:38
Show Gist options
  • Select an option

  • Save avrahamappel/87e154e8015c26220fbfe9765d8cf72a to your computer and use it in GitHub Desktop.

Select an option

Save avrahamappel/87e154e8015c26220fbfe9765d8cf72a to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -euo pipefail
# --------------------------------------------------------------------
# Configuration
# --------------------------------------------------------------------
# Directory where temporary files will be stored
WORKDIR="${HOME}/garmin_map_update"
mkdir -p "${WORKDIR}"
# Destination mount point of the Nuvi device
# Change this to match your system
GARMIN_MOUNT="/media/garmin" # Linux
# GARMIN_MOUNT="/Volumes/Garmin" # macOS
# OSM extract URLs (central/eastern US + Canada)
# Sources: https://download.geofabrik.de/
OSM_URLS=(
"https://download.geofabrik.de/north-america/us/western-oregon-latest.osm.pbf"
"https://download.geofabrik.de/north-america/us/midwest-latest.osm.pbf"
"https://download.geofabrik.de/north-america/us/eastern-latest.osm.pbf"
"https://download.geofabrik.de/north-america/canada/ontario-latest.osm.pbf"
"https://download.geofabrik.de/north-america/canada/quebec-latest.osm.pbf"
)
# Output folder inside the Nuvi where Garmin expects map files
GARMIN_MAP_DIR="${GARMIN_MOUNT}/Garmin/Map"
# --------------------------------------------------------------------
# Helper functions
# --------------------------------------------------------------------
log() {
echo -e "[\e[32m$(date +'%H:%M:%S')\e[0m] $*"
}
error_exit() {
echo -e "\e[31mERROR: $*\e[0m" >&2
exit 1
}
# --------------------------------------------------------------------
# Main steps
# --------------------------------------------------------------------
log "Starting Garmin Nuvi map update..."
# Ensure the device is mounted
[[ -d "${GARMIN_MOUNT}" ]] || error_exit "Garmin mount point not found: ${GARMIN_MOUNT}"
# Create map directory if it doesn't exist
mkdir -p "${GARMIN_MAP_DIR}"
# Download each OSM extract (skip if already present)
for url in "${OSM_URLS[@]}"; do
filename=$(basename "${url}")
dest="${WORKDIR}/${filename}"
if [[ -f "${dest}" ]]; then
log "Found existing ${filename}, skipping download."
else
log "Downloading ${filename} ..."
wget -q --show-progress -O "${dest}" "${url}"
fi
done
# Convert each .pbf into Garmin .img using gpsbabel
for pbf in "${WORKDIR}"/*.osm.pbf; do
base=$(basename "${pbf}" .osm.pbf)
img="${WORKDIR}/${base}.img"
if [[ -f "${img}" ]]; then
log "Image ${base}.img already exists, skipping conversion."
continue
fi
log "Converting ${base}.osm.pbf → ${base}.img ..."
gpsbabel -i osm -f "${pbf}" -o garminimg -F "${img}" \
--garminimg-zoom-levels=0,10 \
--garminimg-wpt-plane=off \
--garminimg-veh-attr=on \
--garminimg-route=off \
--garminimg-attr-limit=2
done
# Copy the .img files to the Nuvi
log "Copying .img files to the device..."
cp -v "${WORKDIR}"/*.img "${GARMIN_MAP_DIR}/"
# Optional: clean up old map files (delete non‑generated .img files)
# Uncomment if you want a clean map folder each run:
# find "${GARMIN_MAP_DIR}" -type f -name "*.img" ! -path "${WORKDIR}/*.img" -delete
log "Map update complete. Safely eject your Nuvi device."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment