mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-10-26 02:48:38 -04:00
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.
This commit is contained in:
parent
57ffe5f5c9
commit
abb0b49315
33 changed files with 529 additions and 285 deletions
21
scripts/build_api_and_app.sh
Executable file
21
scripts/build_api_and_app.sh
Executable file
|
|
@ -0,0 +1,21 @@
|
|||
#! /usr/bin/env bash
|
||||
# This script will rebuild and install dependencies of the API and App.
|
||||
|
||||
set -x
|
||||
set -e
|
||||
|
||||
# Install any App dependencies.
|
||||
cd /opt/wrolpi/app || exit 1
|
||||
npm install || npm install || npm install || npm install # try install multiple times :(
|
||||
# Build app in the background.
|
||||
npm run build &
|
||||
|
||||
# Install python requirements in background job.
|
||||
/opt/wrolpi/venv/bin/pip3 install -r /opt/wrolpi/requirements.txt &
|
||||
|
||||
wait $(jobs -p)
|
||||
|
||||
# Upgrade the WROLPi database.
|
||||
(cd /opt/wrolpi && /opt/wrolpi/venv/bin/python3 /opt/wrolpi/main.py db upgrade)
|
||||
|
||||
systemctl start wrolpi.target
|
||||
|
|
@ -2,13 +2,13 @@
|
|||
|
||||
# Create WROLPi API database.
|
||||
sudo -u postgres psql -c '\l' | grep wrolpi || (
|
||||
sudo -u postgres createuser wrolpi
|
||||
sudo -u postgres createuser -s wrolpi # superuser so maps can be imported
|
||||
sudo -u postgres psql -c "alter user postgres password 'wrolpi'"
|
||||
sudo -u postgres psql -c "alter user wrolpi password 'wrolpi'"
|
||||
sudo -u postgres createdb -E UTF8 -O wrolpi wrolpi
|
||||
echo "Created wrolpi database"
|
||||
)
|
||||
sudo -u wrolpi /bin/bash -c 'cd /opt/wrolpi && ./main.py db upgrade'
|
||||
sudo -u wrolpi /bin/bash -c 'cd /opt/wrolpi && /opt/wrolpi/venv/bin/python3 main.py db upgrade'
|
||||
|
||||
# Create gis (map) database.
|
||||
sudo -u postgres psql -c '\l' | grep gis || (
|
||||
|
|
@ -25,4 +25,4 @@ sudo -u postgres psql -d gis -c 'ALTER TABLE geography_columns OWNER TO _renderd
|
|||
sudo -u postgres psql -d gis -c 'ALTER TABLE geometry_columns OWNER TO _renderd'
|
||||
sudo -u postgres psql -d gis -c "ALTER TABLE spatial_ref_sys OWNER TO _renderd"
|
||||
# Clear map tile cache files.
|
||||
[ -d /var/lib/mod_tile/ajt ] && sudo rm -r /var/lib/mod_tile/ajt
|
||||
[ -d /var/cache/renderd/tiles/ajt ] && sudo rm -r /var/cache/renderd/tiles/ajt
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ if [ "${1}" == "" ]; then
|
|||
fi
|
||||
|
||||
HAS_ICE_SHEET=false
|
||||
psql gis wrolpi -c '\d' | grep icesheet_polygons && HAS_ICE_SHEET=true
|
||||
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
|
||||
|
|
@ -58,12 +58,30 @@ if [[ ${1} == *.osm.pbf ]]; then
|
|||
pbf_path=${MERGED_TMP_FILE}
|
||||
fi
|
||||
|
||||
nice -n 18 osm2pgsql -d gis --create --slim -G --hstore -U _renderd -H 127.0.0.1 \
|
||||
# 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}"
|
||||
|
|
|
|||
|
|
@ -8,9 +8,9 @@ fi
|
|||
set -x
|
||||
|
||||
# Use D.C. to initialized DB because it is so small.
|
||||
DC_MAP=district-of-columbia-latest.osm.pbf
|
||||
DC_MAP=district-of-columbia-230222.osm.pbf
|
||||
DC_MAP_PATH=/tmp/${DC_MAP}
|
||||
wget --continue https://download.geofabrik.de/north-america/us/${DC_MAP} -O ${DC_MAP_PATH} || :
|
||||
[ -f "${DC_MAP_PATH}" ] || wget --continue https://wrolpi.org/downloads/${DC_MAP} -O ${DC_MAP_PATH}
|
||||
|
||||
if [ ! -f "${DC_MAP_PATH}" ]; then
|
||||
echo "Could not download D.C. map"
|
||||
|
|
@ -28,15 +28,15 @@ dc_import=false
|
|||
indexes=false
|
||||
while [ "${COUNT}" -lt "${MAX_TRIES}" ]; do
|
||||
[[ "${external_data}" = false ]] &&
|
||||
sudo -u wrolpi nice -n 18 /opt/openstreetmap-carto/scripts/get-external-data.py \
|
||||
sudo -u _renderd nice -n 18 /opt/openstreetmap-carto/scripts/get-external-data.py \
|
||||
-C \
|
||||
-d gis -U wrolpi &&
|
||||
-d gis -U _renderd &&
|
||||
external_data=true
|
||||
[[ "${dc_import}" = false ]] &&
|
||||
sudo -u wrolpi nice -n 18 /opt/wrolpi/scripts/import_map.sh ${DC_MAP_PATH} &&
|
||||
sudo -u _renderd nice -n 18 /opt/wrolpi/scripts/import_map.sh ${DC_MAP_PATH} &&
|
||||
dc_import=true
|
||||
[[ "${indexes}" = false ]] &&
|
||||
sudo -u wrolpi psql -d gis -f /opt/openstreetmap-carto/indexes.sql &&
|
||||
sudo -u _renderd psql -d gis -f /opt/openstreetmap-carto/indexes.sql &&
|
||||
indexes=true
|
||||
if [[ "${external_data}" == true && "${dc_import}" == true && "${indexes}" == true ]]; then
|
||||
SUCCESS=true
|
||||
|
|
|
|||
|
|
@ -4,28 +4,42 @@ echo "Debian 11 install start: $(date '+%Y-%m-%d %H:%M:%S')"
|
|||
set -x
|
||||
set -e
|
||||
|
||||
# Install npm repos.
|
||||
npm --version || curl -fsSL https://deb.nodesource.com/setup_18.x | bash -
|
||||
|
||||
# Update if we haven't updated in the last day.
|
||||
[ -z "$(find -H /var/lib/apt/lists -maxdepth 0 -mtime -1)" ] && apt update
|
||||
# Install dependencies
|
||||
apt install -y apt-transport-https ca-certificates curl gnupg-agent gcc libpq-dev software-properties-common \
|
||||
postgresql-13 nginx-full nginx-doc python3-full python3-dev python3-doc python3-venv htop vim ffmpeg hostapd \
|
||||
chromium chromium-driver cpufrequtils network-manager nodejs
|
||||
apt install -y \
|
||||
apt-transport-https \
|
||||
ca-certificates \
|
||||
chromium \
|
||||
chromium-driver \
|
||||
cpufrequtils \
|
||||
curl \
|
||||
ffmpeg \
|
||||
gcc \
|
||||
gnupg-agent \
|
||||
hostapd \
|
||||
htop \
|
||||
libpq-dev \
|
||||
network-manager \
|
||||
nginx-doc \
|
||||
nginx-full \
|
||||
postgresql-13 \
|
||||
python3-dev \
|
||||
python3-doc \
|
||||
python3-full \
|
||||
python3-pip \
|
||||
python3-venv \
|
||||
software-properties-common \
|
||||
vim
|
||||
|
||||
# Install npm.
|
||||
npm --version || curl -fsSL https://deb.nodesource.com/setup_18.x | bash -
|
||||
apt install -y nodejs
|
||||
node -v
|
||||
npm -v
|
||||
|
||||
# Install serve, and archiving tools.
|
||||
sudo npm i -g serve single-file-cli@1.0.33 'git+https://github.com/lrnselfreliance/readability-extractor' &
|
||||
|
||||
# Setup the virtual environment that main.py expects
|
||||
pip3 --version || (
|
||||
# If no pip, install pip
|
||||
curl https://bootstrap.pypa.io/get-pip.py -o /tmp/get-pip.py &&
|
||||
python3 /tmp/get-pip.py &
|
||||
)
|
||||
|
||||
# Wait for npm and pip3.
|
||||
wait $(jobs -p)
|
||||
sudo npm i -g serve@12.0.1 single-file-cli@1.0.33 readability-extractor@0.0.6
|
||||
|
||||
# Build React app in background job.
|
||||
cd /opt/wrolpi/app || exit 5
|
||||
|
|
@ -33,7 +47,8 @@ npm install || npm install || npm install || npm install # try install multiple
|
|||
npm run build &
|
||||
|
||||
# Install python requirements in background job.
|
||||
pip3 install -r /opt/wrolpi/requirements.txt &
|
||||
python3 -m venv /opt/wrolpi/venv
|
||||
/opt/wrolpi/venv/bin/pip3 install -r /opt/wrolpi/requirements.txt &
|
||||
|
||||
wait $(jobs -p)
|
||||
|
||||
|
|
@ -44,7 +59,12 @@ cp /opt/wrolpi/50x.html /var/www/50x.html
|
|||
|
||||
# Create the WROLPi user
|
||||
grep wrolpi /etc/passwd || useradd -md /home/wrolpi wrolpi -s "$(command -v bash)"
|
||||
chown -R wrolpi:wrolpi /opt/wrolpi
|
||||
cat >/home/wrolpi/.pgpass <<'EOF'
|
||||
127.0.0.1:5432:gis:_renderd:wrolpi
|
||||
127.0.0.1:5432:wrolpi:wrolpi:wrolpi
|
||||
EOF
|
||||
chown -R wrolpi:wrolpi /home/wrolpi /opt/wrolpi
|
||||
chmod 0600 /home/wrolpi/.pgpass
|
||||
|
||||
# Give WROLPi group a few privileged commands via sudo without password.
|
||||
cat >/etc/sudoers.d/90-wrolpi <<'EOF'
|
||||
|
|
@ -62,9 +82,9 @@ visudo -c -f /etc/sudoers.d/90-wrolpi
|
|||
chown wrolpi:wrolpi /media/wrolpi
|
||||
|
||||
# Install the systemd services
|
||||
cp /opt/wrolpi/etc/ubuntu20.04/wrolpi-api.service /etc/systemd/system/
|
||||
cp /opt/wrolpi/etc/raspberrypios/wrolpi-api.service /etc/systemd/system/
|
||||
cp /opt/wrolpi/etc/debian11/wrolpi-app.service /etc/systemd/system/
|
||||
cp /opt/wrolpi/etc/ubuntu20.04/wrolpi.target /etc/systemd/system/
|
||||
cp /opt/wrolpi/etc/raspberrypios/wrolpi.target /etc/systemd/system/
|
||||
/usr/bin/systemctl daemon-reload
|
||||
systemctl enable wrolpi-api.service
|
||||
systemctl enable wrolpi-app.service
|
||||
|
|
@ -74,13 +94,16 @@ systemctl stop wrolpi-app.service
|
|||
|
||||
# Configure Postgresql. Do this after the API is stopped.
|
||||
sudo -u postgres psql -c '\l' | grep wrolpi || (
|
||||
sudo -u postgres createuser wrolpi &&
|
||||
sudo -u postgres createuser -s wrolpi &&
|
||||
sudo -u postgres psql -c "alter user postgres password 'wrolpi'" &&
|
||||
sudo -u postgres psql -c "alter user wrolpi password 'wrolpi'" &&
|
||||
sudo -u postgres createdb -E UTF8 -O wrolpi wrolpi
|
||||
)
|
||||
# Initialize/upgrade the WROLPi database.
|
||||
(cd /opt/wrolpi && /usr/bin/python3 /opt/wrolpi/main.py db upgrade)
|
||||
(cd /opt/wrolpi && /opt/wrolpi/venv/bin/python3 /opt/wrolpi/main.py db upgrade)
|
||||
|
||||
# Install map only if that script hasn't finished.
|
||||
[ -f /var/www/html/leaflet.css ] || /opt/wrolpi/scripts/install_map_debian_11.sh
|
||||
|
||||
set +x
|
||||
|
||||
|
|
|
|||
|
|
@ -9,48 +9,52 @@ set -e
|
|||
[ -z "$(find -H /var/lib/apt/lists -maxdepth 0 -mtime -1)" ] && apt update
|
||||
# Install map dependencies.
|
||||
apt install -y libapache2-mod-tile renderd tar unzip wget bzip2 apache2 lua5.1 mapnik-utils python3-mapnik gdal-bin \
|
||||
fonts-noto-cjk fonts-noto-hinted fonts-noto-unhinted ttf-unifont osmium-tool
|
||||
fonts-noto-cjk fonts-noto-hinted fonts-noto-unhinted ttf-unifont osmium-tool python3-psycopg2 python3-yaml
|
||||
|
||||
/usr/bin/npm install -g carto
|
||||
/usr/bin/carto -v
|
||||
/usr/bin/npm install -g carto@1.2.0
|
||||
carto -v
|
||||
|
||||
# Create `gis` database for map.
|
||||
sudo -u postgres psql -c '\l' | grep gis || sudo -u postgres createdb -E UTF8 -O wrolpi gis
|
||||
sudo -u postgres psql -d gis -c "CREATE EXTENSION postgis;" || :
|
||||
sudo -u postgres psql -d gis -c "CREATE EXTENSION hstore;" || :
|
||||
sudo -u postgres psql -d gis -c "ALTER TABLE geometry_columns OWNER TO wrolpi;"
|
||||
sudo -u postgres psql -d gis -c "ALTER TABLE spatial_ref_sys OWNER TO wrolpi;"
|
||||
sudo -u postgres psql -c '\l' | grep gis || (
|
||||
sudo -u postgres createuser _renderd || :
|
||||
sudo -u postgres psql -c "alter user _renderd password 'wrolpi'" || :
|
||||
sudo -u postgres createdb -E UTF8 -O _renderd gis
|
||||
sudo -u postgres psql -d gis -c "CREATE EXTENSION postgis" || :
|
||||
sudo -u postgres psql -d gis -c "CREATE EXTENSION hstore" || :
|
||||
echo "Created gis database"
|
||||
)
|
||||
sudo -u postgres psql -d gis -c 'ALTER TABLE geography_columns OWNER TO _renderd'
|
||||
sudo -u postgres psql -d gis -c 'ALTER TABLE geometry_columns OWNER TO _renderd'
|
||||
sudo -u postgres psql -d gis -c "ALTER TABLE spatial_ref_sys OWNER TO _renderd"
|
||||
|
||||
# Install Debian 11 compatible mod_tile.
|
||||
git clone -b switch2osm https://github.com/lrnselfreliance/mod_tile.git /tmp/mod_tile || :
|
||||
# Install init/systemd config to start map service on startup.
|
||||
cp /tmp/mod_tile/debian/renderd.init /etc/init.d/renderd
|
||||
cp /opt/wrolpi/etc/raspberrypios/renderd /etc/init.d/renderd
|
||||
sudo chmod +x /etc/init.d/renderd
|
||||
sed -i -e 's/^RUNASUSER.*/RUNASUSER=wrolpi/' /etc/init.d/renderd
|
||||
sed -i -e 's/^DAEMON=.*/DAEMON=\/usr\/bin\/$NAME/' /etc/init.d/renderd
|
||||
sed -i -e 's/^DAEMON_ARGS=.*/DAEMON_ARGS="-c \/etc\/renderd.conf"/' /etc/init.d/renderd
|
||||
cp /tmp/mod_tile/debian/renderd.service /lib/systemd/system/
|
||||
chmod +x /etc/init.d/renderd
|
||||
|
||||
# Initialize gis database.
|
||||
[ -d /opt/openstreetmap-carto ] && chown -R wrolpi:wrolpi /opt/openstreetmap-carto
|
||||
git clone https://github.com/lrnselfreliance/openstreetmap-carto.git /opt/openstreetmap-carto || :
|
||||
chown -R wrolpi:wrolpi /opt/openstreetmap-carto
|
||||
sudo -u wrolpi /bin/bash -c '(cd /opt/openstreetmap-carto && git fetch && git checkout master && git reset --hard origin/master && git pull --ff)'
|
||||
chown -R _renderd:_renderd /opt/openstreetmap-carto
|
||||
sudo -u _renderd /bin/bash -c '(cd /opt/openstreetmap-carto && git fetch && git checkout master && git reset --hard origin/master && git pull --ff)'
|
||||
cd /opt/openstreetmap-carto
|
||||
if [[ ! -f /opt/openstreetmap-carto/mapnik.xml || ! -s /opt/openstreetmap-carto/mapnik.xml ]]; then
|
||||
/usr/bin/carto project.mml >/opt/openstreetmap-carto/mapnik.xml
|
||||
carto project.mml >/opt/openstreetmap-carto/mapnik.xml
|
||||
fi
|
||||
chown -R _renderd:_renderd /opt/openstreetmap-carto
|
||||
|
||||
# Reset map. Force it.
|
||||
/opt/wrolpi/scripts/reset_map.sh -f
|
||||
|
||||
cp /opt/wrolpi/etc/debian11/renderd.conf /etc/renderd.conf
|
||||
cp /opt/wrolpi/etc/raspberrypios/renderd.conf /etc/renderd.conf
|
||||
# Configure Apache2 to listen on 8084.
|
||||
cp /opt/wrolpi/etc/debian11/ports.conf /etc/apache2/ports.conf
|
||||
cp /opt/wrolpi/etc/raspberrypios/ports.conf /etc/apache2/ports.conf
|
||||
cp /opt/wrolpi/etc/debian11/000-default.conf /etc/apache2/sites-available/000-default.conf
|
||||
# Copy Leaflet files to Apache's directory so they can be used offline.
|
||||
cp /opt/wrolpi/etc/debian11/index.html \
|
||||
cp /opt/wrolpi/etc/raspberrypios/index.html \
|
||||
/opt/wrolpi/modules/map/leaflet.js \
|
||||
/opt/wrolpi/modules/map/leaflet.css /var/www/html/
|
||||
chmod 644 /var/www/html/*
|
||||
|
|
|
|||
76
scripts/install_map_raspberrypios.sh
Executable file
76
scripts/install_map_raspberrypios.sh
Executable file
|
|
@ -0,0 +1,76 @@
|
|||
#! /usr/bin/env bash
|
||||
# This script installs OpenStreetMap tile server.
|
||||
# This server uses Apache2, renderd, and mod_tile to render and display map tiles.
|
||||
|
||||
set -x
|
||||
set -e
|
||||
|
||||
# Update if we haven't updated in the last day.
|
||||
[ -z "$(find -H /var/lib/apt/lists -maxdepth 0 -mtime -1)" ] && apt update
|
||||
# Install map dependencies.
|
||||
apt install -y libapache2-mod-tile libboost-all-dev git tar unzip wget bzip2 build-essential autoconf libtool libxml2-dev libgeos-dev \
|
||||
libgeos++-dev libpq-dev libbz2-dev libproj-dev protobuf-c-compiler libfreetype6-dev libtiff5-dev \
|
||||
libicu-dev libgdal-dev libcairo2-dev libcairomm-1.0-dev libagg-dev liblua5.2-dev ttf-unifont lua5.1 liblua5.1-0-dev \
|
||||
postgis postgresql-13-postgis-3 postgresql-13-postgis-3-scripts osm2pgsql gdal-bin libmapnik-dev mapnik-utils \
|
||||
python3-mapnik apache2 apache2-dev libcurl4-gnutls-dev libiniparser-dev libmemcached-dev librados-dev \
|
||||
fonts-noto-cjk fonts-noto-hinted fonts-noto-unhinted postgresql-contrib osmium-tool python3-psycopg2 python3-yaml
|
||||
|
||||
/usr/bin/npm install -g carto@1.2.0
|
||||
carto -v
|
||||
|
||||
# Create `gis` database for map.
|
||||
sudo -u postgres psql -c '\l' | grep gis || (
|
||||
sudo -u postgres createuser _renderd || :
|
||||
sudo -u postgres psql -c "alter user _renderd password 'wrolpi'" || :
|
||||
sudo -u postgres createdb -E UTF8 -O _renderd gis
|
||||
sudo -u postgres psql -d gis -c "CREATE EXTENSION postgis" || :
|
||||
sudo -u postgres psql -d gis -c "CREATE EXTENSION hstore" || :
|
||||
echo "Created gis database"
|
||||
)
|
||||
sudo -u postgres psql -d gis -c 'ALTER TABLE geography_columns OWNER TO _renderd'
|
||||
sudo -u postgres psql -d gis -c 'ALTER TABLE geometry_columns OWNER TO _renderd'
|
||||
sudo -u postgres psql -d gis -c "ALTER TABLE spatial_ref_sys OWNER TO _renderd"
|
||||
|
||||
# Install Raspberry Pi OS compatible mod_tile.
|
||||
git clone -b switch2osm https://github.com/lrnselfreliance/mod_tile.git /tmp/mod_tile || :
|
||||
# Install init/systemd config to start map service on startup.
|
||||
cp /opt/wrolpi/etc/raspberrypios/renderd /etc/init.d/renderd
|
||||
sudo chmod +x /etc/init.d/renderd
|
||||
cp /tmp/mod_tile/debian/renderd.service /lib/systemd/system/
|
||||
chmod +x /etc/init.d/renderd
|
||||
|
||||
# Initialize gis database.
|
||||
[ -d /opt/openstreetmap-carto ] && chown -R wrolpi:wrolpi /opt/openstreetmap-carto
|
||||
git clone https://github.com/lrnselfreliance/openstreetmap-carto.git /opt/openstreetmap-carto || :
|
||||
chown -R _renderd:_renderd /opt/openstreetmap-carto
|
||||
sudo -u _renderd /bin/bash -c '(cd /opt/openstreetmap-carto && git fetch && git checkout master && git reset --hard origin/master && git pull --ff)'
|
||||
cd /opt/openstreetmap-carto
|
||||
if [[ ! -f /opt/openstreetmap-carto/mapnik.xml || ! -s /opt/openstreetmap-carto/mapnik.xml ]]; then
|
||||
carto project.mml >/opt/openstreetmap-carto/mapnik.xml
|
||||
fi
|
||||
chown -R _renderd:_renderd /opt/openstreetmap-carto
|
||||
|
||||
# Reset map. Force it.
|
||||
/opt/wrolpi/scripts/reset_map.sh -f
|
||||
|
||||
cp /opt/wrolpi/etc/raspberrypios/renderd.conf /etc/renderd.conf
|
||||
# Enable mod_tile.
|
||||
cp /opt/wrolpi/etc/raspberrypios/mod_tile.conf /etc/apache2/conf-available/mod_tile.conf
|
||||
|
||||
/usr/sbin/a2enconf mod_tile
|
||||
|
||||
# Configure Apache2 to listen on 8084.
|
||||
cp /opt/wrolpi/etc/raspberrypios/ports.conf /etc/apache2/ports.conf
|
||||
cp /opt/wrolpi/etc/raspberrypios/000-default.conf /etc/apache2/sites-available/000-default.conf
|
||||
# Copy Leaflet files to Apache's directory so they can be used offline.
|
||||
cp /opt/wrolpi/etc/raspberrypios/index.html \
|
||||
/opt/wrolpi/modules/map/leaflet.js \
|
||||
/opt/wrolpi/modules/map/leaflet.css /var/www/html/
|
||||
chmod 644 /var/www/html/*
|
||||
|
||||
systemctl enable renderd
|
||||
systemctl stop renderd
|
||||
systemctl start renderd
|
||||
|
||||
systemctl stop apache2
|
||||
systemctl start apache2
|
||||
|
|
@ -1,84 +0,0 @@
|
|||
#! /usr/bin/env bash
|
||||
# This script installs OpenStreetMap tile server.
|
||||
# This server uses Apache2, renderd, and mod_tile to render and display map tiles.
|
||||
|
||||
function yes_or_no {
|
||||
while true; do
|
||||
read -p "$* [y/n]:" yn
|
||||
case $yn in
|
||||
[Yy]*) return 0 ;;
|
||||
[Nn]*) return 1 ;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
set -x
|
||||
set -e
|
||||
|
||||
# Update if we haven't updated in the last day.
|
||||
[ -z "$(find -H /var/lib/apt/lists -maxdepth 0 -mtime -1)" ] && apt update
|
||||
# Install map dependencies.
|
||||
apt install -y libboost-all-dev git tar unzip wget bzip2 build-essential autoconf libtool libxml2-dev libgeos-dev \
|
||||
libgeos++-dev libpq-dev libbz2-dev libproj-dev protobuf-c-compiler libfreetype6-dev libtiff5-dev \
|
||||
libicu-dev libgdal-dev libcairo2-dev libcairomm-1.0-dev libagg-dev liblua5.2-dev ttf-unifont lua5.1 liblua5.1-0-dev \
|
||||
postgis postgresql-12-postgis-3 postgresql-12-postgis-3-scripts osm2pgsql gdal-bin libmapnik-dev mapnik-utils \
|
||||
python3-mapnik apache2 apache2-dev libcurl4-gnutls-dev libiniparser-dev libmemcached-dev librados-dev \
|
||||
fonts-noto-cjk fonts-noto-hinted fonts-noto-unhinted postgresql-contrib osmium-tool
|
||||
|
||||
/usr/bin/npm install -g carto
|
||||
/usr/bin/carto -v
|
||||
|
||||
# Create `gis` database for map.
|
||||
sudo -u postgres psql -c '\l' | grep gis || sudo -u postgres createdb -E UTF8 -O wrolpi gis
|
||||
sudo -u postgres psql -d gis -c "CREATE EXTENSION postgis;" || :
|
||||
sudo -u postgres psql -d gis -c "CREATE EXTENSION hstore;" || :
|
||||
sudo -u postgres psql -d gis -c "ALTER TABLE geometry_columns OWNER TO wrolpi;"
|
||||
sudo -u postgres psql -d gis -c "ALTER TABLE spatial_ref_sys OWNER TO wrolpi;"
|
||||
|
||||
# Install Ubuntu 20.04 compatible mod_tile.
|
||||
git clone -b switch2osm https://github.com/lrnselfreliance/mod_tile.git /tmp/mod_tile || :
|
||||
if [ ! -f /usr/lib/apache2/modules/mod_tile.so ]; then
|
||||
(cd /tmp/mod_tile && ./autogen.sh && ./configure && make -j4 && make install && make install-mod_tile && ldconfig)
|
||||
fi
|
||||
# Install init/systemd config to start map service on startup.
|
||||
cp /tmp/mod_tile/debian/renderd.init /etc/init.d/renderd
|
||||
sudo chmod +x /etc/init.d/renderd
|
||||
cp /tmp/mod_tile/debian/renderd.service /lib/systemd/system/
|
||||
sed -ie 's/^RUNASUSER.*/RUNASUSER=wrolpi/' /etc/init.d/renderd
|
||||
chmod +x /etc/init.d/renderd
|
||||
[ ! -d /var/lib/mod_tile ] && mkdir /var/lib/mod_tile
|
||||
chown wrolpi /var/lib/mod_tile
|
||||
|
||||
# Initialize gis database.
|
||||
[ -d /opt/openstreetmap-carto ] && chown -R wrolpi:wrolpi /opt/openstreetmap-carto
|
||||
git clone https://github.com/lrnselfreliance/openstreetmap-carto.git /opt/openstreetmap-carto || :
|
||||
chown -R wrolpi:wrolpi /opt/openstreetmap-carto
|
||||
sudo -u wrolpi /bin/bash -c '(cd /opt/openstreetmap-carto && git fetch && git checkout master && git reset --hard origin/master && git pull --ff)'
|
||||
cd /opt/openstreetmap-carto
|
||||
if [[ ! -f /opt/openstreetmap-carto/mapnik.xml || ! -s /opt/openstreetmap-carto/mapnik.xml ]]; then
|
||||
/usr/bin/carto project.mml >/opt/openstreetmap-carto/mapnik.xml
|
||||
fi
|
||||
|
||||
# Reset map. Force it.
|
||||
/opt/wrolpi/scripts/reset_map.sh -f
|
||||
|
||||
cp /opt/wrolpi/etc/ubuntu20.04/renderd.conf /usr/local/etc/renderd.conf
|
||||
# Enable mod_tile.
|
||||
cp /opt/wrolpi/etc/ubuntu20.04/mod_tile.conf /etc/apache2/conf-available/mod_tile.conf
|
||||
|
||||
/usr/sbin/a2enconf mod_tile
|
||||
|
||||
# Configure Apache2 to listen on 8084.
|
||||
cp /opt/wrolpi/etc/ubuntu20.04/ports.conf /etc/apache2/ports.conf
|
||||
cp /opt/wrolpi/etc/ubuntu20.04/000-default.conf /etc/apache2/sites-available/000-default.conf
|
||||
cp /opt/wrolpi/etc/ubuntu20.04/index.html /var/www/html/index.html
|
||||
# Copy Leaflet files to Apache's directory so they can be used offline.
|
||||
cp /opt/wrolpi/modules/map/leaflet.js /var/www/html/leaflet.js
|
||||
cp /opt/wrolpi/modules/map/leaflet.css /var/www/html/leaflet.css
|
||||
|
||||
systemctl enable renderd
|
||||
systemctl stop renderd
|
||||
systemctl start renderd
|
||||
|
||||
systemctl stop apache2
|
||||
systemctl start apache2
|
||||
|
|
@ -1,31 +1,45 @@
|
|||
#!/usr/bin/env bash
|
||||
echo "Ubuntu 20.04 install start: $(date '+%Y-%m-%d %H:%M:%S')"
|
||||
echo "Raspberry Pi OS install start: $(date '+%Y-%m-%d %H:%M:%S')"
|
||||
|
||||
set -x
|
||||
set -e
|
||||
|
||||
# Install npm repos.
|
||||
npm --version || curl -fsSL https://deb.nodesource.com/setup_18.x | bash -
|
||||
|
||||
# Update if we haven't updated in the last day.
|
||||
[ -z "$(find -H /var/lib/apt/lists -maxdepth 0 -mtime -1)" ] && apt update
|
||||
# Install dependencies
|
||||
apt install -y apt-transport-https ca-certificates curl gnupg-agent gcc libpq-dev software-properties-common \
|
||||
postgresql-12 nginx-full nginx-doc python3.8-minimal python3.8-dev python3.8-doc python3.8-venv \
|
||||
ffmpeg hostapd nodejs chromium-browser chromium-chromedriver cpufrequtils network-manager
|
||||
apt install -y \
|
||||
apt-transport-https \
|
||||
ca-certificates \
|
||||
chromium \
|
||||
chromium-driver \
|
||||
cpufrequtils \
|
||||
curl \
|
||||
ffmpeg \
|
||||
gcc \
|
||||
gnupg-agent \
|
||||
hostapd \
|
||||
htop \
|
||||
libpq-dev \
|
||||
network-manager \
|
||||
nginx-doc \
|
||||
nginx-full \
|
||||
postgresql-13 \
|
||||
python3-dev \
|
||||
python3-doc \
|
||||
python3-full \
|
||||
python3-pip \
|
||||
python3-venv \
|
||||
software-properties-common \
|
||||
vim
|
||||
|
||||
# Install npm.
|
||||
npm --version || curl -fsSL https://deb.nodesource.com/setup_18.x | bash -
|
||||
apt install -y nodejs
|
||||
node -v
|
||||
npm -v
|
||||
|
||||
# Install serve, and archiving tools.
|
||||
sudo npm i -g serve single-file-cli@1.0.33 'git+https://github.com/lrnselfreliance/readability-extractor' &
|
||||
|
||||
# Setup the virtual environment that main.py expects
|
||||
pip3 --version || (
|
||||
# If no pip, install pip
|
||||
curl https://bootstrap.pypa.io/get-pip.py -o /tmp/get-pip.py &&
|
||||
python3 /tmp/get-pip.py &
|
||||
)
|
||||
|
||||
# Wait for npm and pip3.
|
||||
wait $(jobs -p)
|
||||
sudo npm i -g serve@12.0.1 single-file-cli@1.0.33 readability-extractor@0.0.6
|
||||
|
||||
# Build React app in background job.
|
||||
cd /opt/wrolpi/app || exit 5
|
||||
|
|
@ -33,7 +47,8 @@ npm install || npm install || npm install || npm install # try install multiple
|
|||
npm run build &
|
||||
|
||||
# Install python requirements in background job.
|
||||
pip3 install -r /opt/wrolpi/requirements.txt &
|
||||
python3 -m venv /opt/wrolpi/venv
|
||||
/opt/wrolpi/venv/bin/pip3 install -r /opt/wrolpi/requirements.txt &
|
||||
|
||||
wait $(jobs -p)
|
||||
|
||||
|
|
@ -62,9 +77,9 @@ visudo -c -f /etc/sudoers.d/90-wrolpi
|
|||
chown wrolpi:wrolpi /media/wrolpi
|
||||
|
||||
# Install the systemd services
|
||||
cp /opt/wrolpi/etc/ubuntu20.04/wrolpi-api.service /etc/systemd/system/
|
||||
cp /opt/wrolpi/etc/debian11/wrolpi-app.service /etc/systemd/system/
|
||||
cp /opt/wrolpi/etc/ubuntu20.04/wrolpi.target /etc/systemd/system/
|
||||
cp /opt/wrolpi/etc/raspberrypios/wrolpi-api.service /etc/systemd/system/
|
||||
cp /opt/wrolpi/etc/raspberrypios/wrolpi-app.service /etc/systemd/system/
|
||||
cp /opt/wrolpi/etc/raspberrypios/wrolpi.target /etc/systemd/system/
|
||||
/usr/bin/systemctl daemon-reload
|
||||
systemctl enable wrolpi-api.service
|
||||
systemctl enable wrolpi-app.service
|
||||
|
|
@ -74,13 +89,16 @@ systemctl stop wrolpi-app.service
|
|||
|
||||
# Configure Postgresql. Do this after the API is stopped.
|
||||
sudo -u postgres psql -c '\l' | grep wrolpi || (
|
||||
sudo -u postgres createuser wrolpi &&
|
||||
sudo -u postgres createuser -s wrolpi &&
|
||||
sudo -u postgres psql -c "alter user postgres password 'wrolpi'" &&
|
||||
sudo -u postgres psql -c "alter user wrolpi password 'wrolpi'" &&
|
||||
sudo -u postgres createdb -E UTF8 -O wrolpi wrolpi
|
||||
)
|
||||
# Initialize/upgrade the WROLPi database.
|
||||
(cd /opt/wrolpi && /usr/bin/python3 /opt/wrolpi/main.py db upgrade)
|
||||
(cd /opt/wrolpi && /opt/wrolpi/venv/bin/python3 /opt/wrolpi/main.py db upgrade)
|
||||
|
||||
# Install map only if that script hasn't finished.
|
||||
[ -f /var/www/html/leaflet.css ] || /opt/wrolpi/scripts/install_map_raspberrypios.sh
|
||||
|
||||
set +x
|
||||
|
||||
|
|
@ -66,11 +66,11 @@ if [ -d /var/lib/mod_tile ]; then
|
|||
else
|
||||
mkdir /var/lib/mod_tile
|
||||
fi
|
||||
chown -R wrolpi:wrolpi /var/lib/mod_tile
|
||||
chown -R _renderd:_renderd /var/lib/mod_tile
|
||||
|
||||
sudo -u postgres dropdb gis || :
|
||||
|
||||
sudo -u postgres createdb -E UTF8 -O wrolpi gis
|
||||
sudo -u postgres createdb -E UTF8 -O _renderd gis
|
||||
sudo -u postgres psql -d gis -c "CREATE EXTENSION postgis;" || :
|
||||
sudo -u postgres psql -d gis -c "CREATE EXTENSION hstore;" || :
|
||||
sudo -u postgres psql -d gis -c "ALTER TABLE geometry_columns OWNER TO wrolpi;"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue