Minor changes needed to run on the N900
[marble] / packaging / debian / marble.postinst
index 0592ba8..e634624 100755 (executable)
 
 set -e
 
-if [ "$1" = "configure" ]
+if [ "$1" != "configure" ]
 then
-  config="/home/user/.config/kde.org/Marble Desktop Globe.conf"
-  if test -e "${config}"
-  then
-    sed -i \
-    -e 's/^sideBar=true$/sideBar=false/' \
-    -e 's/^volatileTileCacheLimit=30$/volatileTileCacheLimit=6/' \
-    -e 's/^projection=0$/projection=2/' \
-    -e '/^distanceUnit=/d' \
-    "${config}"
-    chown user:users "${config}"
-  fi
+  exit 0
 fi
 
+### Change old default values to new default values
+
+CONFIG_FILE="/home/user/.config/kde.org/Marble Desktop Globe.conf"
+if test -e "${CONFIG_FILE}"
+then
+  sed -i \
+  -e 's/^sideBar=true$/sideBar=false/' \
+  -e 's/^volatileTileCacheLimit=30$/volatileTileCacheLimit=6/' \
+  -e 's/^projection=0$/projection=2/' \
+  -e '/^distanceUnit=/d' \
+  -e 's/^persistentTileCacheLimit=300$/persistentTileCacheLimit=0/' \
+  "${CONFIG_FILE}"
+  chown user:users "${CONFIG_FILE}"
+fi
+
+### Migrate cached openstreetmap tiles to shared directory
+
+# The OSM tile download location in Marble 1.0.x and earlier
+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/user/MyDocs/.maps/OpenStreetMap I"
+
+# The OSM theme .dgml file
+OSM_DGML="/opt/marble/share/marble/data/maps/earth/openstreetmap/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} 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
+confirmation="Marble can share OpenStreetMap data with other applications on this device. This helps to save disk space and reduce network traffic.
+
+Press 'Accept' to enable sharing and migrate already downloaded OpenStreetMap data. This can take several minutes. Alternatively you can skip this step now and data sharing will be disabled. You'll be prompted again to enable it during the next Marble version upgrade."
+
+#test -e "${OSM_DIR_10}" && test -e "${OSM_DIR_11}" && { echo "${confirmation}" | maemo-confirm-text "Enable OpenStreetMap Data Sharing" /dev/stdin || exit 0; }
+#message="$(mktemp marbleXXXXXX)"
+#echo "${confirmation}" > "${message}"
+#maemo-confirm-text "Enable OpenStreetMap Data Sharing" "${message}"
+#rm "${message}"
+
+# Tile migration
+mkdir -p "${OSM_DIR_11}"
+if test -d "${OSM_DIR_10}"
+then
+    # 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
+        dx="$(basename ${x})"
+        if test -e "${OSM_DIR_11}/${dx}"
+        then
+            # Tiles /x/ were downloaded both in Marble and another application
+            for y in ${x}/[0-9]*
+            do
+                test -e "${y}" || continue
+                dy="$(basename ${y})"
+                target="${OSM_DIR_11}/${dx}/${dy}/"
+                if test -e "${target}"
+                then
+                    # 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}/"
+        fi
+    done
+fi
+
+# 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
+# the OSM cache directory
+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}"
+
 exit 0