post_install() {
  getent group rethinkdb >/dev/null || groupadd --system rethinkdb &>/dev/null
  getent passwd rethinkdb >/dev/null || useradd --system -g rethinkdb -d /var/lib/rethinkdb -s /bin/false rethinkdb &>/dev/null

  if type -P systemd-tmpfiles &> /dev/null; then
    systemd-tmpfiles --create rethinkdb.conf
  fi

  if [ -d /var/lib/rethinkdb ]; then
    echo "Database directory '/var/lib/rethinkdb' already exists. If you want to recreate default database then delete the directory and run 'rethinkdb create -d /var/lib/rethinkdb/default'."
  fi

  if [ ! -d /var/lib/rethinkdb/default ]; then
    mkdir -p /var/lib/rethinkdb
    /usr/bin/rethinkdb create -d /var/lib/rethinkdb/default
  fi
  chown -R rethinkdb:rethinkdb /var/lib/rethinkdb
}

post_remove() {
  echo "RethinkDB data directory '/var/lib/rethinkdb' is left untouched. Remove it if you really sure you won't need your data in the future."
}
