Minor changes needed to run on the N900
[marble] / packaging / debian / marble.postinst
1 #!/bin/sh
2
3 set -e
4
5 if [ "$1" != "configure" ]
6 then
7   exit 0
8 fi
9
10 ### Change old default values to new default values
11
12 CONFIG_FILE="/home/user/.config/kde.org/Marble Desktop Globe.conf"
13 if test -e "${CONFIG_FILE}"
14 then
15   sed -i \
16   -e 's/^sideBar=true$/sideBar=false/' \
17   -e 's/^volatileTileCacheLimit=30$/volatileTileCacheLimit=6/' \
18   -e 's/^projection=0$/projection=2/' \
19   -e '/^distanceUnit=/d' \
20   -e 's/^persistentTileCacheLimit=300$/persistentTileCacheLimit=0/' \
21   "${CONFIG_FILE}"
22   chown user:users "${CONFIG_FILE}"
23 fi
24
25 ### Migrate cached openstreetmap tiles to shared directory
26
27 # The OSM tile download location in Marble 1.0.x and earlier
28 OSM_DIR_10="/home/user/MyDocs/.local/share/marble/maps/earth/openstreetmap"
29
30 # The OSM tile download location in Marble 1.1 and later
31 OSM_DIR_11="/home/user/MyDocs/.maps/OpenStreetMap I"
32
33 # The OSM theme .dgml file
34 OSM_DGML="/opt/marble/share/marble/data/maps/earth/openstreetmap/openstreetmap.dgml"
35
36 # A file used as a flag to indicate a previous migration
37 MIGRATED="${OSM_DIR_10}/.migrated"
38
39 # Verify we have the .dgml file and can write to it (required)
40 test -w "${OSM_DGML}" || { echo "DGML file ${OSM_DGML} not existant/writable."; exit 1; }
41
42 # Check whether the tiles were previously migrated. In that case there's nothing to do
43 test -e "${MIGRATED}" && exit 0
44
45 # If the migration has to move files, ask the user to skip it since it can
46 # take some minutes to finish
47 confirmation="Marble can share OpenStreetMap data with other applications on this device. This helps to save disk space and reduce network traffic.
48
49 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."
50
51 #test -e "${OSM_DIR_10}" && test -e "${OSM_DIR_11}" && { echo "${confirmation}" | maemo-confirm-text "Enable OpenStreetMap Data Sharing" /dev/stdin || exit 0; }
52 #message="$(mktemp marbleXXXXXX)"
53 #echo "${confirmation}" > "${message}"
54 #maemo-confirm-text "Enable OpenStreetMap Data Sharing" "${message}"
55 #rm "${message}"
56
57 # Tile migration
58 mkdir -p "${OSM_DIR_11}"
59 if test -d "${OSM_DIR_10}"
60 then
61     # Cached tiles from an old Marble installation exist and must be migrated
62     for x in ${OSM_DIR_10}/[0-9]*
63     do
64         test -e "${x}" || continue
65         dx="$(basename ${x})"
66         if test -e "${OSM_DIR_11}/${dx}"
67         then
68             # Tiles /x/ were downloaded both in Marble and another application
69             for y in ${x}/[0-9]*
70             do
71                 test -e "${y}" || continue
72                 dy="$(basename ${y})"
73                 target="${OSM_DIR_11}/${dx}/${dy}/"
74                 if test -e "${target}"
75                 then
76                     # Tiles /x/y/ were downloaded both in Marble and another application. Move each /x/y/z
77                     mv "${y}"/[0-9]*.png "${target}"
78                     rmdir "${y}" || true
79                 else
80                     # Target dir does not exist yet, so we can move it over (much quicker)
81                     mv "${y}" "${OSM_DIR_11}/${dx}"
82                 fi
83             done
84             rmdir "${x}" || true
85         else
86             # Target does not exist yet, so we can move it over (much quicker)
87             mv "${x}" "${OSM_DIR_11}/"
88         fi
89     done
90 fi
91
92 # Delete now empty directory
93 test -d "${OSM_DIR_10}/" && rmdir "${OSM_DIR_10}/" || true
94
95 # If files are left in the old directory, leave a flag to avoid running 
96 # the migration again. This only happens if the user created custom files in
97 # the OSM cache directory
98 test -d "${OSM_DIR_10}/" && touch "${MIGRATED}"
99
100 # Finally, change the download location in the .dgml file. Also needed for new installations
101 sed -i "s@<sourcedir format=\"PNG\"> earth/openstreetmap </sourcedir>@<sourcedir format=\"PNG\"> ${OSM_DIR_11} </sourcedir>@" "${OSM_DGML}"
102
103 exit 0