#!/bin/bash -e #Version: 3.1.0 #For use on clean Ubuntu 22 only!!! #Cited, Inc https://www.citedcorp.com #Usage Example for State of Delaware: #./Nominatim-Server.sh http://download.geofabrik.de/north-america/us/delaware-latest.osm.pbf #NOTE: It is best to run this via the screen command as it takes some time to finish. PBF_URL="${1}"; #get URL from first parameter, http://download.geofabrik.de/europe/germany-latest.osm.pbf PROJECT_NAME='nominatim' NM_USER='ntim'; #nominatim website NM_PG_PASS=$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c32); HNAME=$(hostname -f) PG_VER='14' PGIS_VER='3' function install_postgresql(){ #3. Install PostgreSQL apt-get install -y postgresql-${PG_VER} postgresql-client-${PG_VER} postgresql-contrib-${PG_VER} \ postgresql-server-dev-${PG_VER} postgresql-${PG_VER}-postgis-${PGIS_VER} postgis if [ ! -f /usr/lib/postgresql/${PG_VER}/bin/postgres ]; then echo "Error: Get PostgreSQL version"; exit 1; fi ln -sf /usr/lib/postgresql/${PG_VER}/bin/pg_config /usr/bin ln -sf /var/lib/postgresql/${PG_VER}/main/ /var/lib/postgresql ln -sf /var/lib/postgresql/${PG_VER}/backups /var/lib/postgresql systemctl start postgresql #5. Set postgres Password if [ $(grep -m 1 -c 'pg pass' /root/auth.txt) -eq 0 ]; then PG_PASS=$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c32); sudo -u postgres psql 2>/dev/null -c "alter user postgres with password '${PG_PASS}'" echo "pg pass: ${PG_PASS}" > /root/auth.txt fi #4. Add Postgre variables to environment if [ $(grep -m 1 -c 'PGDATA' /etc/environment) -eq 0 ]; then cat >>/etc/environment </etc/postgresql/${PG_VER}/main/pg_hba.conf <> /root/auth.txt fi } function download_optional_data(){ for f in wikipedia_article wikipedia_redirect gb_postcode_data; do wget --output-document=/home/${NM_USER}/Nominatim/data/${f}.sql.bin http://www.nominatim.org/data/${f}.sql.bin done } function setup_nm_apache(){ cat >/etc/apache2/conf-available/nominatim_dir.conf < Options FollowSymLinks MultiViews AddType text/html .php DirectoryIndex search.php Require all granted Alias /nominatim /var/www/${PROJECT_NAME}/website EOF a2enconf nominatim_dir.conf su ${NM_USER} <.env <&1 | tee /tmp/setup.log EOF rm -f ${PBF_FILE} popd chown -R www-data:www-data /var/www/${PROJECT_NAME} } function enable_nm_updates(){ pushd /home/${NM_USER} nominatim replication --init popd cat >/etc/systemd/system/nominatim-updates.service <"; exit 1; fi touch /root/auth.txt export DEBIAN_FRONTEND=noninteractive apt-get -y update setup_nm_user; install_prerequisites; install_postgresql; install_nominatim; install_nominatim_ui; #download_optional_data; #uncomment if you want optional data. Adds 30Gb to install size import_osm_data; setup_nm_apache; enable_nm_updates; #install_housenumber; #uncomment to install Tiger census data.