Files
Claude 5792e201b6 Offline CUPS from the normal menu, local-file sites, build-dep install
- CUPS (Addons -> CUPS Printing, from ./install.sh or the Web UI) now
  installs from the offline bundle by itself when the kiosk can't reach
  the Ubuntu archive: lib/config.sh's run_with_offline_fallback switches
  apt to the bundle (kiosk-offline-apt on) around the install and back
  afterwards. No-op on manual installs or when online.
- Fix cups_is_installed reporting "not installed" for an installed CUPS:
  `dpkg -l | grep -q` under install.sh's pipefail fails when grep exits
  early and dpkg takes SIGPIPE. Uses dpkg-query on the one package now.
- Sites: an absolute path (/home/kiosk/docs/menu.pdf) is accepted and
  turned into a percent-encoded file:// URL, identically in the Sites
  menu (sites_parse_url) and the Web UI (parseUrl, with tests). Electron
  42 shows local HTML, PDFs (built-in viewer) and images as-is.
- iso/build-iso.sh checks its build tools (plus the --offline ones) and
  offers to `sudo apt install` what's missing; --install-deps does it
  without asking. --offline now refuses non-amd64 hosts up front.

Tested: offline chroot of the 26.04.1 server filesystem - action_install_cups
installed CUPS + printer-driver-all/hplip/gutenprint from the bundle with
no network and left apt back on normal sources; webui test suite passes;
Electron 42 rendered a file:// PDF and PNG with spaces/# in the path;
build-iso.sh stopped with the install command when apt-utils was missing
and no TTY, and installed it and built the ISO with --install-deps.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Cjz8a58eB5P9sUweqd3NHm
2026-10-03 13:29:04 +00:00

64 lines
2.5 KiB
Bash
Executable File

#!/bin/bash
################################################################################
# kiosk-offline-apt - point apt at the offline install bundle, or back.
#
# sudo kiosk-offline-apt on apt uses ONLY /opt/kiosk-offline/apt
# sudo kiosk-offline-apt off back to the normal Ubuntu archive
# kiosk-offline-apt status
#
# Installed by the custom ISO (iso/build-iso.sh); the bundle itself is
# only there on ISOs built with --offline. kiosk-firstboot turns this on
# by itself when first boot finds no internet, and back off afterwards;
# so does the CUPS addon install (lib/config.sh's
# run_with_offline_fallback). By hand it's for installing anything else
# from the bundle with no internet. While it's on, install.sh also
# unpacks the bundle's prebuilt node_modules instead of running npm
# (lib/config.sh's offline_mode_active checks for the file this writes).
#
# "Only" matters: with the normal archive still listed, apt would pick
# newer versions from it that it then can't download.
################################################################################
set -euo pipefail
BUNDLE_DIR=/opt/kiosk-offline
APT_CONF=/etc/apt/apt.conf.d/90-kiosk-offline
case "${1:-status}" in
on)
[[ $EUID -eq 0 ]] || { echo "Run with sudo" >&2; exit 1; }
if [[ ! -f "$BUNDLE_DIR/apt/Packages" ]]; then
echo "No offline bundle at $BUNDLE_DIR (ISO not built with --offline)" >&2
exit 1
fi
mkdir -p "$BUNDLE_DIR/sources.d"
echo "deb [trusted=yes] file:$BUNDLE_DIR/apt ./" > "$BUNDLE_DIR/offline.list"
cat > "$APT_CONF" <<EOF
// Written by kiosk-offline-apt - remove with: sudo kiosk-offline-apt off
Dir::Etc::SourceList "$BUNDLE_DIR/offline.list";
Dir::Etc::SourceParts "$BUNDLE_DIR/sources.d";
Acquire::Languages "none";
EOF
apt-get update -q >/dev/null
echo "apt now installs from the offline bundle only ($BUNDLE_DIR)."
;;
off)
[[ $EUID -eq 0 ]] || { echo "Run with sudo" >&2; exit 1; }
rm -f "$APT_CONF"
echo "apt is back on the normal Ubuntu sources."
echo "Run 'sudo apt update' once there's internet."
;;
status)
if [[ -f "$APT_CONF" ]]; then
echo "on (apt uses $BUNDLE_DIR/apt only)"
else
echo "off"
fi
[[ -f "$BUNDLE_DIR/bundle-info.txt" ]] && sed -n '1,3p;5,6p' "$BUNDLE_DIR/bundle-info.txt"
;;
*)
echo "Usage: kiosk-offline-apt on|off|status" >&2
exit 2
;;
esac