#!/bin/sh
# postinst script for gnome-remote-desktop
# inspired by polkitd.postinst
#
# This can be dropped if https://bugs.debian.org/1070473 gets fixed
#
# see: dh_installdeb(1)

set -e

case "$1" in
    configure)
        if ! getent passwd gnome-remote-desktop >/dev/null; then
            user_changed=yes
        else
            user_changed=
        fi

        # Intentionally not using dh_installsysusers: we need enough control
        # over sequencing to reload dbus-daemon after doing this, but before
        # restarting gnome-remote-desktop
        if command -v systemd-sysusers >/dev/null; then
            systemd-sysusers ${DPKG_ROOT:+--root="$DPKG_ROOT"} gnome-remote-desktop-sysusers.conf || true
        fi

        if command -v systemd-tmpfiles >/dev/null; then
            systemd-tmpfiles ${DPKG_ROOT:+--root="$DPKG_ROOT"} --create gnome-remote-desktop-tmpfiles.conf || true
        fi

        # If the gnome-remote-desktop user was newly created,
        # the dbus-daemon might not know about that until reloaded.
        # dbus-broker's service has a dbus.service alias, so this will reload
        # either dbus-daemon or dbus-broker, whichever is used.
        if [ -z "${DPKG_ROOT-}" ] && [ -n "$user_changed" ]; then
            invoke-rc.d dbus reload || true
        fi
    ;;

    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#

exit 0

# vim:set sw=4 sts=4 et:
