2023-02-24 17:31:08 -07:00
|
|
|
#! /usr/bin/env bash
|
2023-09-24 20:10:09 -06:00
|
|
|
# Installs any new dependencies of the App and API. Uses internet.
|
2023-02-24 17:31:08 -07:00
|
|
|
|
2023-09-24 20:10:09 -06:00
|
|
|
set -e
|
|
|
|
|
set -x
|
2023-05-23 16:41:48 -06:00
|
|
|
|
2025-12-07 17:03:55 -07:00
|
|
|
# Ensure help service is always restarted, but preserve exit code
|
|
|
|
|
cleanup() {
|
|
|
|
|
local exit_code=$?
|
|
|
|
|
systemctl restart wrolpi-help.service || :
|
|
|
|
|
exit $exit_code
|
|
|
|
|
}
|
|
|
|
|
trap cleanup EXIT
|
2025-12-06 13:35:32 -07:00
|
|
|
|
2026-03-19 15:02:12 -06:00
|
|
|
# Upgrade Controller first so users can monitor the rest of the upgrade.
|
|
|
|
|
upgrade_controller() {
|
|
|
|
|
echo "Upgrading WROLPi Controller..."
|
|
|
|
|
|
|
|
|
|
# Create Controller venv if it doesn't exist
|
|
|
|
|
if [ ! -d /opt/wrolpi/controller/venv ]; then
|
|
|
|
|
echo "Creating Controller virtual environment..."
|
|
|
|
|
python3 -m venv /opt/wrolpi/controller/venv
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Clear bytecode cache before upgrading.
|
|
|
|
|
find /opt/wrolpi/controller/venv -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || :
|
|
|
|
|
find /opt/wrolpi/controller/venv -name "*.pyc" -delete 2>/dev/null || :
|
|
|
|
|
|
|
|
|
|
# Install dependencies while Controller is still running to minimize downtime.
|
|
|
|
|
echo "Updating Controller dependencies..."
|
|
|
|
|
/opt/wrolpi/controller/venv/bin/pip install --upgrade pip
|
|
|
|
|
/opt/wrolpi/controller/venv/bin/pip install --upgrade -r /opt/wrolpi/controller/requirements.txt
|
|
|
|
|
|
|
|
|
|
# Dependencies are ready, now restart the Controller as quickly as possible.
|
|
|
|
|
systemctl daemon-reload
|
|
|
|
|
systemctl restart wrolpi-controller
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
upgrade_controller || echo "Controller upgrade failed, continuing..."
|
|
|
|
|
|
2023-09-24 20:10:09 -06:00
|
|
|
# Install any App dependencies.
|
|
|
|
|
cd /opt/wrolpi/app || exit 1
|
|
|
|
|
npm install || npm install || npm install || npm install # try install multiple times :(
|
2023-05-01 13:00:23 -06:00
|
|
|
|
2026-02-16 08:08:46 -07:00
|
|
|
# Install/upgrade Deno runtime.
|
|
|
|
|
upgrade_deno() {
|
Single file deno (#478)
* Singlefile runs under Deno 2.8.3; browser leftovers are reaped.
single-file-cli is designed for Deno. Under node 18 (Debian 12/RPi OS) it
cannot reach the browser CDP on IPv6-enabled hosts ("localhost" resolves to
::1 first with no IPv4 fallback) and it never exits after a successful save,
blocking the download worker forever.
The native path and the Archive docker container now run single-file with
"deno run". Deno is pinned at v2.8.3 everywhere because yt-dlp 2026.06.09
requires at least 2.3.0 (our node is Debian's v18, below yt-dlp's v22
minimum). Deno >= 2.3 kills the browser single-file spawns (piped stderr
that single-file never reads), so the browser is run through
singlefile_browser_wrapper.sh which discards its stderr.
Commands are run in their own process group which is killed when they
finish, reaping the browser single-file leaves behind. The Archive
downloader now has a ten minute timeout. Install scripts install Deno
(previously only upgrade.sh and the image builds did).
* Singlefile writes to a file instead of dumping to stdout.
Deno >= 2.3 truncates large --dump-content output at exit; compressed
(SingleFileZ) singlefiles of large pages lost their ZIP tail, failed the
compression check in write_archive_files, and were destroyed by the HTML
prettifier (blank white archives). single-file now writes its result to a
temporary file which WROLPi reads back.
As insurance, a singlefile marked compressed (<html data-sfz) whose ZIP is
unreadable is now stored verbatim instead of being prettified.
* Compressed Archive screenshots and readability images are no longer broken.
The index.html inside a compressed (SingleFileZ) singlefile references its
resources by relative ZIP paths. Screenshots are now taken from the fully
extracted ZIP so those references resolve. Readability images are inlined
as data URIs read from the ZIP (readability-extractor absolutizes relative
srcs against the page URL, so both forms are matched).
* Compressed Archives are created by converting the uncompressed capture.
The page is always captured uncompressed; readability, screenshot, and
title come from that canonical page (its images are inline data URIs, so
no ZIP extraction or image inlining is needed). When compress_singlefile
is set, a second single-file run converts the captured file into a
compressed (SingleFileZ) self-extracting file. The conversion is a local
file:// operation - the page is not fetched again, and single-file
preserves the original URL header when re-saving its own pages. If the
conversion fails, the uncompressed singlefile is stored instead.
* Consolidating duplicate compressed-singlefile tests.
The write_archive_files tests (verbatim write, title fallback, broken-ZIP
guard, readability inlining) are combined into one test; the helper probes
and the setting-plumbing tests are each merged into one. The do_singlefile
compression-failure scenario and the timeout constant are folded into the
main do_singlefile test, which shared their setup.
* Addressing review comments: removeprefix, PermissionError when killing.
* Bumping version to 0.24.1-beta.
* Install scripts assert the deno.zip hash to avoid malicious or invalid files.
The hashes are the official sha256sum assets of the Deno v2.8.3 release,
per architecture.
* Archive Dockerfile asserts the deno.zip hash to avoid malicious or invalid files.
---------
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-06-12 17:07:10 -06:00
|
|
|
DENO_VERSION="v2.8.3"
|
2026-02-16 08:08:46 -07:00
|
|
|
ARCH=$(uname -m)
|
|
|
|
|
if [ "$ARCH" = "aarch64" ]; then
|
|
|
|
|
DENO_ARCH="aarch64-unknown-linux-gnu"
|
|
|
|
|
elif [ "$ARCH" = "x86_64" ]; then
|
|
|
|
|
DENO_ARCH="x86_64-unknown-linux-gnu"
|
|
|
|
|
else
|
|
|
|
|
echo "Unsupported architecture for Deno: $ARCH"
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Check if Deno is already installed at the correct version.
|
|
|
|
|
if command -v deno &> /dev/null; then
|
|
|
|
|
CURRENT_VERSION=$(deno --version | head -n1 | awk '{print "v"$2}')
|
|
|
|
|
if [ "$CURRENT_VERSION" = "$DENO_VERSION" ]; then
|
|
|
|
|
echo "Deno ${DENO_VERSION} already installed"
|
|
|
|
|
return 0
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo "Installing Deno ${DENO_VERSION} for ${ARCH}..."
|
|
|
|
|
curl -fsSL "https://github.com/denoland/deno/releases/download/${DENO_VERSION}/deno-${DENO_ARCH}.zip" -o /tmp/deno.zip
|
|
|
|
|
unzip -o /tmp/deno.zip -d /usr/local/bin/
|
|
|
|
|
chmod +x /usr/local/bin/deno
|
|
|
|
|
rm /tmp/deno.zip
|
|
|
|
|
deno --version
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
upgrade_deno || echo "Deno upgrade failed, continuing..."
|
|
|
|
|
|
2026-06-11 20:05:10 -06:00
|
|
|
# Upgrade single-file to the pinned version; old versions (1.x) create compressed Archives without
|
|
|
|
|
# the SingleFile comment header in the prelude, which WROLPi cannot validate.
|
|
|
|
|
# readability-extractor is pinned alongside it to match the install scripts.
|
|
|
|
|
upgrade_singlefile() {
|
|
|
|
|
SINGLE_FILE_VERSION="2.0.73"
|
|
|
|
|
if [ "$(single-file --version 2>/dev/null)" != "${SINGLE_FILE_VERSION}" ]; then
|
|
|
|
|
echo "Upgrading single-file-cli to ${SINGLE_FILE_VERSION}..."
|
|
|
|
|
npm i -g single-file-cli@${SINGLE_FILE_VERSION} readability-extractor@0.0.6
|
|
|
|
|
else
|
|
|
|
|
echo "single-file-cli ${SINGLE_FILE_VERSION} already installed"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
upgrade_singlefile || echo "single-file upgrade failed, continuing..."
|
|
|
|
|
|
2026-02-28 16:11:12 -07:00
|
|
|
# Clear Python bytecode cache before upgrading packages.
|
|
|
|
|
echo "Clearing Python bytecode cache..."
|
|
|
|
|
find /opt/wrolpi/venv -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || :
|
|
|
|
|
find /opt/wrolpi/venv -name "*.pyc" -delete 2>/dev/null || :
|
|
|
|
|
|
2023-09-24 20:10:09 -06:00
|
|
|
# Install any new Python requirements.
|
2024-07-31 15:01:31 -06:00
|
|
|
/opt/wrolpi/venv/bin/pip3 install --upgrade -r /opt/wrolpi/requirements.txt
|
2026-07-05 15:40:47 -06:00
|
|
|
# Upgrade the WROLPi database. Never fatal: the database may be down and
|
|
|
|
|
# repair.sh (which runs at the end of this upgrade) may be exactly what fixes
|
|
|
|
|
# it; initialize_api_db.sh re-runs this migration there.
|
|
|
|
|
(cd /opt/wrolpi && /opt/wrolpi/venv/bin/python3 /opt/wrolpi/main.py db upgrade) || \
|
|
|
|
|
echo "WARNING: db upgrade failed (database down?); it will be retried during repair."
|
2023-07-11 17:23:56 -06:00
|
|
|
|
2023-11-23 16:20:28 -07:00
|
|
|
# Upgrade WROLPi Help.
|
2023-11-23 16:22:46 -07:00
|
|
|
/opt/wrolpi/scripts/install_help_service.sh || echo "Help install failed."
|
2023-11-23 16:20:28 -07:00
|
|
|
|
2026-03-29 18:58:31 -06:00
|
|
|
# Migrate from old Leaflet/renderd/Apache2 map stack to MapLibre GL JS + PMTiles.
|
|
|
|
|
/opt/wrolpi/scripts/install_protomaps.sh || echo "Protomaps migration failed."
|
|
|
|
|
|
|
|
|
|
# Download map fonts blob if missing.
|
|
|
|
|
MAP_FONTS_BLOB=/opt/wrolpi-blobs/map-fonts.tar.gz
|
|
|
|
|
if [[ ! -f ${MAP_FONTS_BLOB} || ! -s ${MAP_FONTS_BLOB} ]]; then
|
|
|
|
|
echo "Downloading map fonts..."
|
|
|
|
|
mkdir -p /tmp/map-fonts-dl
|
|
|
|
|
curl -fsSL https://github.com/protomaps/basemaps-assets/archive/refs/heads/main.tar.gz \
|
|
|
|
|
| tar -xz --strip-components=1 -C /tmp/map-fonts-dl basemaps-assets-main/fonts
|
|
|
|
|
tar -czf "${MAP_FONTS_BLOB}" -C /tmp/map-fonts-dl fonts
|
|
|
|
|
rm -rf /tmp/map-fonts-dl
|
|
|
|
|
fi || echo "Map fonts download failed, continuing..."
|
|
|
|
|
|
|
|
|
|
# Download map overview blob if missing (42 MB, provides global zoom 0-6).
|
|
|
|
|
MAP_OVERVIEW_BLOB=/opt/wrolpi-blobs/map-overview.pmtiles
|
|
|
|
|
if [[ ! -f ${MAP_OVERVIEW_BLOB} || ! -s ${MAP_OVERVIEW_BLOB} ]]; then
|
|
|
|
|
echo "Downloading map overview..."
|
|
|
|
|
curl -fsSL https://wrolpi.nyc3.cdn.digitaloceanspaces.com/maps/map-overview.pmtiles \
|
|
|
|
|
-o "${MAP_OVERVIEW_BLOB}"
|
|
|
|
|
fi || echo "Map overview download failed, continuing..."
|
2025-01-01 10:59:28 -07:00
|
|
|
|
2026-07-05 13:09:11 -06:00
|
|
|
# Finish configuring any package left half-configured by an interrupted apt/dpkg run
|
|
|
|
|
# (e.g. a prior upgrade that died at a conffile prompt).
|
|
|
|
|
DEBIAN_FRONTEND=noninteractive dpkg --force-confdef --force-confold --configure -a || :
|
|
|
|
|
|
Replace nginx with Caddy for TLS termination and reverse proxying.
- Replace nginx with Caddy as the web server for both Docker and native
(RPi/Debian) deployments. Caddy handles HTTPS termination, reverse
proxying to all services (API, React app, Controller, Kiwix, Help, Map),
and serves the media/download file browsers.
- Generate a Root CA and signed leaf certificates for HTTPS. The Root CA
uses Name Constraints to restrict signing to local addresses only
(.local, localhost, and RFC 1918 private IP ranges), mitigating MITM
risk if the CA key is compromised.
- Add an HTTP landing page that guides users through one-time CA
certificate installation on iOS, Android, macOS, Windows, Linux, and
Firefox, with auto-redirect when the cert is already trusted.
- Add trailing-slash redirects for /controller, /docs, /media, and
/download so bare paths don't fall through to the React catch-all.
- Add a Root CA download link on the Settings page under Configs.
- Update help.sh diagnostics for IPv6 listener detection and HTTP/2
status codes.
- Remove all nginx config files and the https_proxy Docker container.
- Bump wrolpi-help submodule with certificate documentation.
2026-03-07 12:08:27 -07:00
|
|
|
# Migrate from nginx to Caddy if necessary.
|
|
|
|
|
if ! command -v caddy &>/dev/null; then
|
|
|
|
|
echo "Installing Caddy (replacing nginx)..."
|
|
|
|
|
# Disable and stop nginx if it was previously used.
|
|
|
|
|
systemctl stop nginx 2>/dev/null || :
|
|
|
|
|
systemctl disable nginx 2>/dev/null || :
|
|
|
|
|
# Install Caddy from official apt repo.
|
2026-07-05 13:02:59 -06:00
|
|
|
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | gpg --batch --yes --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
|
Replace nginx with Caddy for TLS termination and reverse proxying.
- Replace nginx with Caddy as the web server for both Docker and native
(RPi/Debian) deployments. Caddy handles HTTPS termination, reverse
proxying to all services (API, React app, Controller, Kiwix, Help, Map),
and serves the media/download file browsers.
- Generate a Root CA and signed leaf certificates for HTTPS. The Root CA
uses Name Constraints to restrict signing to local addresses only
(.local, localhost, and RFC 1918 private IP ranges), mitigating MITM
risk if the CA key is compromised.
- Add an HTTP landing page that guides users through one-time CA
certificate installation on iOS, Android, macOS, Windows, Linux, and
Firefox, with auto-redirect when the cert is already trusted.
- Add trailing-slash redirects for /controller, /docs, /media, and
/download so bare paths don't fall through to the React catch-all.
- Add a Root CA download link on the Settings page under Configs.
- Update help.sh diagnostics for IPv6 listener detection and HTTP/2
status codes.
- Remove all nginx config files and the https_proxy Docker container.
- Bump wrolpi-help submodule with certificate documentation.
2026-03-07 12:08:27 -07:00
|
|
|
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | tee /etc/apt/sources.list.d/caddy-stable.list
|
|
|
|
|
apt-get update
|
2026-07-05 13:09:11 -06:00
|
|
|
# Non-interactive: a conffile prompt (e.g. repair.sh already wrote /etc/caddy/Caddyfile)
|
|
|
|
|
# would otherwise hang or abort under the tty-less wrolpi-upgrade.service.
|
|
|
|
|
DEBIAN_FRONTEND=noninteractive apt-get install -y \
|
|
|
|
|
-o Dpkg::Options::=--force-confdef -o Dpkg::Options::=--force-confold caddy
|
Replace nginx with Caddy for TLS termination and reverse proxying.
- Replace nginx with Caddy as the web server for both Docker and native
(RPi/Debian) deployments. Caddy handles HTTPS termination, reverse
proxying to all services (API, React app, Controller, Kiwix, Help, Map),
and serves the media/download file browsers.
- Generate a Root CA and signed leaf certificates for HTTPS. The Root CA
uses Name Constraints to restrict signing to local addresses only
(.local, localhost, and RFC 1918 private IP ranges), mitigating MITM
risk if the CA key is compromised.
- Add an HTTP landing page that guides users through one-time CA
certificate installation on iOS, Android, macOS, Windows, Linux, and
Firefox, with auto-redirect when the cert is already trusted.
- Add trailing-slash redirects for /controller, /docs, /media, and
/download so bare paths don't fall through to the React catch-all.
- Add a Root CA download link on the Settings page under Configs.
- Update help.sh diagnostics for IPv6 listener detection and HTTP/2
status codes.
- Remove all nginx config files and the https_proxy Docker container.
- Bump wrolpi-help submodule with certificate documentation.
2026-03-07 12:08:27 -07:00
|
|
|
fi
|
|
|
|
|
|
2026-03-28 16:28:47 -06:00
|
|
|
# Install Samba if not already installed.
|
|
|
|
|
if ! command -v smbd &>/dev/null; then
|
|
|
|
|
echo "Installing Samba..."
|
|
|
|
|
apt-get update
|
2026-07-05 13:09:11 -06:00
|
|
|
DEBIAN_FRONTEND=noninteractive apt-get install -y \
|
|
|
|
|
-o Dpkg::Options::=--force-confdef -o Dpkg::Options::=--force-confold samba
|
2026-03-28 16:28:47 -06:00
|
|
|
fi
|
|
|
|
|
|
2026-04-07 20:01:49 -06:00
|
|
|
# Install gnome-disk-utility if not already installed (provides desktop disk management GUI).
|
|
|
|
|
if ! command -v gnome-disks &>/dev/null; then
|
|
|
|
|
echo "Installing gnome-disk-utility..."
|
|
|
|
|
apt-get update
|
2026-07-05 13:09:11 -06:00
|
|
|
DEBIAN_FRONTEND=noninteractive apt-get install -y \
|
|
|
|
|
-o Dpkg::Options::=--force-confdef -o Dpkg::Options::=--force-confold gnome-disk-utility
|
2026-04-07 20:01:49 -06:00
|
|
|
fi
|
|
|
|
|
|
2026-07-09 07:30:36 -06:00
|
|
|
# Install dnsmasq-base if not already installed (NetworkManager needs it for the hotspot's
|
|
|
|
|
# DHCP; it is only a Recommends of network-manager, so ISOs built with --apt-recommends
|
|
|
|
|
# false shipped without it). iw and rfkill are WiFi diagnostic tools.
|
2026-07-09 07:34:56 -06:00
|
|
|
if ! command -v dnsmasq &>/dev/null || ! command -v iw &>/dev/null || ! command -v rfkill &>/dev/null; then
|
2026-07-09 07:30:36 -06:00
|
|
|
echo "Installing dnsmasq-base, iw, rfkill..."
|
|
|
|
|
apt-get update
|
|
|
|
|
DEBIAN_FRONTEND=noninteractive apt-get install -y \
|
|
|
|
|
-o Dpkg::Options::=--force-confdef -o Dpkg::Options::=--force-confold dnsmasq-base iw rfkill
|
|
|
|
|
fi
|
|
|
|
|
|
2026-04-07 20:01:49 -06:00
|
|
|
# Clean up stale landing page (Controller now serves port 80 directly).
|
|
|
|
|
rm -f /var/www/landing.html
|
|
|
|
|
|
2023-09-24 20:10:09 -06:00
|
|
|
# Install any configs, restart services.
|
|
|
|
|
/opt/wrolpi/repair.sh
|