post_install() {
  if [ ! -d '/var/lib/postgres' ]; then
    mkdir -p '/var/lib/postgres'
  fi
  if ! getent group postgres >/dev/null; then
    groupadd -g 88 postgres
  fi
  if ! getent passwd postgres >/dev/null; then
    useradd -c 'PostgreSQL user' -u 88 -g postgres -d '/var/lib/postgres' -s /bin/bash postgres
    passwd -l postgres >/dev/null
  fi
  if ! getent group pgbouncer >/dev/null; then
    groupadd -r pgbouncer
  fi
  if ! getent passwd pgbouncer >/dev/null; then
    useradd -c 'PGBouncer user' -r -g pgbouncer -d '/etc/pgbouncer' -s /bin/bash pgbouncer
    passwd -l pgbouncer >/dev/null
  fi
  chown pgbouncer:pgbouncer /var/log/pgbouncer
  systemd-tmpfiles --create pgbouncer.conf
  gpasswd -a pgbouncer postgres
}

post_upgrade() {
  post_install $1
}
