Install osm base tile in the cache dir.
[marble] / packaging / debian / marble.postinst
index 57f8dc3..d8149b0 100755 (executable)
@@ -25,31 +25,39 @@ fi
 ### Migrate cached openstreetmap tiles to shared directory
 
 # The OSM tile download location in Marble 1.0.x and earlier
-OSM_DIR_10="${HOME}/MyDocs/.local/share/marble/maps/earth/openstreetmap"
+OSM_DIR_10="/home/user/MyDocs/.local/share/marble/maps/earth/openstreetmap"
 
 # The OSM tile download location in Marble 1.1 and later
-OSM_DIR_11="${HOME}/MyDocs/.maps/OpenStreetMap I"
+OSM_DIR_11="/home/user/MyDocs/.maps/OpenStreetMap I"
+
+# The OSM base path
+OSM_DIR_BASE="/opt/marble/share/marble/data/maps/earth/openstreetmap"
 
 # The OSM theme .dgml file
-OSM_DGML="/opt/marble/share/marble/data/maps/earth/openstreetmap/openstreetmap.dgml"
+OSM_DGML="${OSM_DIR_BASE}/openstreetmap.dgml"
 
 # A file used as a flag to indicate a previous migration
 MIGRATED="${OSM_DIR_10}/.migrated"
 
 # Verify we have the .dgml file and can write to it (required)
-test -w "${OSM_DGML}" || { echo "DGML file ${OSM_DGML} missing."; exit 1; }
+test -w "${OSM_DGML}" || { echo "DGML file ${OSM_DGML} not existant/writable."; exit 1; }
 
 # Check whether the tiles were previously migrated. In that case there's nothing to do
 test -e "${MIGRATED}" && exit 0
 
+# If the migration has to move files, ask the user to skip it since it can
+# take some minutes to finish
+
+test -e "${OSM_DIR_10}" && test -e "${OSM_DIR_11}" && { maemo-confirm-text "Enable OpenStreetMap Data Sharing" /opt/marble/share/marble/data/migration-warning.txt || exit 0; }
+
 # Tile migration
+mkdir -p "${OSM_DIR_11}"
 if test -d "${OSM_DIR_10}"
 then
-    mkdir -p "${OSM_DIR_11}"
     # Cached tiles from an old Marble installation exist and must be migrated
     for x in ${OSM_DIR_10}/[0-9]*
     do
-        test -e "${x}" || continue # nullglob would be shorter, but is a bashism
+        test -e "${x}" || continue
         dx="$(basename ${x})"
         if test -e "${OSM_DIR_11}/${dx}"
         then
@@ -61,22 +69,15 @@ then
                 target="${OSM_DIR_11}/${dx}/${dy}/"
                 if test -e "${target}"
                 then
-                    test -e "${z}" || continue
-                    # Tiles /x/y/ were downloaded both in Marble and another application. Check each /x/y/z
-                    for z in ${y}/[0-9]*.png
-                    do
-                        fz="$(basename ${z})"
-                        echo -n "."
-                        # Overwrite the shared tile only if the Marble one is newer
-                        mv -u "${z}" "${target}"
-                        # If the shared tile was not overwritten, delete the Marble one now
-                        test -e "${z}" && rm "${z}"
-                    done
+                    # Tiles /x/y/ were downloaded both in Marble and another application. Move each /x/y/z
+                    mv "${y}"/[0-9]*.png "${target}"
+                    rmdir "${y}" || true
                 else
                     # Target dir does not exist yet, so we can move it over (much quicker)
                     mv "${y}" "${OSM_DIR_11}/${dx}"
                 fi
             done
+            rmdir "${x}" || true
         else
             # Target does not exist yet, so we can move it over (much quicker)
             mv "${x}" "${OSM_DIR_11}/"
@@ -84,8 +85,8 @@ then
     done
 fi
 
-# Delete now empty directories
-test -d "${OSM_DIR_10}/" && find "${OSM_DIR_10}/" -depth -type d -empty -delete
+# Delete now empty directory
+test -d "${OSM_DIR_10}/" && rmdir "${OSM_DIR_10}/" || true
 
 # If files are left in the old directory, leave a flag to avoid running 
 # the migration again. This only happens if the user created custom files in
@@ -95,4 +96,8 @@ test -d "${OSM_DIR_10}/" && touch "${MIGRATED}"
 # Finally, change the download location in the .dgml file. Also needed for new installations
 sed -i "s@<sourcedir format=\"PNG\"> earth/openstreetmap </sourcedir>@<sourcedir format=\"PNG\"> ${OSM_DIR_11} </sourcedir>@" "${OSM_DGML}"
 
+# Copy the base tile to the right place.
+mkdir -p "${OSM_DIR_11}/0/0"
+cp "${OSM_DIR_BASE}/0/0/0.png" "${OSM_DIR_11}/0/0/"
+
 exit 0