control: tags -1 + patch
control: tags 855265 + patch
control: tags 855391 + patch
control: tags 855286 + patch

Hi,

this patch is for several things from the thread at debian-devel and
some related bugs.  Not sure if you've already been working on this, but
I hope this patch helps.  Just tell me if you want something done
differently, or if I should split this patch into a patch series.

I did some basic testing, but will do some more.  I just feel it's
better to share the current state with you now.


At its core this patch changes copying the profiles to just linking them.

Since this wildly moves around code in the script I tried to put some
more things in separate functions (displaying messages and mimeTypes.rdf
migration) to keep the script clear.  Unfortunately this further bloats
this patch.

I added several checks to test if something needs to be migrated before
the actual migration command, and also moved some debug messages inside
conditional code.

#855265 (thunderbird: migration script should not error out on trivial
migrations)
--> I check for existing links between .thunderbird and .icedove

#855391 (icedove -> thunderbird transition: Original profile removed
when using symlinks)
--> not relevant anymore since the profiles are now linked (assuming we
only need backups for things explicitly changed in this script)

#855501 (thunderbird: copy account during transition from icedove to
thunderbird not a good idea)
--> now we link

#855286 (migration script should use zenity on MATE)
--> this touches the same code as above changes, so I added it to this
patch.  I also dropped the obsolete upper-case handling, see thread in
debian-devel iirc.


Greets
jre

diff --git a/debian/thunderbird-wrapper.sh b/debian/thunderbird-wrapper.sh
index 61c4cc0e79..681bf94cda 100755
--- a/debian/thunderbird-wrapper.sh
+++ b/debian/thunderbird-wrapper.sh
@@ -57,10 +57,7 @@ with underlaying profile(s) from Icedove.
 The Icedove package is now de-branded back to Thunderbird.
 
 The Icedove profile(s) will now be migrated to the Thunderbird folder
-structure. This will take some time!
-
-Please be patient, the Thunderbird program will be started right after
-the migration.
+structure. Thunderbird will be started right after the migration.
 
 If you need more information about the de-branding of the Icedove package
 please take a look into
@@ -87,6 +84,50 @@ if [ "${VERBOSE}" = "1" ]; then
 fi
 }
 
