#!/bin/sh
# postinst script for email-oauth2-proxy.

set -e


case "$1" in
    configure)
        # Make sure the system user/group exist
        if ! getent passwd email-oauth2-proxy >/dev/null; then
            adduser \
                --disabled-password \
                --quiet \
                --system \
                --home /var/lib/email-oauth2-proxy \
                --gecos "Email OAuth2 Proxy user" \
                --group \
                email-oauth2-proxy
        fi

        # Create a basic default config file if none already present
        if ! test -f /etc/email-oauth2-proxy.conf; then
            cp /usr/share/doc/email-oauth2-proxy/examples/minimal.conf /etc/email-oauth2-proxy.conf
            echo "A default config file /etc/email-oauth2-proxy.conf has been created. Please edit to your needs and restart service as needed."
        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
