post_install() {
    if [ -z "`grep '^postgrey::' /etc/group`" ]; then
        groupadd -g 314 postgrey >& /dev/null
    fi
    if [ -z "`grep '^postgrey:' /etc/passwd`" ]; then
        useradd -u 314 -d /var/spool/postfix/postgrey -g postgrey -s /bin/false postgrey
    else
        # (postgrey should have no shell, but may have been added by others in the past)
        usermod -s /bin/false postgrey
    fi

    chown postgrey:postgrey /var/spool/postfix/postgrey

    mkdir -p var/run/postgrey
    chown postgrey:postgrey var/run/postgrey
}

post_upgrade() {
    post_install $1
}

pre_remove() {
    userdel postgrey &> /dev/null
    groupdel postgrey &> /dev/null
}
