post_install() { gtk-update-icon-cache -q -t -f usr/share/icons/hicolor # Add icons to the system icons XDG_ICON_RESOURCE="`which xdg-icon-resource 2> /dev/null || true`" if [ ! -x "$XDG_ICON_RESOURCE" ]; then echo "Error: Could not find xdg-icon-resource" >&2 exit 1 fi for icon in "/opt/slimjet/product_logo_"*.png; do size="${icon##*/product_logo_}" "$XDG_ICON_RESOURCE" install --size "${size%.png}" "$icon" "flashpeak-slimjet" done UPDATE_MENUS="`which update-mime-database usr/share/mime &> /dev/null 2> /dev/null || true`" if [ -x "$UPDATE_MENUS" ]; then update-mime-database usr/share/mime &> /dev/null fi # Update cache of .desktop file MIME types. Non-fatal since it's just a cache. update-desktop-database > /dev/null 2>&1 || true # Updates defaults.list file if present. update_defaults_list() { # $1: name of the .desktop file #local DEFAULTS_FILE="/usr/share/applications/defaults.list" DEFAULTS_FILE="/usr/share/applications/defaults.list" if [ ! -f "${DEFAULTS_FILE}" ]; then return fi # Split key-value pair out of MimeType= line from the .desktop file, # then split semicolon-separated list of mime types (they should not contain # spaces). mime_types="$(grep MimeType= /usr/share/applications/${1} | cut -d '=' -f 2- | tr ';' ' ')" for mime_type in ${mime_types}; do if egrep -q "^${mime_type}=" "${DEFAULTS_FILE}"; then if ! egrep -q "^${mime_type}=.*${1}" "${DEFAULTS_FILE}"; then default_apps="$(grep ${mime_type}= "${DEFAULTS_FILE}" | cut -d '=' -f 2-)" egrep -v "^${mime_type}=" "${DEFAULTS_FILE}" > "${DEFAULTS_FILE}.new" echo "${mime_type}=${default_apps};${1}" >> "${DEFAULTS_FILE}.new" mv "${DEFAULTS_FILE}.new" "${DEFAULTS_FILE}" fi else # If there's no mention of the mime type in the file, add it. echo "${mime_type}=${1};" >> "${DEFAULTS_FILE}" fi done } update_defaults_list "slimjet.desktop" # This function uses sed to insert the contents of one file into another file, # after the first line matching a given regular expression. If there is no # matching line, then the file is unchanged. insert_after_first_match() { # $1: file to update # $2: regular expression # $3: file to insert sed -i -e "1,/$2/ { /$2/ r $3 }" "$1" } # If /usr/share/gnome-control-center/gnome-default-applications.xml exists, it # may need to be updated to add ourselves to the default applications list. If # we find the file and it does not seem to contain our patch already (the patch # is safe to leave even after uninstall), update it. GNOME_DFL_APPS=/usr/share/gnome-control-center/gnome-default-applications.xml if [ -f "$GNOME_DFL_APPS" ]; then # Conditionally insert the contents of the file "default-app-block" after the # first "" line we find in gnome-default-applications.xml fgrep -q "FlashPeak Slimjet" "$GNOME_DFL_APPS" || insert_after_first_match "$GNOME_DFL_APPS" "^[ ]*[ ]*$" "/opt/slimjet/default-app-block" fi update-desktop-database -q echo "You must run Slimjet from a terminal the first time!" } post_upgrade() { post_install } pre_remove() { # Remove icons from the system icons XDG_ICON_RESOURCE="`which xdg-icon-resource 2> /dev/null || true`" if [ ! -x "$XDG_ICON_RESOURCE" ]; then echo "Error: Could not find xdg-icon-resource" >&2 exit 1 fi for icon in "/opt/slimjet/product_logo_"*.png; do size="${icon##*/product_logo_}" "$XDG_ICON_RESOURCE" uninstall --size "${size%.png}" "flashpeak-slimjet" done UPDATE_MENUS="`which update-mime-database usr/share/mime &> /dev/null 2> /dev/null || true`" if [ -x "$UPDATE_MENUS" ]; then update-mime-database usr/share/mime &> /dev/null fi # Update cache of .desktop file MIME types. Non-fatal since it's just a cache. update-desktop-database > /dev/null 2>&1 || true } post_remove() { gtk-update-icon-cache -q -t -f usr/share/icons/hicolor update-desktop-database -q }