wrolpi/scripts/import_map.sh
Roland abb0b49315
Checking for icesheet table as current user.
Importing maps as wrolpi user, then changing ownership to _renderd.

Changing ownership of /opt/wrolpi as well.

Creating pgpass for wrolpi user in debian 11.

Install specific version of serve.

Not echoing the echo.

Updating cache directory in create_db.sh.

Use python binary to run db upgrade.

Install renderd.conf to /etc on RPi OS.

Fetching DC map from wrolpi.org to avoid broken daily PBFs.

Only get latest dc map if it doesn't exist.

carto switched again??

Changing mod_tile directory to /var/cache/renderd/tiles for RPi OS.

Copying renderd configs for RPi OS.

Installing postgres 13 for RPi OS map.

Changing title of feature matrix.

Moving download link up in readme.

Changing mod_tile to _renderd.

Using unix socket rather than host connection.

Getting openstreetmap-carto as _renderd user.

Assigning ownership of gis db to _renderd in reset_map.sh.

Creating _renderd db user.

Using _renderd to run renderd on debian 11.

Installing python modules that map requires globally.

Upgrading db using venv.

Installing nodejs which installs npm.

Install npm/node after other dependencies.

Updating apt so nodejs can be installed.

Upgrading PyYAML in new venv.

Installing pip via apt.

Including bash binary for portability.

Moving images link out of list.

Moving download up on Readme.

Removing map installation from readme.

Installing specific version of carto.

Creating venv for wrolpi project.  Using venv to install requirements and run wrolpi's main.py.

Logging upgrade script.

Including upgrade script in Upgrade readme.

Moving upgrade logic into separate script.  This is necessary so and repo update will take immediate effect on the upgrade.

Modifying and unifying Debian installation with RPi OS installation.
2023-02-24 16:16:13 -07:00

95 lines
3.1 KiB
Bash
Executable file

#!/usr/bin/env bash
MERGED_TMP_FILE=/tmp/wrolpi-merged.osm.pbf
if [ ! -f /opt/openstreetmap-carto/openstreetmap-carto.lua ]; then
echo "openstreetmap-carto.lua file is missing. Has install been completed?"
exit 1
fi
if [ ! -f /opt/openstreetmap-carto/openstreetmap-carto.style ]; then
echo "openstreetmap-carto.style file is missing. Has install been completed?"
exit 2
fi
if [ "${1}" == "" ]; then
echo "Missing file argument."
exit 3
fi
HAS_ICE_SHEET=false
psql gis -c '\d' | grep icesheet_polygons && HAS_ICE_SHEET=true
if [ ${HAS_ICE_SHEET} = false ]; then
echo "WROLPi: Missing icesheet_polygons. Run reset_map.sh"
exit 4
fi
function cleanup() {
if [ -f ${MERGED_TMP_FILE} ]; then
rm ${MERGED_TMP_FILE}
fi
}
trap cleanup EXIT
cleanup
if [[ ${1} == *.osm.pbf ]]; then
# Import PBF files.
for i in "$@"; do
if [[ $i != *.osm.pbf ]]; then
echo "WROLPi: Cannot mix file types"
exit 5
fi
if [ ! -f "${i}" ]; then
echo "WROLPi: File does not exist! ${i}"
exit 6
fi
done
# Use 1/4 of the RAM to import. 1/2 causes crashes on RPi.
RAM_KB=$(grep MemTotal /proc/meminfo | awk '{print $2}')
MAX_CACHE=$((RAM_KB / 1024 / 4))
pbf_path=${1}
pbf_paths=($@)
if [[ ${#pbf_paths[@]} -gt 1 ]]; then
# More than one PBF, merge them before import.
nice -n 18 osmium merge $@ -o ${MERGED_TMP_FILE}
pbf_path=${MERGED_TMP_FILE}
fi
# Import as wrolpi user (the user running this script), then change ownership to _renderd.
nice -n 18 osm2pgsql -d gis --create --slim -G --hstore \
--tag-transform-script /opt/openstreetmap-carto/openstreetmap-carto.lua \
-C ${MAX_CACHE} \
--number-processes 3 \
-S /opt/openstreetmap-carto/openstreetmap-carto.style \
"${pbf_path}"
# Assign all data to _renderd so the map can be rendered.
psql -d gis -c 'ALTER TABLE external_data OWNER TO _renderd'
psql -d gis -c 'ALTER TABLE geography_columns OWNER TO _renderd'
psql -d gis -c 'ALTER TABLE geometry_columns OWNER TO _renderd'
psql -d gis -c "ALTER TABLE icesheet_outlines OWNER TO _renderd"
psql -d gis -c "ALTER TABLE icesheet_polygons OWNER TO _renderd"
psql -d gis -c "ALTER TABLE ne_100m_admin_0_boundary_lines_land OWNER TO _renderd"
psql -d gis -c "ALTER TABLE planet_osm_line OWNER TO _renderd"
psql -d gis -c "ALTER TABLE planet_osm_nodes OWNER TO _renderd"
psql -d gis -c "ALTER TABLE planet_osm_point OWNER TO _renderd"
psql -d gis -c "ALTER TABLE planet_osm_polygon OWNER TO _renderd"
psql -d gis -c "ALTER TABLE planet_osm_rels OWNER TO _renderd"
psql -d gis -c "ALTER TABLE planet_osm_roads OWNER TO _renderd"
psql -d gis -c "ALTER TABLE planet_osm_ways OWNER TO _renderd"
psql -d gis -c "ALTER TABLE simplified_water_polygons OWNER TO _renderd"
psql -d gis -c "ALTER TABLE spatial_ref_sys OWNER TO _renderd"
psql -d gis -c "ALTER TABLE water_polygons OWNER TO _renderd"
elif [[ ${1} == *.dump ]]; then
if [ ! -f "${1}" ]; then
echo "WROLPi: File does not exist! ${1}"
exit 7
fi
# Import a Postgresql dump.
nice -n 18 pg_restore -j3 --no-owner -d gis -U _renderd -h 127.0.0.1 "${1}"
else
echo "WROLPi: Cannot import unknown map file"
exit 8
fi