#!/bin/sh
set -e
if [ "$1" != "configure" ]
then
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 base path
OSM_DIR_BASE="/opt/marble/share/marble/data/maps/earth/openstreetmap"
# The OSM theme .dgml file
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} 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
# 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@ earth/openstreetmap @ ${OSM_DIR_11} @" "${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