#!/bin/sh

set -e

case "$1" in
    configure)
        if ! getent passwd mitra > /dev/null; then
            adduser --system --group --home /var/lib/mitra mitra
        fi
        # Update modification time to refresh nginx cache
        touch /usr/share/mitra/www/index.html
    ;;

    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#

# Reload (service file changed in mitra 4.0)
if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then
    if [ -d /run/systemd/system ]; then
        systemctl --system daemon-reload >/dev/null || true
    fi
fi

exit 0
