Home | History | Annotate | Download | only in common
      1 # Add icons to the system icons
      2 XDG_ICON_RESOURCE="`which xdg-icon-resource 2> /dev/null || true`"
      3 if [ ! -x "$XDG_ICON_RESOURCE" ]; then
      4   echo "Error: Could not find xdg-icon-resource" >&2
      5   exit 1
      6 fi
      7 for icon in "@@INSTALLDIR@@/product_logo_"*.png; do
      8   size="${icon##*/product_logo_}"
      9   "$XDG_ICON_RESOURCE" install --size "${size%.png}" "$icon" "@@PACKAGE@@"
     10 done
     11 
     12 UPDATE_MENUS="`which update-menus 2> /dev/null || true`"
     13 if [ -x "$UPDATE_MENUS" ]; then
     14   update-menus
     15 fi
     16 
     17 # Update cache of .desktop file MIME types. Non-fatal since it's just a cache.
     18 update-desktop-database > /dev/null 2>&1 || true
     19 
     20 # Updates defaults.list file if present.
     21 update_defaults_list() {
     22   # $1: name of the .desktop file
     23 
     24   local DEFAULTS_FILE="/usr/share/applications/defaults.list"
     25 
     26   if [ ! -f "${DEFAULTS_FILE}" ]; then
     27     return
     28   fi
     29 
     30   # Split key-value pair out of MimeType= line from the .desktop file,
     31   # then split semicolon-separated list of mime types (they should not contain
     32   # spaces).
     33   mime_types="$(grep MimeType= /usr/share/applications/${1} |
     34                 cut -d '=' -f 2- |
     35                 tr ';' ' ')"
     36   for mime_type in ${mime_types}; do
     37     if egrep -q "^${mime_type}=" "${DEFAULTS_FILE}"; then
     38       if ! egrep -q "^${mime_type}=.*${1}" "${DEFAULTS_FILE}"; then
     39         default_apps="$(grep ${mime_type}= "${DEFAULTS_FILE}" |
     40                         cut -d '=' -f 2-)"
     41         egrep -v "^${mime_type}=" "${DEFAULTS_FILE}" > "${DEFAULTS_FILE}.new"
     42         echo "${mime_type}=${default_apps};${1}" >> "${DEFAULTS_FILE}.new"
     43         mv "${DEFAULTS_FILE}.new" "${DEFAULTS_FILE}"
     44       fi
     45     else
     46       # If there's no mention of the mime type in the file, add it.
     47       echo "${mime_type}=${1};" >> "${DEFAULTS_FILE}"
     48     fi
     49   done
     50 }
     51 
     52 update_defaults_list "@@PACKAGE@@.desktop"
     53 
     54 # This function uses sed to insert the contents of one file into another file,
     55 # after the first line matching a given regular expression. If there is no
     56 # matching line, then the file is unchanged.
     57 insert_after_first_match() {
     58   # $1: file to update
     59   # $2: regular expression
     60   # $3: file to insert
     61   sed -i -e "1,/$2/ {
     62     /$2/ r $3
     63     }" "$1"
     64 }
     65 
     66 # If /usr/share/gnome-control-center/gnome-default-applications.xml exists, it
     67 # may need to be updated to add ourselves to the default applications list. If
     68 # we find the file and it does not seem to contain our patch already (the patch
     69 # is safe to leave even after uninstall), update it.
     70 GNOME_DFL_APPS=/usr/share/gnome-control-center/gnome-default-applications.xml
     71 if [ -f "$GNOME_DFL_APPS" ]; then
     72 # Conditionally insert the contents of the file "default-app-block" after the
     73 # first "<web-browsers>" line we find in gnome-default-applications.xml
     74   fgrep -q "@@MENUNAME@@" "$GNOME_DFL_APPS" || insert_after_first_match \
     75     "$GNOME_DFL_APPS" \
     76     "^[ 	]*<web-browsers>[ 	]*$" \
     77     "@@INSTALLDIR@@/default-app-block"
     78 fi
     79