#!/bin/bash

post_install() {
    cat <<- 'EOF'
Create the required PostgreSQL database and user for nominatim by running
`sudo -u postgres createuser --superuser nominatim`
`sudo -u postgres createuser http`

Then `su` to user `nominatim` and follow the instructions at https://nominatim.org/release-docs/latest/admin/Import/#choosing-the-data-to-import to
download and import data. The project directory is /var/lib/nominatim. The configuration can be found in `/etc/nominatim/env.defaults`.

Don't forget to remove superuser permissions from the nominatim PostgreSQL user after installation is complete:
`ALTER ROLE username WITH NOSUPERUSER;`

After the import one should run `nominatim replication --init`, and start an initial catch-up:
`NOMINATIM_REPLICATION_MAX_DIFF=5000 nominatim replication --catch-up --threads 16`
For future periodic updates start and enable the update service:
`systemctl enable --now nominatim-updates.service`

To use the python frontend with gunicorn and Falcon, start and enable the nominatim socket and service:

`systemctl enable --now nominatim.socket nominatim.service`

See `/usr/share/doc/nominatim/examples/nginx-python.conf` for an examplary nginx vhost that uses the python socket.
EOF
}

post_upgrade() {
    if (( $(vercmp "$2" "5.1.0-1") < 0 )); then
        cat <<- 'EOF'
If you used the deprecated PHP backend you need to switch to a python frontend.
EOF

   cat <<- 'EOF'
Run `sudo -u nominatim -H nominatim admin --migrate` to migrate the PostgreSQL database.
EOF

    fi
}
