#!/bin/sh
# postinst script for mintinstall
#
# see: dh_installdeb(1)

set -e

# summary of how this script can be called:
#        * <postinst> `configure' <most-recently-configured-version>
#        * <old-postinst> `abort-upgrade' <new version>
#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
#          <new-version>
#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
#          <failed-install-package> <version> `removing'
#          <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package
#

case "$1" in
    configure)
    if which update-mime-database > /dev/null 2>&1
    then
        update-mime-database /usr/share/mime
    fi
    if which /usr/bin/update-desktop-database > /dev/null 2>&1
    then
        update-desktop-database
    fi
    if which glib-compile-schemas >/dev/null 2>&1
    then
        glib-compile-schemas /usr/share/glib-2.0/schemas
    fi
    if which flatpak >/dev/null 2>&1
    then
        # flatpak remote-add --if-not-exists gnome https://sdk.gnome.org/gnome.flatpakrepo
        # flatpak remote-add --if-not-exists gnome-apps https://sdk.gnome.org/gnome-apps.flatpakrepo
        flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
        # Create share dirs for flatpak, they're in XDG_DATA_DIRS already but if they don't exist
        # they won't be monitored by some of the DEs and the first apps installed with Flatpak won't
        # show in the menu until the user logs out.
        mkdir -p /var/lib/flatpak/exports/share/applications
        mkdir -p /var/lib/flatpak/exports/share/icons
    fi

    python3 -m compileall /usr/lib/linuxmint/mintinstall
    ;;

    abort-upgrade|abort-remove|abort-deconfigure)

    ;;

    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#



