wrolpi/scripts/install_debian.sh

90 lines
3.2 KiB
Bash
Raw Permalink Normal View History

#!/usr/bin/env bash
echo "Debian install start: $(date '+%Y-%m-%d %H:%M:%S')"
set -x
set -e
# Run the install in a predictable UTF-8 locale. Fresh images (or SSH sessions
# forwarding LC_* variables from the client) may reference an ungenerated
# locale, which makes apt/perl/python emit "Cannot set LC_CTYPE" warnings
# throughout the install. C.UTF-8 is built into glibc, always present, and
# locale-neutral, so this does not change the user's configured locale.
export LC_ALL=C.UTF-8
# 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-get install -y $(cat /opt/wrolpi/debian-live-config/config/package-lists/wrolpi.list.chroot)
# App dependencies were installed.
node -v
npm -v
# Install serve, and archiving tools. Check each independently so a present
# single-file cannot mask a missing serve (which breaks wrolpi-app).
command -v serve >/dev/null || sudo npm i -g serve@12.0.1
single-file --version >/dev/null 2>&1 || sudo npm i -g single-file-cli@2.0.73
command -v readability-extractor >/dev/null || sudo npm i -g readability-extractor@0.0.6
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
# Install Deno runtime; single-file runs under it.
command -v deno || {
DENO_VERSION="v2.8.3"
ARCH=$(uname -m)
if [ "$ARCH" = "aarch64" ]; then
DENO_ARCH="aarch64-unknown-linux-gnu"
DENO_SHA256="d4589cc1ffcbf1995c92a0127d932aaf832ac70cfdcc6d5b7bf38043cf303575"
else
DENO_ARCH="x86_64-unknown-linux-gnu"
DENO_SHA256="30455b845ffa6082209c3590269c910ad3b7efdf28c9879afd4006c47ae54197"
fi
curl -fsSL "https://github.com/denoland/deno/releases/download/${DENO_VERSION}/deno-${DENO_ARCH}.zip" -o /tmp/deno.zip
# Assert the hash to avoid malicious or invalid files.
echo "${DENO_SHA256} /tmp/deno.zip" | sha256sum -c -
unzip -o /tmp/deno.zip -d /usr/local/bin/
chmod +x /usr/local/bin/deno
rm /tmp/deno.zip
}
deno --version
# Build React app in background job.
cd /opt/wrolpi/app || exit 5
npm install || npm install || npm install || npm install # try install multiple times :(
# Install python requirements in background job.
python3 -m venv /opt/wrolpi/venv
/opt/wrolpi/venv/bin/pip3 install --upgrade -r /opt/wrolpi/requirements.txt
# Create the Controller venv (kept separate from the main API venv).
python3 -m venv /opt/wrolpi/controller/venv
/opt/wrolpi/controller/venv/bin/pip3 install --upgrade -r /opt/wrolpi/controller/requirements.txt
# Create the WROLPi user
grep wrolpi: /etc/passwd || useradd -md /home/wrolpi wrolpi -s "$(command -v bash)"
# Install Caddy from official apt repo if not already installed.
if ! command -v caddy &>/dev/null; then
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | gpg --batch --yes --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | tee /etc/apt/sources.list.d/caddy-stable.list
apt-get update
apt-get install -y caddy
fi
# Install WROLPi Help.
/opt/wrolpi/scripts/install_help_service.sh
# Repair will install configs and restart services.
/opt/wrolpi/repair.sh
set +x
echo "
WROLPi has successfully been installed!
Browse to http://$(hostname).local to choose the drive for your library, or join
the WiFi hotspot:
SSID: WROLPi
Password: wrolpi hotspot
"