control: tags -1 + patch

Hi,

I went ahead and made some changes.  I didn't follow my previously
suggested plan, but went for removing the old .desktop files.

Attached are 3 patches.  I successfully tested them with Rick's files
(see my previous comment).
I'll propose something similar for firefox tomorrow, to actually fix
Rick's original problem.


1_mimeapps.list.patch:
----------------------
Also migrate .local/share/applications/mimeapps.list.

Combine this with the existing fix of .config/mimeapps.list in a for loop.

Since some people have migrated already move this fix out of the
conditional migration code, but add a new test if executing this code is
necessary.

Note: mimeapps.list specifies default applications for mime types.


2_remove_desktop_files.patch:
-----------------------------
Backup and remove old icedove .desktop files.

Update mimeinfo.cache for this change.

All icedove .desktop files in $HOME are superseded by the system-wide
/usr/share/applications/thunderbird.desktop (they don't receive updates
and might have missing/outdated fields).

Note: .desktop files and their reverse cache mimeinfo.cache provide
information about available applications.


3_unrelated.patch:
------------------
a missing ";;", and unrelated non-critical fixes


Greets
jre
diff --git a/debian/thunderbird-wrapper.sh b/debian/thunderbird-wrapper.sh
index 91f467e541..d6a7ed4f9a 100755
--- a/debian/thunderbird-wrapper.sh
+++ b/debian/thunderbird-wrapper.sh
@@ -254,25 +254,7 @@ if [ -d "${ID_PROFILE_FOLDER}" -o -L "${ID_PROFILE_FOLDER}" ] && \
         for MIME_TYPES_RDF_FILE in $(find ${TB_PROFILE_FOLDER}/ -name mimeTypes.rdf); do
             sed -i "s|/usr/bin/iceweasel|/usr/bin/x-www-browser|g" "${MIME_TYPES_RDF_FILE}"
         done
-
-        if [ -f ${HOME}/.config/mimeapps.list ]; then
-            # Fixing mimeapps.list which may have icedove.desktop associations
-            debug "Fixing possible broken '~/.config/mimeapps.list'."
-            # first make a copy of the file
-            cp ${HOME}/.config/mimeapps.list ${HOME}/.config/mimeapps.list.copy_by_thunderbird_starter
-            if [ "$(echo $?)" != 0  ]; then
-                echo "The configuration file with for the associated MIME applications"
-                echo "'${HOME}/.config/mimeapps.list' couldn't be saved into a backup file"
-                echo "'${HOME}/.config/mimeapps.list.copy_by_thunderbird_starter'."
-                echo "Please check for potentially problems like low disk space or wrong access rights!"
-                logger -i -p warning -s "$0: [profile migration] Couldn't copy '${HOME}/.config/mimeapps.list' into '${HOME}/.config/mimeapps.list.copy_by_thunderbird_starter'!"
-                FAIL=1
-            else
-                sed -i "s|icedove\.desktop|/thunderbird\.desktop|g" "${HOME}/.config/mimeapps.list"
-            fi
-        fi
         debug "Migration done."
-        debug "A copy of the previous MIME associations was saved into '${HOME}/.config/mimeapps.list.copy_by_thunderbird_starter'."
         debug "The old Icedove profile folder was moved to '${HOME}/.icedove_moved_by_thunderbird_starter'"
     fi
 
@@ -308,6 +290,39 @@ if [ "$FAIL" = 1 ]; then
     exit 1
 fi
 