+migration_message() {
+    if [ -x "$(which xmessage)" ]; then
+        migration_message_cmd="xmessage -center"
+    else
+        migration_message_cmd="echo"
+    fi
+    case "${DESKTOP}" in
+        gnome|xfce|mate)
+            if [ -x "$(which zenity)" ]; then
+                migration_message_cmd="zenity --info --no-wrap --title ${TITLE} --text"
+            fi
+            ;;
+
+        kde)
+            if [ -x "$(which kdialog)" ]; then
+                migration_message_cmd="kdialog --title ${TITLE} --msgbox"
+            fi
+            ;;
+    esac
+    $migration_message_cmd "$@"
+}
+
+migrate_MIME_TYPES_RDF_FILE() {
+    # only move on if we not have already a problem
+    if [ "${FAIL}" != 1 ]; then
+        # Fixing mimeTypes.rdf which may have registered the iceweasel binary
+        # as browser, instead of x-www-browser
+        for MIME_TYPES_RDF_FILE in $(find ${TB_PROFILE_FOLDER}/ -name mimeTypes.rdf); do
+            if grep -q /usr/bin/iceweasel ${MIME_TYPES_RDF_FILE}; then
+                debug "Fixing broken 'mimeTypes.rdf'."
+                # Note: changed to create backup copy, and check the result.
+                sed -i.copy_by_thunderbird_starter "s|/usr/bin/iceweasel|/usr/bin/x-www-browser|g" "${MIME_TYPES_RDF_FILE}"
+                if [ $? -ne 0 ]; then
+                    echo "${MIME_TYPES_RDF_FILE} 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 '${MIME_TYPES_RDF_FILE}'!"
+                    exit 1
+                fi
+                debug "${MIME_TYPES_RDF_FILE} has been fixed."
+            fi
+        done
+    fi
+}
+
 migrate_old_icedove_desktop() {
 # Fixing mimeapps.list files in ~/.config/ and ~/.local ... which may have
 # icedove.desktop associations, the latter location is deprecated, but still
@@ -115,9 +156,9 @@ for MIMEAPPS_LIST in ${HOME}/.config/mimeapps.list ${HOME}/.local/share/applicat
             logger -i -p warning -s "$0: [profile migration] Couldn't fix '${MIMEAPPS_LIST}'!"
             exit 1
         fi
+        debug "A copy of the configuration file of default applications for some MIME types"
+        debug "was saved into '${MIMEAPPS_LIST_COPY}'."
     fi
-    debug "A copy of the configuration file of default applications for some MIME types"
-    debug "was saved into '${MIMEAPPS_LIST_COPY}'."
 done
 
 # Migrate old user specific desktop entries
@@ -257,7 +298,7 @@ fi
 
 # trying to get the DE
 if [ "${XDG_CURRENT_DESKTOP}" = "" ]; then
-    DESKTOP=$(echo "${XDG_DATA_DIRS}" | sed 's/.*\(xfce\|kde\|gnome\).*/\1/')
+    DESKTOP=$(echo "${XDG_DATA_DIRS}" | sed 's/.*\(xfce\|kde\|gnome\|mate\).*/\1/')
 else
     DESKTOP=${XDG_CURRENT_DESKTOP}
 fi
@@ -269,88 +310,78 @@ DESKTOP=`echo "$DESKTOP" | tr '[:upper:]' '[:lower:]'`
 # profile migration #
 #####################
 
-# First try the default case for migration, there is only a folder
-# ${ID_PROFILE_FOLDER} and we can migrate this.
-if [ -d "${ID_PROFILE_FOLDER}" -o -L "${ID_PROFILE_FOLDER}" ] && \
-   [ ! -d "${TB_PROFILE_FOLDER}" -a ! -L "${TB_PROFILE_FOLDER}" ]; then
-    debug "found folder '${ID_PROFILE_FOLDER}'"
-    debug "not found folder '${TB_PROFILE_FOLDER}'"
-    debug "Start Thunderbird profile migration, please be patient!"
-
-    # Inform the user we will starting the migration
-    case "${DESKTOP}" in
-        gnome|GNOME|xfce|XFCE)
-            zenity --info --no-wrap --title "${TITLE}" --text "${START_MIGRATION}"
-        ;;
-
-        kde|KDE)
-            kdialog --title "${TITLE}" --msgbox "${START_MIGRATION}"
-        ;;
-
-        *)
-            xmessage -center "${START_MIGRATION}"
-        ;;
-    esac
+# Only do anything migration related if old .icedove exists.
+if [ -e "${ID_PROFILE_FOLDER}" ]; then
+    # First try the default case, migration is already done (TB_PROFILE_FOLDER is a symlink to ID_PROFILE_FOLDER).
+    if [ -d "${ID_PROFILE_FOLDER}" ] && [ -L "${TB_PROFILE_FOLDER}" ] && \
+       [ $(readlink -f ${TB_PROFILE_FOLDER} | sed "s|$HOME/||") = .icedove ]; then
+        debug "found folder '${ID_PROFILE_FOLDER}'"
+        debug "'${TB_PROFILE_FOLDER}' links to it."
+        debug "Migration already done, or some similar custom user setup exists, nothing to do."
+        # TODO: do this everytime (to cover custom user setups), or only during our migration?
+        #migrate_MIME_TYPES_RDF_FILE
+
+    # Default case for migration, there is only a folder ${ID_PROFILE_FOLDER} and we can migrate this.
+    elif [ -d "${ID_PROFILE_FOLDER}" -o -L "${ID_PROFILE_FOLDER}" ] && \
+         [ ! -d "${TB_PROFILE_FOLDER}" -a ! -L "${TB_PROFILE_FOLDER}" ]; then
+        debug "found folder '${ID_PROFILE_FOLDER}'"
+        debug "not found folder '${TB_PROFILE_FOLDER}'"
+        debug "Start Thunderbird profile migration!"
+        migration_message "${START_MIGRATION}"
+        ln -s ${ID_PROFILE_FOLDER} ${TB_PROFILE_FOLDER}
+        if [ "$(echo $?)" != 0  ]; then
+            echo "An error happened while symlinking '${TB_PROFILE_FOLDER}' to '${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 symlink '${TB_PROFILE_FOLDER}' to '${ID_PROFILE_FOLDER}'!"
+            FAIL=1
+        fi
+        migrate_MIME_TYPES_RDF_FILE
+        debug "Migration done."
+        debug "The old Icedove profile folder was linked to '${TB_PROFILE_FOLDER}'"
+
+    # ID_PROFILE_FOLDER links to TB_PROFILE_FOLDER.
+    elif [ -d "${TB_PROFILE_FOLDER}" ] && [ -L "${ID_PROFILE_FOLDER}" ] && \
+         [ $(readlink -f ${ID_PROFILE_FOLDER} | sed "s|$HOME/||") = .thunderbird ]; then
+        debug "found folder '${TB_PROFILE_FOLDER}'"
+        debug "'${ID_PROFILE_FOLDER}' links to it."
+        debug "Custom user setup, nothing to do."
+        # TODO: do this everytime (to cover custom user setups), or only during our migration?
+        #migrate_MIME_TYPES_RDF_FILE
+
+    # 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
+        debug "There is already a folder '${TB_PROFILE_FOLDER}', will do nothing."
+        debug "Please investigate by yourself!"
+        logger -i -p warning -s "$0: [profile migration] Couldn't migrate Icedove into Thunderbird profile due existing folder '${TB_PROFILE_FOLDER}'!"
+
+        # display a graphical advice if possible
+        migration_message "${DOT_THUNDERBIRD_EXISTS}"
+        FAIL=1
 
