NoPaste

thunderbird

von geier22
Beschreibung:
usr/bin/thunderbird
Snippet erstellt:
02.06.2018 10:52:14
Snippet wird automatisch gelöscht:
Niemals

Dein Code:
  1. #!/bin/bash
  2. # vim: autoindent tabstop=4 shiftwidth=4 expandtab softtabstop=4 filetype=sh textwidth=76
  3. #
  4. # File:
  5. #   /usr/bin/thunderbird
  6. #
  7. # Purpose:
  8. #   This is a wrapper script for starting the thunderbird binary with taking
  9. #   care of the searching for an old user Icedove profile folder and adopting
  10. #   the folder into the new place if possible.
  11. #
  12. # Environment:
  13. #   The Icedove binary was using the profile folder '${HOME}/.icedove'. The
  14. #   Mozilla default for the Thunderbird binary is '${HOME}/.thunderbird'.
  15. #   The script will looking for the old profile folder and will symlink the
  16. #   folder '${HOME}/.thunderbird' to the profile folder '${HOME}/.icedove'.
  17. #
  18. # Copyright:
  19. #   Licensed under the terms of GPLv2+.
  20.  
  21. #set -x
  22.  
  23. TB_HELPER=${TB_HELPER:-"/usr/lib/thunderbird/thunderbird-wrapper-helper.sh"}
  24. # sourcing external variables and helper functions
  25. # hide the sourcing for http://www.shellcheck.net/
  26. # shellcheck source=/dev/null
  27. . "${TB_HELPER}"
  28. if [ $? -ne 0 ]; then
  29.     echo "sourcing ${TB_HELPER} failed - giving up."
  30.     exit 1
  31. fi
  32.  
  33. # some global variables
  34. MOZ_APP_NAME=thunderbird
  35. MOZ_APP_LAUNCHER=$(which "$0")
  36. MOZ_LIBDIR=/usr/lib/${MOZ_APP_NAME}
  37. ID_PROFILE_FOLDER=${HOME}/.icedove
  38. TB_PROFILE_FOLDER=${HOME}/.thunderbird
  39.  
  40. export HELP=0
  41. export FAIL=0
  42. export FORCE_MIMEAPPS_MIGRATE=0
  43. export VERBOSE=0
  44.  
  45. # set MOZ_APP_LAUNCHER for gnome-session
  46. export MOZ_APP_LAUNCHER
  47.  
  48. declare -a TB_ARGS=()
  49.  
  50. for ARG in "$@"; do
  51.     case "${ARG}" in
  52.         --fixmime)
  53.             FIXMIME=1
  54.             FORCE_MIMEAPPS_MIGRATE=1
  55.             ;;
  56.         -g)
  57.             DEBUGGER=1
  58.             DEBUG=1
  59.             ;;
  60. #       -d)
  61. #            USER_DEBUGGER=$2
  62. #            DEBUG=1
  63. #            shift
  64. #            ;;
  65.         --help)
  66.             HELP=1
  67.             ;;
  68.         --show-backup)
  69.             SHOW_BACKUP=1
  70.             ;;
  71.         --verbose)
  72.             output_info "[[ ... using verbose mode ... ]]"
  73.             VERBOSE=1
  74.             ;;
  75.         '?')
  76.             usage >&2
  77.             exit 1
  78.             ;;
  79.         # Every other argument is needed to get down to the TB starting call.
  80.         *)
  81.             TB_ARGS+=("${ARG}")
  82.             ;;
  83.     esac
  84.     shift
  85. done
  86.  
  87. # sanity check
  88. if [ "$DEBUGGER" != "" ] && [ "$USER_DEBUGGER" != "" ]; then
  89.     output_info "You can't use option '-g and '-d' at the same time!"
  90.     usage
  91.     exit 1
  92. fi
  93.  
  94. # If '--help' was called show usage() and exit immediately without other
  95. # helpers can be called.
  96. if [ "${HELP}" = "1" ]; then
  97.     usage
  98.     exit 0
  99. fi
  100.  
  101. # The user is forcing to do the MIME fixing (again). If called a used
  102. # profile(s) folder ~/.thunderbird will be also reworked. That's not the
  103. # case if the user is starting this wrapper for a first time and only a
  104. # folder ~/.thunderbird is existing!
  105. if [ "${FIXMIME}" = "1" ]; then
  106.     do_fix_mimetypes_rdf
  107.     do_migrate_old_icedove_desktop
  108.     do_collect_backup_files
  109.     exit 0
  110. fi
  111.  
  112. if [ "${SHOW_BACKUP}" = "1" ]; then
  113.     do_collect_backup_files
  114.     exit 0
  115. fi
  116.  
  117. #############################################################################
  118. #                  User Thunderbird Profile Adoptions                       #
  119. #                                                                           #
  120. # The users Icedove/Thunderbird profile(s) doesn't need to be modified in a #
  121. # different and complicated way. We simply need to ensure that the          #
  122. # Thunderbird binary is finding the existing profiles in the folder         #
  123. # $(HOME)/.thunderbird folder or a valid symlink pointing to the profiles.  #
  124. #                                                                           #
  125. # To "migrate" an old existing Icedove profile we can simply do a symlink   #
  126. # from $(HOME)/.thunderbird --> $(HOME)/.icedove .                          #
  127. #                                                                           #
  128. # Afterwards do some changes to the file mimeTypes.rdf within every         #
  129. # profile. Also we can modify existing *icedove*.desktop entries in the     #
  130. # files.                                                                    #
  131. #                                                                           #
  132. #     $(HOME)/.config/mimeapps.list                                         #
  133. #     $(HOME)/.local/share/applications/mimeapps.list                       #
  134. #                                                                           #
  135. #############################################################################
  136.  
  137. # First try the default case for modification, there is only a folder
  138. # ${ID_PROFILE_FOLDER} and we can symlink to this.
  139. if { [ -d "${ID_PROFILE_FOLDER}" ] || [ -L "${ID_PROFILE_FOLDER}" ]; } && \
  140.    { [ ! -d "${TB_PROFILE_FOLDER}" ] && [ ! -L "${TB_PROFILE_FOLDER}" ]; }; then
  141.     output_debug "found folder '${ID_PROFILE_FOLDER}'"
  142.     output_debug "not found folder or symlink '${TB_PROFILE_FOLDER}'"
  143.     output_debug "Start Thunderbird profile adoptions, please be patient!"
  144.  
  145.     # open a pop-up window with a message about starting migration
  146.     do_inform_migration_start
  147.  
  148.     # do the symlinking
  149.     do_thunderbird2icedove_symlink
  150.  
  151.     # fixing mimeTypes.rdf which may have registered the iceweasel binary
  152.     # as browser, instead of x-www-browser
  153.     do_fix_mimetypes_rdf
  154.  
  155.     # Fix local mimeapp.list and *.desktop entries
  156.     do_migrate_old_icedove_desktop
  157.  
  158.     # we are finished
  159.     output_info "Thunderbird Profile adoptions done."
  160.     do_collect_backup_files
  161. fi
  162.  
  163. # We found both profile folder, and .thunderbird is a symlink,
  164. # we need to check if .thunderbird is symlinked to .icedove
  165. if { [ -d "${ID_PROFILE_FOLDER}" ] && [ -L "${TB_PROFILE_FOLDER}" ]; } && \
  166.    [ "$(readlink -e "${TB_PROFILE_FOLDER}")" = "${ID_PROFILE_FOLDER}" ];then
  167.  
  168.     output_debug "Found folder ${ID_PROFILE_FOLDER}, found a symlink ${TB_PROFILE_FOLDER} pointing to ${ID_PROFILE_FOLDER}"
  169.  
  170.     # Check if we need to do some migration, the linking could be existing
  171.     # before we switched back to Thunderbird.
  172.     if [ ! -f "${TB_PROFILE_FOLDER}/.migrated" ]; then
  173.         # Fixing mimeTypes.rdf which may have registered the iceweasel binary
  174.         # as browser, instead of x-www-browser
  175.         do_fix_mimetypes_rdf
  176.  
  177.         # Fix local mimeapp.list and *.desktop entries
  178.         do_migrate_old_icedove_desktop
  179.     fi
  180.  
  181. # ... or the opposite if .icedove is symlinked to .thunderbird
  182. elif { [ -d "${TB_PROFILE_FOLDER}" ] && [ -L "${ID_PROFILE_FOLDER}" ]; } && \
  183.      [ "$(readlink -e "${ID_PROFILE_FOLDER}")" = "${TB_PROFILE_FOLDER}" ];then
  184.  
  185.     output_debug "Found folder ${TB_PROFILE_FOLDER}, found a symlink ${ID_PROFILE_FOLDER} pointing to ${TB_PROFILE_FOLDER}"
  186.     output_debug "You may want to remove the symlink ${ID_PROFILE_FOLDER}? It's probably not needed anymore."
  187.  
  188.     # Check if we need to do some migration ...
  189.     if [ ! -f "${TB_PROFILE_FOLDER}/.migrated" ]; then
  190.         # Fixing mimeTypes.rdf which may have registered the iceweasel binary
  191.         # as browser, instead of x-www-browser
  192.         do_fix_mimetypes_rdf
  193.  
  194.         # Fix local mimeapps.list and *.desktop entries
  195.         do_migrate_old_icedove_desktop
  196.     fi
  197.  
  198. # We found both profile folder, but they are not linked to each other! This
  199. # is a state we can't solve on our own !!! The user needs to interact and
  200. # has probably an old or otherwise used Thunderbird installation. Which one
  201. # is the correct one to use?
  202. elif { [ -d "${ID_PROFILE_FOLDER}" ] || [ -L "${ID_PROFILE_FOLDER}" ]; } && \
  203.      { [ -d "${TB_PROFILE_FOLDER}" ] || [ -L "${TB_PROFILE_FOLDER}" ]; } && \
  204.        [ "$(readlink -e "${TB_PROFILE_FOLDER}")" != "$(readlink -e "${ID_PROFILE_FOLDER}")" ]; then
  205.  
  206.     for CHECK in ${ID_PROFILE_FOLDER} ${TB_PROFILE_FOLDER}; do
  207.         FILE_CHECK=$(readlink -e "${CHECK}")
  208.         if [ "${FILE_CHECK}" != "" ] && [ -L "${CHECK}" ]; then
  209.             output_debug "Found symlink '${CHECK}' pointing to '${FILE_CHECK}'."
  210.         elif [ "${FILE_CHECK}" != "" ] && [ -d "${CHECK}" ]; then
  211.             output_debug "Found folder '${FILE_CHECK}'."
  212.         else
  213.             output_debug "${CHECK} is probably a symlink pointing to a non existing target, at least not to ${ID_PROFILE_FOLDER}."
  214.             logger -i -p warning -s "$0: [profile migration] ${CHECK} is probably a symlink pointing to a non existing target, at least not to ${ID_PROFILE_FOLDER}."
  215.         fi
  216.     done
  217.  
  218.     output_debug "There are already the folders or symlinks '${TB_PROFILE_FOLDER}' and '${ID_PROFILE_FOLDER}'"
  219.     output_debug "which not pointing to each other, will do nothing as don't know which folder to use."
  220.     output_debug "Please investigate by yourself! Maybe you will find additional information in '/usr/share/doc/thunderbird/README.Debian.gz'."
  221.     logger -i -p warning -s "$0: [profile migration] Couldn't migrate Icedove into Thunderbird profile due existing or symlinked folder '${TB_PROFILE_FOLDER}'!"
  222.  
  223.     # display a graphical advice if possible
  224.     do_thunderbird2icedove_error_out
  225.  
  226. fi
  227.  
  228. if [ "${FAIL}" = 1 ]; then
  229.     output_info "An error happened while trying to migrate the old Icedove profile folder '${ID_PROFILE_FOLDER}'."
  230.     output_info "Please take a look into the syslog file!"
  231.     exit 1
  232. fi
  233.  
  234. # If we are here we going simply further by starting Thunderbird.
  235.  
  236. if [ "${DEBUG}" = "" ]; then
  237.     TB_ARGS_LINE=$(echo "${TB_ARGS[@]}" | sed "s/'/\"/g")
  238.     output_debug "call '${MOZ_LIBDIR}/${MOZ_APP_NAME} ${TB_ARGS_LINE}'"
  239.     exec "${MOZ_LIBDIR}"/"${MOZ_APP_NAME}" "${TB_ARGS[@]}"
  240. else
  241.     # User has selected GDB?
  242.     if [ "${DEBUGGER}" = "1" ]; then
  243.         # checking for GDB
  244.         if [ -f /usr/bin/gdb ]; then
  245.             if dpkg-query -W -f='${Version}' thunderbird-dbg &>/dev/null ; then
  246.                 output_info "Starting Thunderbird with GDB ..."
  247.                 LANG='' exec "${MOZ_LIBDIR}"/run-mozilla.sh -g "${MOZ_LIBDIR}"/"${MOZ_APP_NAME}" "${TB_ARGS[@]}"
  248.             else
  249.                 output_info "No package 'thunderbird-dbg' installed! Please install first and restart."
  250.                 exit 1
  251.             fi
  252.         else
  253.             output_info "No package 'gdb' installed! Please install first and try again."
  254.             exit 1
  255.         fi
  256.     fi
  257. fi
  258.  
  259. exit 0

Quellcode

Hier kannst du den Code kopieren und ihn in deinen bevorzugten Editor einfügen. Alternativ kannst du den gesamten Eintrag auch als Datei herunterladen.