post_install() {
  if [ -z "$(getent group nrpe)" ]; then
    groupadd -g 31 nrpe
  fi
  if [ -z "$(getent passwd nrpe)" ]; then
    useradd -u 31 -g nrpe -c "NRPE" -d /dev/null -s /usr/bin/nologin nrpe
  fi

  grep -Pq '^nrpe\s+' /etc/services || \
    echo "nrpe             5666/tcp" >> /etc/services

  systemd-tmpfiles --create /usr/lib/tmpfiles.d/nrpe.conf
}

post_upgrade() {
  post_install $1
}

post_remove() {
  # remove the line added to /etc/services
  sed -e '/nrpe             5666\/tcp/d' \
      -i /etc/services || true
}