-    cp -a ${ID_PROFILE_FOLDER} ${TB_PROFILE_FOLDER}
-    if [ "$(echo $?)" != 0  ]; then
-        echo "A error happened 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!"
-        logger -i -p warning -s "$0: [profile migration] Couldn't copy '${ID_PROFILE_FOLDER}' into '${TB_PROFILE_FOLDER}'!"
+    # Catch-all if .icedove exists, but the setup is uncommon.
+    else
+        debug "$HOME/.icedove exists, but something prevents migrating it to the new $HOME/.thunderbird."
+        debug "You have to migrate your profile(s) on your own."
+        logger -i -p warning -s "$0: [profile migration] Couldn't migrate Icedove into Thunderbird profile due unknown reason!"
+        migration_message "Couldn't migrate Icedove into Thunderbird profile. Unknown reason!"
         FAIL=1
     fi
-    mv ${ID_PROFILE_FOLDER} ${HOME}/.icedove_moved_by_thunderbird_starter
 
-    # only move on if we not have already a problem
-    if [ "${FAIL}" != 1 ]; then
-        # Fixing mimeTypes.rdf which may have registered the iceweasel binary
-        # as browser, instead of x-www-browser
-        debug "Fixing possible broken 'mimeTypes.rdf'."
-        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
-        debug "Migration done."
-        debug "The old Icedove profile folder was moved to '${HOME}/.icedove_moved_by_thunderbird_starter'"
+    if [ "$FAIL" = 1 ]; then
+        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
-
-# We found both profile folder, the user has probaly a 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
-    debug "There is already a folder '${TB_PROFILE_FOLDER}', will do nothing."
-    debug "Please investigate by yourself!"
-    logger -i -p warning -s "$0: [profile migration] Couldn't migrate Icedove into Thunderbird profile due existing folder '${TB_PROFILE_FOLDER}'!"
-
-    # display a graphical advice if possible
-    case "${DESKTOP}" in
-        gnome|GNOME|xfce|XFCE)
-            zenity --info --no-wrap --title "${TITLE}" --text "${DOT_THUNDERBIRD_EXISTS}"
-            FAIL=1
-        ;;
-
-        kde|KDE)
-            kdialog --title "${TITLE}" --msgbox "${DOT_THUNDERBIRD_EXISTS}"
-            FAIL=1
-        ;;
-
-        *)
-            xmessage -center "${DOT_THUNDERBIRD_EXISTS}"
-            FAIL=1
-    esac
-fi
-
-if [ "$FAIL" = 1 ]; then
-    echo "A 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
 
 # Fix local mimeapp.list and *.desktop entries
+## TODO: Move this in main if-conditional for migration above?
 migrate_old_icedove_desktop
 
-# There is no old Icedove profile folder (anymore), we have nothing to
-# migrate, going further by starting Thunderbird.
+
+# If necessary the migration has been handled, going further by starting Thunderbird.
 
 if [ "${DEBUG}" = "" ]; then
     debug "call $MOZ_LIBDIR/$MOZ_APP_NAME '${THUNDERBIRD_OPTIONS}'"

Reply via email to