wrolpi/scripts/install_npm_tools.sh
lrnselfreliance d69f8317aa
serve, single-file and readability-extractor install from a committed lockfile (#912)
They were installed with `npm i -g`, which pinned only the three top-level versions and
resolved their 156 dependencies fresh from the registry, so a forged TLS certificate (as
the eMudhra key compromise allowed) could change code WROLPi runs on every archive.
npm-tools/package-lock.json pins every package with its sha512, and install_npm_tools.sh
runs `npm ci` and links the commands into /usr/local/bin for every install path, upgrades,
both images and the archive container.  The app container's unpinned, unused global serve
is removed.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 10:39:08 -06:00

18 lines
1,001 B
Bash
Executable file

#!/usr/bin/env bash
# Usage: install_npm_tools.sh [NPM_TOOLS_DIR]
#
# Installs the npm command-line tools WROLPi runs (serve, single-file, readability-extractor) from the committed
# npm-tools/package-lock.json. `npm ci` checks every package against its sha512 in the lockfile, so a forged TLS
# certificate for the registry cannot change them; `npm i -g` resolved the whole dependency tree fresh. The commands
# are linked into /usr/local/bin, where WROLPi, help.sh and the systemd units find them.
set -e
NPM_TOOLS=${1:-$(dirname "$(dirname "$(realpath "$0")")")/npm-tools}
npm ci --prefix "${NPM_TOOLS}" --omit=dev --no-audit --no-fund
# Remove the copies older WROLPi versions installed globally (in /usr/bin on Raspberry Pi OS) so they cannot be found
# instead of these.
npm rm -g serve single-file-cli readability-extractor >/dev/null 2>&1 || :
for command in serve single-file readability-extractor; do
ln -sf "${NPM_TOOLS}/node_modules/.bin/${command}" "/usr/local/bin/${command}"
done