post_install() {
  if ! getent group dovenull &> /dev/null; then
    groupadd -g 74 dovenull > /dev/null
  fi
  if ! getent group dovecot &> /dev/null; then
    groupadd -g 76 dovecot > /dev/null
  fi
  if ! getent passwd dovenull &> /dev/null; then
    useradd -s /bin/nologin -c "Dovecot user for completely untrustworthy processes" -d /var/empty -u 74 -g dovenull -G adm -r dovenull > /dev/null
  fi
  if ! getent passwd dovecot &> /dev/null; then
    useradd -s /bin/nologin -c "Dovecot user" -d /var/empty -u 76 -g dovecot -G adm -r dovecot > /dev/null
  fi
  if ! groups dovenull | grep adm &>/dev/null; then
    gpasswd -a dovenull adm >/dev/null
  fi
  dovenull_shell=$(getent passwd dovenull | cut -d: -f7)
  if [ "$dovenull_shell" != '/bin/nologin' ]; then
    chsh -s /bin/nologin dovenull &>/dev/null
  fi
  if ! groups dovecot | grep adm &>/dev/null; then
    gpasswd -a dovecot adm >/dev/null
  fi
  dovecot_shell=$(getent passwd dovecot | cut -d: -f7)
  if [ "$dovecot_shell" != '/bin/nologin' ]; then
    chsh -s /bin/nologin dovecot &>/dev/null
  fi
}

post_remove() {
  if getent passwd dovecot &> /dev/null; then
    userdel dovecot >/dev/null
  fi
  if getent group dovecot &> /dev/null; then
    groupdel dovecot >/dev/null
  fi
  if getent group dovenull &> /dev/null; then
    groupdel dovenull >/dev/null
  fi
  rm -rf /var/run/dovecot/ &> /dev/null || /bin/true
}
