Device notifier script for updating OSM map on Garmin device

I am regularly mapping things in Openstreetmap with my Garmin Nüvi 205 and a second GPS Tracker (iBlue 747a+).

It is very usefull to have a current version of the OSM map on the Garmin device, so that you see what is actually missing in the map when you are in the field.

I used to manually download the map file from http://dev.openstreetmap.de/aio/ and then uncompressing it to the garmin device. But I was getting tired of doing this repetitive task and so I wrote a script for this….

The script can be executed via the device notifier in KDE4 (more infos about device notifier can be found in an older blogpost of mine: Adding actions to the Device Notifier widget in KDE 4.3).


After selecting “Update OSM map on Garmin device” in the device notifier the script downloads the map and shows a progressbar.

When it is finished a pop-up appears and the device can be removed via device notifier.

I have attached the script (update_map.sh)  and the device notifier config (update_map.desktop) to this post.

The script needs the package “pv” (pipe viewer). It can be installed in kubuntu with “apt-get install pv“.

update_map.sh (place it in /usr/local/bin)

#!/bin/bash

url=http://dev.openstreetmap.de/aio/germany/gmapsupp.img.bz2
path=$1
target_dir=$path/Garmin
target_file=$target_dir/gmapsupp.img

progressfile=/tmp/progress_$$
echo 0 > $progressfile

function watch_progress {
dbusRef=$1
while [ true ]
do
sleep 1
# check if dbus object exists
qdbus $dbusRef 1>/dev/null 2>&1
if [ “$?” -ne “0” ]
then
# dbus Object does not exist (anymore)
exit 0
fi

# read current progress
progress=`tail -n1 $progressfile`

# set progress to progressbar
qdbus $dbusRef Set “” “value” $progress
done

}

if [ ! -d $target_dir ]
then
kdialog –msgbox “$target_dir does not exist!”
exit 1
fi

kdialog –yesno “Update OSM Map on $target_dir ?”
ret=$?

if [ “$ret” -eq “0” ]
then

# get file size
size=`curl -sI $url | grep Content-Length | cut -d ‘ ‘ -f 2 | sed “s/[^0-9]//g”`
kbsize=$((size/1024))k

dbusRef=`kdialog –progressbar “Downloading OSM Map” 100`
watch_progress “$dbusRef” &

wget -qO- $url | pv -s $kbsize -n 2>$progressfile | bunzip2 > $target_file
sync
sync

qdbus $dbusRef close
rm -f $progressfile

error=0
#check return codes in pipe
for rc in ${PIPESTATUS[*]}
do

if [ “$rc” -ne “0” ]
then
error=1
fi
done

if [ “$error” -ne “0” ]
then
kdialog –msgbox “There was an error updating the map”;
else
kdialog –msgbox “The map was updated successfully – You may now disconnect the device”;
fi

else
kdialog –msgbox “cancelled…”
fi

update_map.desktop (place it in e.g. /usr/share/kde4/apps/solid/actions)

[Desktop Entry]
X-KDE-Solid-Predicate=[[ StorageVolume.ignored == false AND StorageVolume.usage == ‘FileSystem’ ] OR [ IS StorageAccess AND StorageDrive.driveType == ‘Floppy’ ]]
Type=Service
Actions=open;

[Desktop Action open]
Name=Update OSM map on Garmin device
Exec=/usr/local/bin/update_map.sh %f
Icon=system-file-manager
X-Ubuntu-Gettext-Domain=desktop_kdebase-workspace

8 Responses to Device notifier script for updating OSM map on Garmin device

  1. Christian says:

    That sounds nice. I think i’ll have to check that for my TomTom.

  2. Sven S. says:

    Tolle Idee!
    Das als .deb Paket für mein Kubuntu, das würde mich (und wahrscheinlnich viele andere) noch glücklicher machen!

    Gruß Sven

  3. Sven S. says:

    I have tried to make this running, but it doesn’t.
    I don’t know what´s the problem.
    I’d followed your Instructions on an Kubuntu 9.10 with an Edge 705.

    • neuntoeter says:

      Did you try to execute the script manually, is it executable?

      e.g. mount the device to /mnt/disk and execute “./update_map.sh /mnt/disk”

      if it doesn’t work – where is the gmapsupp.img located after mounting the device? The script expects it in the Garmin subfolder, but this can of course be changed.

      hope this helps, if not feel free to ask

  4. Sven S. says:

    The map is in the subdirectory Garmin and I typed the command ./update_map.sh /mnt/disk
    in my bash
    The device is also mounted.
    There comes bash: ./update_map.sh: No such file or directory

    • neuntoeter says:

      You should either specify the full path to the script e.g. /usr/local/bin/update_map.sh when executing it or execute it with ./update_map.sh from within the directory where you placed the script.

  5. on3_g says:

    Hi i would like hide a mounted device from the device notifier.

    Is there a way to make that?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: