post_install() {
    if ! getent passwd nullmail > /dev/null; then
        echo "==> Creating nullmail user"
        usr/bin/useradd --comment "nullmailer MTA" --shell /bin/sh --home /var/spool/nullmailer --system --user-group nullmail
    fi

    echo "==> Creating trigger fifo"
    rm -f var/spool/nullmailer/trigger && mkfifo -m 600 var/spool/nullmailer/trigger

    echo "==> Fixing permissions"
    chown nullmail var/spool/nullmailer/*
    chown nullmail usr/bin/nullmailer-queue
    chmod u+s      usr/bin/nullmailer-queue
    chown nullmail usr/bin/mailq
    chmod u+s      usr/bin/mailq
    if ! [ -s etc/nullmailer/me ]; then
        echo "==> Configuring"
        hostnamectl --static > etc/nullmailer/me
    fi
    if ! [ -s etc/nullmailer/remotes ]; then
        echo "smarthost.example.org smtp --port=25 --auth-login --user=user --pass=pass" > etc/nullmailer/remotes
        chgrp nullmail etc/nullmailer/remotes
        chmod 640 etc/nullmailer/remotes
    fi
}

post_upgrade() {
    post_install $1
}

pre_remove() {
    systemctl stop nullmailer
    # Leave the 'queue' directory intact
    rm -rf var/service/nullmailer/{tmp,trigger}
}