+# Fixing mimeapps.list files which may have icedove.desktop associations
+# (the latter location is deprecated, but still commonly used)
+# mimeapps.list configures default applications for MIME types
+for MIMEAPPS_LIST in ${HOME}/.config/mimeapps.list ${HOME}/.local/share/applications/mimeapps.list; do
+    # Check if file exists and has old icedove entry
+    if [ -e ${MIMEAPPS_LIST} ] && grep -iq "\(userapp-\)*icedove\(-.*\)*\.desktop" ${MIMEAPPS_LIST}; then
+        debug "Fixing broken '${MIMEAPPS_LIST}'."
+        MIMEAPPS_LIST_COPY=${MIMEAPPS_LIST}.copy_by_thunderbird_starter
+        if [ -e ${MIMEAPPS_LIST_COPY} ]; then
+            echo "The configuration file for default applications for some MIME types"
+            echo "'${MIMEAPPS_LIST}' already has a backup file"
+            echo "'${MIMEAPPS_LIST_COPY}'."
+            echo "Please remove the backup file or fix the configuration file manually!"
+            echo "Please report a bug at https://bugs.debian.org!";
+            logger -i -p warning -s "$0: [profile migration] Backup file '${MIMEAPPS_LIST_COPY}' of '${MIMEAPPS_LIST}' already exists!"
+            exit 1
+        else
+            # Fix mimeapps.list and create backup
+            # (requires GNU sed 3.02 or ssed for case-insensitive "I")
+            sed -i.copy_by_thunderbird_starter "s|\(userapp-\)*icedove\(-.*\)*\.desktop|thunderbird.desktop|gI" ${MIMEAPPS_LIST}
+            if [ "$(echo $?)" != 0  ]; then
+                echo "The configuration file for default applications for some MIME types"
+                echo "'${MIMEAPPS_LIST}' couldn't be fixed."
+                echo "Please check for potential problems like low disk space or wrong access rights!"
+                logger -i -p warning -s "$0: [profile migration] Couldn't fix '${MIMEAPPS_LIST}'!"
+                exit 1
+            fi
+        fi
+        debug "A copy of the configuration file of default applications for some MIME types"
+        debug "was saved into '${MIMEAPPS_LIST_COPY}'."
+    fi
+done
+
 # There is no old Icedove profile folder (anymore), we have nothing to
 # migrate, going further by starting Thunderbird.
 
diff --git a/debian/thunderbird-wrapper.sh b/debian/thunderbird-wrapper.sh
index f045f0146a..bee9e20b46 100755
--- a/debian/thunderbird-wrapper.sh
+++ b/debian/thunderbird-wrapper.sh
@@ -323,6 +323,31 @@ for MIMEAPPS_LIST in ${HOME}/.config/mimeapps.list ${HOME}/.local/share/applicat
     fi
 done
 
+# Remove old icedove.desktop files, superseded by system-wide /usr/share/applications/thunderbird.desktop
+# (the old ones in $HOME don't receive updates and might have missing/outdated fields)
+# .desktop files and their reverse cache mimeinfo.cache provide information about available applications
+for ICEDOVE_DESKTOP in $(find ${HOME}/.local/share/applications/ -iname "*icedove*.desktop"); do
+    ICEDOVE_DESKTOP_COPY=${ICEDOVE_DESKTOP}.copy_by_thunderbird_starter
+    if [ -e ${ICEDOVE_DESKTOP_COPY} ]; then
+        echo "Want to remove the old '${ICEDOVE_DESKTOP}',"
+        echo "but '${ICEDOVE_DESKTOP_COPY}' already exists."
+        echo "Please remove either of these files!"
+        echo "Please report a bug at https://bugs.debian.org!";
+        logger -i -p warning -s "$0: [profile migration] Backup file '${ICEDOVE_DESKTOP_COPY}' of '${ICEDOVE_DESKTOP}' already exists!"
+        exit 1
+    else
+        mv ${ICEDOVE_DESKTOP} ${ICEDOVE_DESKTOP_COPY}
+        # Update the mimeinfo.cache (a reverse cache of the .desktop files, it does not define priorities).
+        # Not existing .desktop files in there should simply be ignored by the system anyway.
+        if [ -x $(which update-desktop-database) ]; then
+            update-desktop-database ~/.local/share/applications/
+        else
+            grep -v "${ICEDOVE_DESKTOP}" ~/.local/share/applications/mimeinfo.cache > ~/.local/share/applications/mimeinfo.cache.by_thunderbird_starter
+            mv ~/.local/share/applications/mimeinfo.cache.by_thunderbird_starter ~/.local/share/applications/mimeinfo.cache
+        fi
+    fi
+done
+
 # There is no old Icedove profile folder (anymore), we have nothing to
 # migrate, going further by starting Thunderbird.
 
diff --git a/debian/thunderbird-wrapper.sh b/debian/thunderbird-wrapper.sh
index bee9e20b46..da8f49f47c 100755
--- a/debian/thunderbird-wrapper.sh
+++ b/debian/thunderbird-wrapper.sh
@@ -237,10 +237,10 @@ if [ -d "${ID_PROFILE_FOLDER}" -o -L "${ID_PROFILE_FOLDER}" ] && \
     esac
 
     cp -a ${ID_PROFILE_FOLDER} ${TB_PROFILE_FOLDER}
-    if [ "$(echo $?)" != 0  ]; then
-        echo "A error happen while copying the Icedove profile folder into '${TB_PROFILE_FOLDER}'"
-        echo "The old unchanged profile(s) will still be found in '${ID_PROFILE_FOLDER}'."
-        echo "Please check for potentially problems like low disk space or wrong access rights!"
+    if [ "$?" != 0  ]; then
+        echo "An error happened while copying the Icedove profile folder into '${TB_PROFILE_FOLDER}'"
+        echo "The old unchanged profile(s) can still be found in '${ID_PROFILE_FOLDER}'."
+        echo "Please check for potential problems like low disk space or wrong access rights!"
         logger -i -p warning -s "$0: [profile migration] Couldn't copy '${ID_PROFILE_FOLDER}' into '${TB_PROFILE_FOLDER}'!"
         FAIL=1
     fi
@@ -255,10 +255,10 @@ if [ -d "${ID_PROFILE_FOLDER}" -o -L "${ID_PROFILE_FOLDER}" ] && \
             sed -i "s|/usr/bin/iceweasel|/usr/bin/x-www-browser|g" "${MIME_TYPES_RDF_FILE}"
         done
         debug "Migration done."
-        debug "The old Icedove profile folder was moved to '${HOME}/.icedove_moved_by_thunderbird_starter'"
+        debug "The old Icedove profile folder was moved to '${HOME}/.icedove_moved_by_thunderbird_starter'."
     fi
 
-# We found both profile folder, the user has probaly a old or otherwise used
+# We found both profile folders, the user has probably an old or otherwise used
 # Thunderbird installation.
 elif [ -d "${ID_PROFILE_FOLDER}" -o -L "${ID_PROFILE_FOLDER}" ] && \
      [ -d "${TB_PROFILE_FOLDER}" -o -L "${TB_PROFILE_FOLDER}" ]; then
@@ -281,11 +281,12 @@ elif [ -d "${ID_PROFILE_FOLDER}" -o -L "${ID_PROFILE_FOLDER}" ] && \
         *)
             xmessage -center "${DOT_THUNDERBIRD_EXISTS}"
             FAIL=1
+        ;;
     esac
 fi
 
 if [ "$FAIL" = 1 ]; then
-    echo "A error happen while trying to migrate the old Icedove profile folder '${ID_PROFILE_FOLDER}'."
+    echo "An error happened while trying to migrate the old Icedove profile folder '${ID_PROFILE_FOLDER}'."
     echo "Please take a look into the syslog file!"
     exit 1
 fi
@@ -350,7 +351,6 @@ done
 
 # There is no old Icedove profile folder (anymore), we have nothing to
 # migrate, going further by starting Thunderbird.
-
 if [ "${DEBUG}" = "" ]; then
     debug "call $MOZ_LIBDIR/$MOZ_APP_NAME '${THUNDERBIRD_OPTIONS}'"
     $MOZ_LIBDIR/$MOZ_APP_NAME "${THUNDERBIRD_OPTIONS}"

Reply via email to