diff --git a/linux/README.md b/linux/README.md new file mode 100644 index 0000000..bc9400f --- /dev/null +++ b/linux/README.md @@ -0,0 +1,212 @@ +# Linux (Ubuntu) bundle (optional) + +An additive, self-contained way to produce a double-clickable Linux desktop +install of Luminary. The server and Docker workflow stay the source of truth: +this folder only *packages* the existing `dist/` + `server/` output, and the +build writes its artifacts **outside the checkout** — exactly like +[`windows/`](../windows/README.md). + +## Isolation guarantees + +1. **The packaging tree is additive.** There is no `package.json` script for + this, and no change to `.gitignore` (beyond ignoring the tarball in + `releases/`), `.dockerignore`, `Dockerfile`, `docker-compose.yml` or + `scripts/deploy.mjs`. Invoke it directly: `node linux/build.mjs`. The only + app-side behaviour used is the opt-in desktop mode in `server/config.mjs` + + `server/index.mjs` (`LUMINARY_LOCAL=1`), which the Windows launcher already + introduced; it stays off unless the launcher sets it. +2. **Artifacts live outside the repo** (default: `~/.cache/luminary-linux`). The + script refuses an `--out` inside the checkout, because `scripts/deploy.mjs` + rsyncs the worktree to production and `docker build` would pull a ~300 MB + bundle into its context. +3. **The worktree must be clean outside `linux/`** before and after a build (the + untracked `logo.png` is tolerated). `--allow-dirty` overrides it. +4. **Nothing in the app changes at run time.** The bundle is the unchanged + `server/` + `dist/` + production `node_modules`, started with `PORT`, `HOST`, + `NODE_ENV` and `LUMINARY_DATA` — all variables the server already reads. + +## What the end user needs + +Ubuntu 22.04 or 24.04, 64-bit, and a browser. Nothing to install: Node 24 is +inside the bundle (`runtime/bin/node`), sharp's Linux binaries are bundled, and +there is no deb, no apt step and no root. + +| Piece | What it uses | +| --- | --- | +| `runtime/bin/node` | the official Node 24 linux-x64 build, SHA-256 checked against nodejs.org | +| `sharp` | `@img/sharp-linux-x64` + `@img/sharp-libvips-linux-x64`, installed from this repo's lockfile | +| app window | Chrome, Chromium, Edge, Brave or Vivaldi `--app=`; Firefox and the default browser are fallbacks | +| Develop module | a browser with WebGL2 | + +## Build + +```bash +node linux/build.mjs # npm run build, then the bundle +node linux/build.mjs --skip-build # reuse the existing dist/ +node linux/build.mjs --out /srv/builds/luminary-linux +node linux/build.mjs --skip-build --publish +``` + +Output: + +``` +/ + Luminary-0.5.1-linux-x64.tar.gz portable bundle + Luminary-0.5.1-linux-amd64.deb Ubuntu package, built from the same bundle + stage/Luminary/ the unpacked bundle (kept for inspection) + cache/node-v24.22.2-linux-x64.tar.gz + cache/SHASUMS256-v24.22.2.txt +``` + +The build prints the archive size, its SHA-256, the Node version, the .deb size +and the staged folder. The tarball keeps the executable bits on `luminary` and +`runtime/bin/node`, so extracting it is enough — no `chmod` needed. The `.deb` +is built with the `dpkg` package's `dpkg-deb` when it is installed; on a host +without it the build prints a warning and produces only the tarball. + +### Installing on Ubuntu + +Easiest: install the `.deb`, which puts the app in `/opt/luminary`, adds +`/usr/bin/luminary`, an applications-menu entry and the icon. Your photos and +catalog still live in `~/.local/share/luminary`, so removing or upgrading the +package never touches them: + +```bash +sudo apt install ./Luminary-0.5.1-linux-amd64.deb +luminary # or launch Luminary from the applications menu +``` + +`apt` pulls in the two runtime libraries it needs (`libstdc++6`, `libgomp1`); +Node, the server and sharp's Linux binaries are inside the package. Uninstall +with `sudo apt remove luminary`; `sudo apt purge luminary` also removes +`/opt/luminary` but never the data folder. + +Or stay portable — nothing installed, nothing to root: + +```bash +tar -xzf Luminary-0.5.1-linux-x64.tar.gz +cd Luminary +./luminary # starts desktop mode and opens the app window +./install.sh # optional: add Luminary to the applications menu +``` + +`--publish` copies the tarball and a `SHA256SUMS.txt` into +[`releases/`](releases/), the hand-off folder for a USB stick, network share or +release upload. That is the only write the builder makes inside the checkout. +`scripts/deploy.mjs` rsyncs the worktree, so remove the tarball from `releases/` +after transferring if you do not want it on the server. + +## What is in the bundle + +``` +Luminary/ + luminary bash launcher: start, health wait, app window + install.sh adds ~/.local/share/applications/luminary.desktop + Luminary.png 256×256 icon for the menu + version.txt version, commit, and the Node pin (version, SHA-256, size) + README-linux.txt end-user instructions + LICENSE, THIRD_PARTY_NOTICES.md, licenses/ + runtime/ official Node 24 linux-x64 (bin/node, lib/node_modules) + app/ + server/ unchanged, minus server/data and *.test.mjs + dist/ the normal Vite build (UI, lens db, guide PDF) + package.json provenance + package-lock.json + node_modules/ production deps installed with --os=linux --cpu=x64 +``` + +## Running it + +`./luminary` picks a free loopback port from 8787, sets +`LUMINARY_DATA=~/.local/share/luminary`, starts the server with +`LUMINARY_LOCAL=1`, waits for `/api/health`, then opens a chromeless window: + +``` +google-chrome --app=http://127.0.0.1:8787 \ + --user-data-dir=~/.local/share/luminary/window-profile \ + --class=Luminary +``` + +No tabs, no address bar, its own profile and window size. `./luminary --browser` +opens a normal tab instead (`LUMINARY_WINDOW=browser` works too). + +| Command | What it does | +| --- | --- | +| `./luminary` | start (or reuse a running server) and open the window | +| `./luminary --stop` | stop the server; data stays | +| `./luminary --status` | bundle, data folder, pid, URL and `/api/health` | +| `./luminary --verify` | list any missing piece of the bundle | +| `./luminary --install` | add the applications-menu entry | +| `./luminary --uninstall` | remove that entry, keep the catalog | + +The `.deb` installs the same launcher as `/usr/bin/luminary`, so every flag +works there too (`luminary --stop`, `--status`, `--verify`). Its data folder is +the same `~/.local/share/luminary`. + +### Single-user desktop mode + +The launcher starts the server with `LUMINARY_LOCAL=1`, the same mode the +Windows bundle uses: + +- one admin (`local@luminary`) is created on first start and reused afterwards; +- `/api/auth/me` answers without a cookie, so the UI never shows signup or + sign-in, and registration returns 403; +- the account is an admin, so every panel works, with no password to remember; +- the server binds `127.0.0.1`, so this is not reachable from the network. + Starting with `HOST=0.0.0.0` and `LUMINARY_LOCAL=1` logs a warning at boot. + +## Smoke test + +The automated first pass is [`SMOKE-LINUX.sh`](SMOKE-LINUX.sh). Run it from the +extracted bundle (or a `.deb` install): + +```bash +./SMOKE-LINUX.sh # bundle in this folder +./SMOKE-LINUX.sh --bundle /opt/luminary +``` + +It reports the distribution, browser and display, checks the bundle files and +`luminary --verify`, boots the real server through the launcher in desktop mode +(`local:true`, cookieless `/api/auth/me`, closed registration, `/api/sync`), +checks `--install`/`--uninstall` write and remove a real `.desktop` file, and +confirms `--stop` stops it. It uses a throwaway data folder and a private +`XDG_DATA_HOME`, so no real catalog or menu entry is touched, and it writes +`smoke-report.txt` next to the bundle. The app window itself stays a visual +check (the launcher runs with `LUMINARY_WINDOW=none` during the test). + +## Data, updates and backups + +- Catalog, originals, previews, `secret.key`, logs and the window profile live in + `~/.local/share/luminary` (or `$LUMINARY_DATA`), never inside the bundle. +- Update: `./luminary --stop`, replace `app/` and `runtime/` from a newer + bundle, start again. The SQLite schema migrates on boot. +- Back up: copy `~/.local/share/luminary` while Luminary is stopped, including + `lumenroom.db`, `lumenroom.db-wal`, `lumenroom.db-shm`. + +## Verifying a build + +```bash +cd +sha256sum Luminary-0.5.1-linux-x64.tar.gz +tar -tzf Luminary-0.5.1-linux-x64.tar.gz | grep -E 'luminary$|runtime/bin/node$|app/server/index.mjs$' +tar -xzf Luminary-0.5.1-linux-x64.tar.gz -C /tmp/luminary-check +/tmp/luminary-check/Luminary/luminary --verify +``` + +On a real desktop also check the window opens, the UI is signed in as the local +admin, importing a RAW file works, and `--stop` closes the server. + +## Limitations + +- The `.deb` is unsigned (no repository, no signing key), so `apt` installs it + locally without verification and there is no auto-update. Only the portable +tarball and the `.deb` are produced — no AppImage or Snap in this version — and + there is no tray icon. +- The app window depends on a Chromium-based browser being installed; without + one it falls back to Firefox or the default browser as a normal window. +- Wayland compositors may ignore `--class=Luminary`, so the dock icon can be the + browser's. +- Loopback only by default; set `HOST=0.0.0.0` when starting the server by hand + for LAN proofing galleries. +- The launcher cannot clean up after a server crash; a stale PID file is ignored + on the next start (`--status` reports "stopped"). diff --git a/linux/SMOKE-LINUX.sh b/linux/SMOKE-LINUX.sh new file mode 100755 index 0000000..32741ba --- /dev/null +++ b/linux/SMOKE-LINUX.sh @@ -0,0 +1,277 @@ +#!/usr/bin/env bash +# One-command smoke test for an extracted Luminary Linux bundle. +# +# Run it from the extracted bundle folder (or pass --bundle): +# +# ./SMOKE-LINUX.sh +# ./SMOKE-LINUX.sh --bundle /opt/luminary +# +# It writes smoke-report.txt next to the bundle and prints the same lines. +# Exit code 0 means every check passed. +# +# What it covers without a human clicking: +# - distro, architecture, glibc, display, and which browser the launcher picks +# - the bundle files the launcher needs, and `luminary --verify` +# - a real boot through the launcher in desktop mode: /api/health local:true, +# /api/auth/me 200 without a cookie, registration closed, /api/sync 200 +# - the menu entry install/uninstall writing and removing a real .desktop file +# - `luminary --stop` actually stopping the server +# +# It uses a throwaway data folder under $TMPDIR and a private XDG_DATA_HOME, so +# it never touches a real catalog or your applications menu. The app window is +# not opened (the launcher runs with LUMINARY_WINDOW=none); it is a visual check. + +set -u + +BUNDLE="" +while [ "$#" -gt 0 ]; do + case "$1" in + --bundle) + BUNDLE="${2:-}" + shift 2 + ;; + --help|-h) + sed -n '2,20p' "$0" | sed 's/^# \{0,1\}//' + exit 0 + ;; + *) + printf 'unknown option %s (see --help)\n' "$1" >&2 + exit 2 + ;; + esac +done +[ -n "$BUNDLE" ] || BUNDLE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +BUNDLE="$(readlink -f "$BUNDLE")" + +LINES=() +FAILED=0 +SKIPPED=0 + +say() { + LINES+=("$*") + printf '%s\n' "$*" +} + +check() { + local name="$1" ok="$2" detail="${3:-}" + if [ "$ok" = "0" ]; then + say " PASS $name${detail:+ — $detail}" + else + FAILED=$((FAILED + 1)) + say " FAIL $name${detail:+ — $detail}" + fi +} + +skip() { + SKIPPED=$((SKIPPED + 1)) + say " SKIP $1${2:+ — $2}" +} + +[ -x "$BUNDLE/runtime/bin/node" ] && NODE="$BUNDLE/runtime/bin/node" || NODE="$(command -v node 2>/dev/null || true)" +if [ -z "$NODE" ]; then + printf 'Luminary: no Node runtime found in the bundle or on PATH\n' >&2 + exit 1 +fi + +WORK_DIR="$(mktemp -d "${TMPDIR:-/tmp}/luminary-smoke.XXXXXX")" || exit 1 +export XDG_DATA_HOME="$WORK_DIR/xdg" +export LUMINARY_DATA="$WORK_DIR/data" +export LUMINARY_WINDOW=none +BODY="$WORK_DIR/body.json" +URL="" + +cleanup() { + if [ -x "$BUNDLE/luminary" ] && [ -f "$LUMINARY_DATA/luminary.pid" ]; then + "$BUNDLE/luminary" --stop >/dev/null 2>&1 || true + fi + rm -rf "$WORK_DIR" +} +trap cleanup EXIT + +# http [json-body] -> status code on stdout, body in $BODY +http() { + "$NODE" -e ' + const [method, url, payload, out] = process.argv.slice(-4); + const init = { method }; + if (payload) { + init.headers = { "Content-Type": "application/json" }; + init.body = payload; + } + fetch(url, init) + .then(async (r) => { require("node:fs").writeFileSync(out, await r.text()); process.stdout.write(String(r.status)); }) + .catch(() => process.stdout.write("0")); + ' "$1" "$2" "${3:-}" "$BODY" +} + +# jget -> value from the last response body +jget() { + "$NODE" -e ' + const fs = require("node:fs"); + let value; + try { value = JSON.parse(fs.readFileSync(process.argv.slice(-2)[0], "utf8")); } catch { process.exit(0); } + for (const key of process.argv.slice(-1)[0].split(".")) value = value == null ? value : value[key]; + if (value !== undefined && value !== null) process.stdout.write(String(value)); + ' "$BODY" "$1" +} + +browser_name() { + local name + for name in google-chrome google-chrome-stable chromium chromium-browser \ + microsoft-edge microsoft-edge-stable brave-browser vivaldi-stable firefox; do + if command -v "$name" >/dev/null 2>&1; then + printf '%s' "$name" + return 0 + fi + done + return 1 +} + +say 'Luminary Linux smoke test' +say " bundle $BUNDLE" +say " time $(date -Is)" + +say '' +say 'Environment' +if [ -r /etc/os-release ]; then + # shellcheck disable=SC1091 + distro="$(. /etc/os-release && printf '%s' "${PRETTY_NAME:-${NAME:-unknown}}")" +else + distro="$(uname -s)" +fi +say " distro $distro" +say " arch $(uname -m)" +say " kernel $(uname -r)" +say " glibc $(ldd --version 2>/dev/null | head -n 1 || printf 'unknown')" +say " display ${DISPLAY:-none}${WAYLAND_DISPLAY:+ (wayland $WAYLAND_DISPLAY)}" +if browser="$(browser_name)"; then + say " browser $browser" +else + say ' browser none found (the launcher would fall back to the default browser)' +fi + +say '' +say 'Bundle' +check 'luminary launcher present' $([ -x "$BUNDLE/luminary" ] && echo 0 || echo 1) +check 'runtime/bin/node present' $([ -x "$BUNDLE/runtime/bin/node" ] && echo 0 || echo 1) "$BUNDLE/runtime/bin/node" +check 'app/server/index.mjs present' $([ -f "$BUNDLE/app/server/index.mjs" ] && echo 0 || echo 1) +check 'app/dist/index.html present' $([ -f "$BUNDLE/app/dist/index.html" ] && echo 0 || echo 1) +check 'app/node_modules present' $([ -d "$BUNDLE/app/node_modules" ] && echo 0 || echo 1) +node_version="$("$NODE" --version 2>/dev/null)" +check 'node runs' $([ -n "$node_version" ] && echo 0 || echo 1) "$node_version" +check 'node is 24 or newer' "$("$NODE" -e 'process.exit(Number(process.versions.node.split(".")[0]) >= 24 ? 0 : 1)' 2>/dev/null; echo $?)" + +if [ -x "$BUNDLE/luminary" ]; then + if "$BUNDLE/luminary" --verify >"$WORK_DIR/verify.txt" 2>&1; then + check '--verify exits 0' 0 + else + check '--verify exits 0' 1 "$(tr '\n' ' ' <"$WORK_DIR/verify.txt")" + fi +else + check '--verify exits 0' 1 'launcher missing' +fi + +say '' +say 'Server (desktop mode, via the launcher)' +"$BUNDLE/luminary" >"$WORK_DIR/start.txt" 2>&1 +start_status=$? +check 'launcher start exits 0' "$start_status" "$(head -n 1 "$WORK_DIR/start.txt")" + +if [ -f "$LUMINARY_DATA/runtime.json" ]; then + check 'runtime.json written' 0 + URL="http://127.0.0.1:$("$NODE" -p "JSON.parse(require('fs').readFileSync('$LUMINARY_DATA/runtime.json','utf8')).port")" +else + check 'runtime.json written' 1 "$LUMINARY_DATA/runtime.json" +fi + +if [ -n "$URL" ]; then + code="$(http GET "$URL/api/health")" + check 'health answers' $([ "$code" = "200" ] && echo 0 || echo 1) "HTTP $code" + if [ "$code" = "200" ]; then + check 'local mode advertised' $([ "$(jget local)" = "true" ] && echo 0 || echo 1) "local=$(jget local)" + check 'version advertised' $([ -n "$(jget version)" ] && echo 0 || echo 1) "version=$(jget version)" + check 'no setup prompt' $([ "$(jget needsSetup)" = "false" ] && echo 0 || echo 1) + check 'registration closed' $([ "$(jget registrationOpen)" = "false" ] && echo 0 || echo 1) + check 'libraw ready' $([ "$(jget raw.libraw)" = "true" ] && echo 0 || echo 1) + check 'sharp ready' $([ "$(jget raw.sharp)" = "true" ] && echo 0 || echo 1) + fi + + code="$(http GET "$URL/api/auth/me")" + me_email="$(jget user.email)" + me_role="$(jget user.role)" + check 'signed in without a cookie' $([ "$code" = "200" ] && echo 0 || echo 1) "HTTP $code $me_email ($me_role)" + + code="$(http POST "$URL/api/auth/register" '{"email":"smoke@example.test","password":"smoke-test-password"}')" + check 'registration refused' $([ "$code" = "403" ] && echo 0 || echo 1) "HTTP $code" + + code="$(http GET "$URL/api/sync")" + check '/api/sync answers' $([ "$code" = "200" ] && echo 0 || echo 1) "HTTP $code" + + code="$(http GET "$URL/")" + check 'UI index served' $([ "$code" = "200" ] && echo 0 || echo 1) "HTTP $code" + if [ "$code" = "200" ] && grep -q 'src/assets\|assets/' "$BODY"; then + check 'UI references built assets' 0 + else + check 'UI references built assets' 1 + fi +fi + +if "$BUNDLE/luminary" --status 2>/dev/null | grep -q 'Status: running'; then + check '--status reports running' 0 +else + check '--status reports running' 1 +fi + +say '' +say 'Menu entry' +if XDG_DATA_HOME="$WORK_DIR/xdg" "$BUNDLE/luminary" --install >/dev/null 2>&1 && + [ -f "$WORK_DIR/xdg/applications/luminary.desktop" ]; then + check '--install writes a .desktop file' 0 + if grep -q "^Exec=\"\?$BUNDLE/luminary\"\?$" "$WORK_DIR/xdg/applications/luminary.desktop"; then + check 'menu entry points at this bundle' 0 + else + check 'menu entry points at this bundle' 1 "$(grep '^Exec=' "$WORK_DIR/xdg/applications/luminary.desktop")" + fi +else + check '--install writes a .desktop file' 1 +fi +if XDG_DATA_HOME="$WORK_DIR/xdg" "$BUNDLE/luminary" --uninstall >/dev/null 2>&1 && + [ ! -f "$WORK_DIR/xdg/applications/luminary.desktop" ]; then + check '--uninstall removes it' 0 +else + check '--uninstall removes it' 1 +fi + +say '' +say 'Stop' +"$BUNDLE/luminary" --stop >/dev/null 2>&1 +if [ -n "$URL" ]; then + code="$(http GET "$URL/api/health")" + check 'server stopped' $([ "$code" = "0" ] && echo 0 || echo 1) "HTTP $code" +else + check 'server stopped' 1 'server never started' +fi +if "$BUNDLE/luminary" --status 2>/dev/null | grep -q 'Status: stopped'; then + check '--status reports stopped' 0 +else + check '--status reports stopped' 1 +fi + +say '' +say 'Window' +skip 'app window opens' 'visual check; the launcher opened nothing during this run' + +say '' +if [ "$FAILED" -eq 0 ]; then + say 'RESULT: PASS' +else + say "RESULT: FAIL ($FAILED check(s))" +fi + +report="$BUNDLE/smoke-report.txt" +if ! { printf '%s\n' "${LINES[@]}" >"$report"; } 2>/dev/null; then + report="$(pwd)/smoke-report.txt" + printf '%s\n' "${LINES[@]}" >"$report" 2>/dev/null || true +fi +[ -f "$report" ] && say " report $report" + +[ "$FAILED" -eq 0 ] && exit 0 || exit 1 diff --git a/linux/build.mjs b/linux/build.mjs new file mode 100644 index 0000000..7937dbe --- /dev/null +++ b/linux/build.mjs @@ -0,0 +1,758 @@ +#!/usr/bin/env node +/** + * Build the optional Linux (Ubuntu) desktop bundle for Luminary. + * + * Like windows/build.mjs this is *outside* the main build: it only reads the + * repository (`dist/`, `server/`, `package.json`) and writes everything into a + * directory outside the checkout. Nothing in `src/`, `server/`, `package.json`, + * the Dockerfile, the deploy script or `dist/` is modified by this file, and no + * npm script is added for it. Run it directly: + * + * node linux/build.mjs # build dist/ then the bundle + * node linux/build.mjs --skip-build # reuse the existing dist/ + * node linux/build.mjs --out /srv/lum # choose the output directory + * + * The bundle keeps the layout the server expects (it derives `DIST_DIR` from + * the parent of `server/`), so it is a plain folder plus a launcher: + * + * /Luminary/ + * luminary bash launcher: start, health wait, app window + * install.sh adds Luminary to the Ubuntu applications menu + * Luminary.png icon + * runtime/bin/node official Node 24 linux-x64, SHA-256 checked + * app/ unchanged server/, dist/, production node_modules/ + * README-linux.txt + * version.txt + */ +import { createHash } from 'node:crypto'; +import { spawnSync } from 'node:child_process'; +import { + chmodSync, + cpSync, + existsSync, + lstatSync, + mkdirSync, + readFileSync, + readdirSync, + renameSync, + rmSync, + statSync, + symlinkSync, + writeFileSync, +} from 'node:fs'; +import os from 'node:os'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; + +const HERE = path.dirname(fileURLToPath(import.meta.url)); +const ROOT = path.resolve(HERE, '..'); +const LAUNCHER_FILES = path.join(HERE, 'launcher'); +const RELEASES_DIR = path.join(HERE, 'releases'); +const NPM = 'npm'; +const DEFAULT_NODE = 'v24.22.2'; + +const HELP = `Luminary Linux (Ubuntu) bundle + +Usage: node linux/build.mjs [options] + + --out output directory (default: /luminary-linux). + Must be outside this repository; the bundle is staged in + /stage and archived to + /Luminary--linux-x64.tar.gz. + --skip-build reuse the existing dist/ instead of running npm run build + --node bundled Node version, e.g. v24.22.2 (must be >= 24) + --allow-dirty skip the check that the checkout is clean outside linux/ + --publish copy the finished tar.gz and .deb to linux/releases (plus + a SHA256SUMS.txt) so they can be handed off or uploaded + --help print this text + +Nothing in the repository is modified: the only writes outside the output +directory are the ones npm and nodejs.org make for their own caches. +`; + +function fail(message) { + process.stderr.write(`linux: FAILED: ${message}\n`); + process.exit(1); +} + +function log(step, message) { + process.stdout.write(`linux: ${step.padEnd(9)} ${message}\n`); +} + +function warn(message) { + process.stderr.write(`linux: warning: ${message}\n`); +} + +function defaultOutDir() { + return path.join(process.env.XDG_CACHE_HOME || path.join(os.homedir(), '.cache'), 'luminary-linux'); +} + +function parseArgs(argv) { + const options = { + out: defaultOutDir(), + node: DEFAULT_NODE, + build: true, + allowDirty: false, + publish: false, + help: false, + }; + const value = (index, flag) => { + const next = argv[index + 1]; + if (!next || next.startsWith('--')) fail(`${flag} needs a value`); + return next; + }; + for (let i = 0; i < argv.length; i++) { + const arg = argv[i]; + if (arg === '--out') { + options.out = path.resolve(value(i, arg)); + i += 1; + } else if (arg === '--node') { + const version = value(i, arg); + options.node = version.startsWith('v') ? version : `v${version}`; + i += 1; + } else if (arg === '--skip-build') { + options.build = false; + } else if (arg === '--allow-dirty') { + options.allowDirty = true; + } else if (arg === '--publish') { + options.publish = true; + } else if (arg === '--help' || arg === '-h') { + options.help = true; + } else { + fail(`unknown option ${arg} (see --help)`); + } + } + if (!/^v\d+\.\d+\.\d+$/.test(options.node)) { + fail(`--node must look like v24.22.2 (got ${options.node})`); + } + return options; +} + +function git(args, { trim = true } = {}) { + const result = spawnSync('git', args, { cwd: ROOT, encoding: 'utf8' }); + if (result.error || result.status !== 0) return null; + return trim ? result.stdout.trim() : result.stdout; +} + +/** + * The bundle must not land in the checkout: a staged Node runtime and + * node_modules would otherwise be rsynced to production by scripts/deploy.mjs + * and grow the Docker build context. + */ +function assertOutsideRepo(outDir) { + const relative = path.relative(ROOT, outDir); + const inside = !relative.startsWith('..') && !path.isAbsolute(relative); + if (inside) { + fail( + `--out resolves inside the repository (${outDir}).\n` + + 'The bundle is large and would be copied by the deploy rsync; pick an\n' + + 'output directory outside the checkout, or omit --out to use the cache.', + ); + } +} + +/** + * Only this folder may be dirty. `logo.png` is a long-standing untracked asset + * in this checkout and is not part of the app, so it is tolerated. + */ +function checkRepoClean(options) { + const status = git(['status', '--porcelain'], { trim: false }); + if (status === null) { + warn('git is unavailable here; skipping the worktree check'); + return; + } + const unexpected = status + .split('\n') + .filter((line) => line.length > 3) + .map((line) => line.slice(3).replace(/^"|"$/g, '').replace(/^.* -> /, '').trim()) + .filter((file) => file && !file.startsWith('linux/') && file !== 'logo.png'); + if (!unexpected.length) return; + if (options.allowDirty) { + warn(`building from a modified checkout: ${unexpected.join(', ')}`); + return; + } + fail( + `the checkout has changes outside linux/:\n ${unexpected.join('\n ')}\n` + + 'Commit or stash them, or pass --allow-dirty to build anyway.', + ); +} + +function readPackage() { + const file = path.join(ROOT, 'package.json'); + if (!existsSync(file)) fail('run this from a Luminary checkout (package.json missing)'); + return JSON.parse(readFileSync(file, 'utf8')); +} + +function run(command, args, cwd, extraEnv) { + log('run', [command, ...args].join(' ')); + const result = spawnSync(command, args, { + cwd, + stdio: 'inherit', + env: extraEnv ? { ...process.env, ...extraEnv } : process.env, + }); + if (result.error) fail(`${command} could not start: ${result.error.message}`); + if (result.status !== 0) fail(`${command} ${args.join(' ')} exited with ${result.status}`); +} + +function ensureUi(options) { + const dist = path.join(ROOT, 'dist', 'index.html'); + if (options.build) { + log('ui', 'npm run build (typecheck + vite build, the normal artifact)'); + run(NPM, ['run', 'build'], ROOT); + } else { + log('ui', 'reusing the existing dist/ (--skip-build)'); + } + if (!existsSync(dist)) { + fail('dist/index.html is missing; drop --skip-build or run "npm run build" first'); + } + return dist; +} + +function copyServer(bundle) { + const server = path.join(bundle, 'app', 'server'); + cpSync(path.join(ROOT, 'server'), server, { + recursive: true, + filter: (source) => { + const relative = path.relative(path.join(ROOT, 'server'), source).split(path.sep).join('/'); + // The developer catalog and the test files never belong in a bundle. + if (relative === 'data' || relative.startsWith('data/')) return false; + if (/\.test\.mjs$/.test(relative)) return false; + return true; + }, + }); +} + +function copyLegal(bundle) { + for (const name of ['LICENSE', 'THIRD_PARTY_NOTICES.md']) { + const source = path.join(ROOT, name); + if (existsSync(source)) cpSync(source, path.join(bundle, name)); + } + const licenses = path.join(ROOT, 'licenses'); + if (existsSync(licenses)) cpSync(licenses, path.join(bundle, 'licenses'), { recursive: true }); +} + +function installLinuxDeps(bundle) { + const appDir = path.join(bundle, 'app'); + cpSync(path.join(ROOT, 'package.json'), path.join(appDir, 'package.json')); + cpSync(path.join(ROOT, 'package-lock.json'), path.join(appDir, 'package-lock.json')); + log('deps', 'npm ci --omit=dev --os=linux --cpu=x64 (sharp linux-x64 prebuild)'); + // --ignore-scripts is safe: sharp 0.35 has no install step, it resolves the + // prebuilt binary through optionalDependencies. + run( + NPM, + ['ci', '--omit=dev', '--os=linux', '--cpu=x64', '--no-audit', '--no-fund', '--ignore-scripts'], + appDir, + ); + // .bin shims are for an interactive shell, not for `node server/index.mjs`. + rmSync(path.join(appDir, 'node_modules', '.bin'), { recursive: true, force: true }); + verifySharp(appDir); +} + +function verifySharp(appDir) { + const dir = path.join(appDir, 'node_modules', '@img', 'sharp-linux-x64'); + if (!existsSync(dir)) { + warn('@img/sharp-linux-x64 is missing; the server will fall back to PNG proxies'); + return; + } + const binaries = []; + const walk = (current) => { + for (const entry of readdirSync(current, { withFileTypes: true })) { + const absolute = path.join(current, entry.name); + if (entry.isDirectory()) walk(absolute); + else if (/\.(node|so(\.\d+)*)$/i.test(entry.name)) binaries.push(path.relative(dir, absolute)); + } + }; + walk(dir); + if (!binaries.some((file) => file.endsWith('.node'))) { + warn('@img/sharp-linux-x64 has no .node binary; check the installed package'); + } else { + log('deps', `sharp linux-x64 ready (${binaries.length} native files)`); + } +} + +function sha256File(file) { + return createHash('sha256').update(readFileSync(file)).digest('hex'); +} + +async function download(url) { + const response = await fetch(url); + if (!response.ok) throw new Error(`${response.status} ${response.statusText} from ${url}`); + return Buffer.from(await response.arrayBuffer()); +} + +function extractTar(archive, destination) { + mkdirSync(destination, { recursive: true }); + const result = spawnSync( + 'tar', + ['-xzf', archive, '-C', destination, '--strip-components=1'], + { stdio: 'inherit' }, + ); + if (result.error || result.status !== 0) { + fail(`could not extract ${path.basename(archive)} (is tar installed?)`); + } +} + +async function ensureNode(outDir, version) { + const major = Number(version.slice(1).split('.')[0]); + if (major < 24) { + fail(`Node ${version} is too old: node:sqlite and type stripping need 24 LTS`); + } + const cache = path.join(outDir, 'cache'); + mkdirSync(cache, { recursive: true }); + const name = `node-${version}-linux-x64.tar.gz`; + const archive = path.join(cache, name); + const sums = path.join(cache, `SHASUMS256-${version}.txt`); + const base = `https://nodejs.org/dist/${version}`; + if (!existsSync(archive)) { + // Unlike the Windows node.exe, the Linux tarballs sit at the dist root. + log('node', `downloading ${base}/${name}`); + try { + writeFileSync(archive, await download(`${base}/${name}`)); + } catch (error) { + fail(`could not download ${name}: ${error.message}`); + } + } else { + log('node', `using cached ${name}`); + } + if (!existsSync(sums)) { + try { + writeFileSync(sums, (await download(`${base}/SHASUMS256.txt`)).toString('utf8')); + } catch (error) { + warn(`could not fetch SHASUMS256.txt (${error.message}); the cached tarball is unverified`); + } + } + const hash = sha256File(archive); + if (existsSync(sums)) { + const line = readFileSync(sums, 'utf8') + .split('\n') + .map((row) => row.trim().split(/\s+/)) + .find((row) => row[1] === name); + if (!line) fail(`SHASUMS256.txt for ${version} has no ${name} entry`); + if (hash !== line[0]) { + rmSync(archive, { force: true }); + fail(`${name} failed its SHA-256 check (${hash} != ${line[0]}); re-run to download again`); + } + log('node', `${version} linux-x64 verified (sha256 ${hash.slice(0, 12)}…)`); + } else { + warn(`using the Node tarball without a published checksum (sha256 ${hash})`); + } + return { archive, hash }; +} + +function installRuntime(bundle, archive) { + const runtime = path.join(bundle, 'runtime'); + rmSync(runtime, { recursive: true, force: true }); + log('runtime', 'extracting Node into runtime/ (bin/node, lib/node_modules)'); + extractTar(archive, runtime); + const nodeBin = path.join(runtime, 'bin', 'node'); + if (!existsSync(nodeBin)) fail('the Node tarball did not contain runtime/bin/node'); + chmodSync(nodeBin, 0o755); + const check = spawnSync(nodeBin, ['--version'], { encoding: 'utf8' }); + if (check.status !== 0) fail(`the bundled node binary does not run here: ${check.stderr || ''}`); + log('runtime', `bundled ${check.stdout.trim()} runs on this host`); + return nodeBin; +} + +function installLauncher(bundle) { + const launcher = path.join(bundle, 'luminary'); + cpSync(path.join(LAUNCHER_FILES, 'luminary'), launcher); + chmodSync(launcher, 0o755); + const installer = path.join(bundle, 'install.sh'); + cpSync(path.join(LAUNCHER_FILES, 'install.sh'), installer); + chmodSync(installer, 0o755); + // Ships with the bundle so the first-run check is one command, and travels + // into /opt/luminary in the .deb. + const smoke = path.join(HERE, 'SMOKE-LINUX.sh'); + if (existsSync(smoke)) { + cpSync(smoke, path.join(bundle, 'SMOKE-LINUX.sh')); + chmodSync(path.join(bundle, 'SMOKE-LINUX.sh'), 0o755); + } + log('launcher', 'luminary (app window + --stop/--status/--install), install.sh, SMOKE-LINUX.sh'); +} + +async function writeIcon(bundle) { + const logo = path.join(ROOT, 'logo.png'); + const target = path.join(bundle, 'Luminary.png'); + if (!existsSync(logo)) { + warn('logo.png is missing; the bundle has no menu icon'); + return; + } + try { + const { default: sharp } = await import('sharp'); + await sharp(logo).resize(256, 256, { fit: 'cover' }).png().toFile(target); + log('icon', `Luminary.png (${(statSync(target).size / 1024).toFixed(0)} KB)`); + } catch (error) { + cpSync(logo, target); + warn(`could not resize logo.png (${error.message}); copied it unchanged`); + } +} + +function writeVersion(bundle, pkg, nodeVersion, nodeHash, nodeSize) { + const commit = git(['rev-parse', '--short', 'HEAD']) ?? 'unknown'; + const lines = [ + `Luminary ${pkg.version}`, + `commit ${commit}`, + `built ${new Date().toISOString()}`, + `node ${nodeVersion} linux-x64 sha256 ${nodeHash} size ${nodeSize}`, + 'launcher luminary (bash)', + ]; + writeFileSync(path.join(bundle, 'version.txt'), `${lines.join('\n')}\n`); + return { version: pkg.version, commit }; +} + +function writeBundleReadme(bundle, info) { + const body = `Luminary ${info.version} for Linux (x64) — portable bundle +============================================== + +Start: ./luminary +Stop: ./luminary --stop +Menu: ./install.sh (adds Luminary to your applications menu) +Open tab: ./luminary --browser +Status: ./luminary --status +Data: ~/.local/share/luminary (originals, previews, SQLite catalog) +Logs: ~/.local/share/luminary/logs/server.out.log and server.err.log +Sign-in: none — single-user desktop mode, no account setup + +Requirements + - Ubuntu 22.04 or 24.04, 64-bit (any glibc distribution of similar age works). + - A Chromium-based browser for the app window: Chrome, Chromium, Edge, Brave + or Vivaldi. Firefox is used as a normal window, and the default browser is + the last resort. WebGL2 is needed for the Develop module. + - Nothing to install: Node.js is included in runtime/, and sharp's Linux + binaries are bundled. No root, no apt, no deb package. + - About 250 MB free where the data folder lives. + +Extract the tarball anywhere, then run ./luminary from the extracted folder. +Nothing is written into /usr or /opt, so moving or deleting the folder is safe; +the catalog lives in ~/.local/share/luminary and is not touched on removal. + +./install.sh adds a menu entry (~/.local/share/applications/luminary.desktop) +using this folder's absolute path, so install after you have put the folder +where you want to keep it. ./luminary --uninstall removes the entry again. + +Back up the catalog by copying ~/.local/share/luminary while Luminary is +stopped, including lumenroom.db, lumenroom.db-wal, lumenroom.db-shm and +secret.key. + +Updating: stop Luminary, replace app/ and runtime/ from a newer bundle, start +again. The data folder is outside the bundle and is untouched. + +Notes + - The server listens on 127.0.0.1 only. Set HOST=0.0.0.0 when starting it + directly with node if client proofing galleries must reach other devices. + - The app window is the browser's own app mode with a private profile, so it + has no tabs or address bar. Some Wayland desktops ignore the requested + window class; the window still opens. + - RAW decoding uses the bundled libraw WebAssembly, so no system codec + packages are needed. + - Photo libraries on NTFS/exFAT drives work, but SQLite is happiest on a + native Linux filesystem. +`; + writeFileSync(path.join(bundle, 'README-linux.txt'), body); +} + +/* ------------------------------------------------------------------ deb ---- */ + +function walkBytes(dir) { + let total = 0; + for (const entry of readdirSync(dir, { withFileTypes: true })) { + const absolute = path.join(dir, entry.name); + if (entry.isDirectory()) total += walkBytes(absolute); + else total += lstatSync(absolute).size; + } + return total; +} + +const DEB_MAINTAINER_SCRIPT = `#!/bin/sh +set -e + +# Refresh the menu and icon caches so Luminary appears without a logout. +if command -v update-desktop-database >/dev/null 2>&1; then + update-desktop-database -q /usr/share/applications || true +fi +if command -v gtk-update-icon-cache >/dev/null 2>&1; then + gtk-update-icon-cache -q -t -f /usr/share/icons/hicolor || true +fi + +exit 0 +`; + +function debControlFile(pkg, installedBytes) { + return [ + 'Package: luminary', + `Version: ${pkg.version}`, + 'Architecture: amd64', + 'Maintainer: Brian Hursey ', + `Installed-Size: ${Math.ceil(installedBytes / 1024)}`, + 'Depends: libc6, libstdc++6, libgomp1', + 'Recommends: chromium | google-chrome-stable | microsoft-edge-stable | firefox', + 'Section: graphics', + 'Priority: optional', + 'Homepage: https://git.maple-street.net/bhursey/luminary', + 'Description: photo library and raw editor', + ' Luminary catalogs photos, develops camera raw files and serves client', + ' proofing galleries. This package bundles the Node runtime and the server,', + ' so it installs with no other dependencies. Photos and the catalog live in', + ' ~/.local/share/luminary and are kept when the package is removed.', + '', + ].join('\n'); +} + +function debDesktopEntry() { + return [ + '[Desktop Entry]', + 'Type=Application', + 'Version=1.0', + 'Name=Luminary', + 'GenericName=Photo library', + 'Comment=Photo library and raw editor', + 'Exec=/usr/bin/luminary', + 'Path=/opt/luminary', + 'Icon=luminary', + 'Terminal=false', + 'Categories=Graphics;Photography;', + 'Keywords=photo;raw;catalog;editor;', + 'StartupNotify=true', + 'StartupWMClass=Luminary', + '', + ].join('\n'); +} + +function debCopyright() { + return [ + 'Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/', + 'Upstream-Name: Luminary', + 'Source: https://git.maple-street.net/bhursey/luminary', + '', + 'Files: *', + 'Copyright: 2026 Brian Hursey', + 'License: MIT', + ' The full MIT licence text is in /opt/luminary/LICENSE.', + '', + ].join('\n'); +} + +/** + * Builds the opt-in Ubuntu package from the same staged bundle. Installed as + * /opt/luminary so the bundle layout (and therefore the launcher's bundle + * detection) is unchanged; the data folder stays in the user's home. + */ +function buildDeb(outDir, pkg, bundle) { + const probe = spawnSync('dpkg-deb', ['--version'], { encoding: 'utf8' }); + if (probe.error || probe.status !== 0) { + warn('dpkg-deb is not installed; skipping the .deb (install the dpkg package)'); + return null; + } + + const work = path.join(outDir, 'deb.next'); + rmSync(work, { recursive: true, force: true }); + const root = path.join(work, 'root'); + + log('deb', 'staging /opt/luminary, /usr/bin/luminary and the menu entry'); + const appTarget = path.join(root, 'opt', 'luminary'); + mkdirSync(path.dirname(appTarget), { recursive: true }); + cpSync(bundle, appTarget, { recursive: true }); + + const binDir = path.join(root, 'usr', 'bin'); + mkdirSync(binDir, { recursive: true }); + // Relative link so the package works whatever the prefix. + symlinkSync('../opt/luminary/luminary', path.join(binDir, 'luminary')); + + const appsDir = path.join(root, 'usr', 'share', 'applications'); + mkdirSync(appsDir, { recursive: true }); + writeFileSync(path.join(appsDir, 'luminary.desktop'), debDesktopEntry()); + + const icon = path.join(bundle, 'Luminary.png'); + const iconDir = path.join(root, 'usr', 'share', 'icons', 'hicolor', '256x256', 'apps'); + mkdirSync(iconDir, { recursive: true }); + if (existsSync(icon)) cpSync(icon, path.join(iconDir, 'luminary.png')); + else warn('the bundle has no Luminary.png; the menu entry will use a generic icon'); + + const docDir = path.join(root, 'usr', 'share', 'doc', 'luminary'); + mkdirSync(docDir, { recursive: true }); + cpSync(path.join(bundle, 'README-linux.txt'), path.join(docDir, 'README-linux.txt')); + writeFileSync(path.join(docDir, 'copyright'), debCopyright()); + + const installedBytes = walkBytes(root); + const controlDir = path.join(root, 'DEBIAN'); + mkdirSync(controlDir, { recursive: true }); + writeFileSync(path.join(controlDir, 'control'), debControlFile(pkg, installedBytes)); + for (const name of ['postinst', 'postrm']) { + const file = path.join(controlDir, name); + writeFileSync(file, DEB_MAINTAINER_SCRIPT); + chmodSync(file, 0o755); + } + + const debPath = path.join(outDir, `Luminary-${pkg.version}-linux-amd64.deb`); + rmSync(debPath, { force: true }); + const result = spawnSync( + 'dpkg-deb', + ['--root-owner-group', '-Zxz', '--build', root, debPath], + { stdio: 'inherit' }, + ); + if (result.error || result.status !== 0) fail('dpkg-deb could not build the package'); + + const listed = spawnSync('dpkg-deb', ['--contents', debPath], { encoding: 'utf8' }); + if (listed.status !== 0) fail('the .deb could not be read back'); + for (const required of [ + 'opt/luminary/luminary', + 'opt/luminary/runtime/bin/node', + 'usr/bin/luminary', + 'usr/share/applications/luminary.desktop', + ]) { + if (!listed.stdout.includes(required)) fail(`the .deb is missing ${required}`); + } + + log('deb', `${path.basename(debPath)} (${(statSync(debPath).size / 1024 / 1024).toFixed(1)} MB)`); + rmSync(work, { recursive: true, force: true }); + return debPath; +} + +/* ------------------------------------------------------------------ tar ---- */ + +function createArchive(workRoot, tarPath) { + rmSync(tarPath, { force: true }); + const deterministic = [ + '--sort=name', + '--owner=0', + '--group=0', + '--numeric-owner', + '--mtime=@1577836800', + '-czf', + tarPath, + '-C', + workRoot, + 'Luminary', + ]; + let result = spawnSync('tar', deterministic, { stdio: 'inherit' }); + if (result.error || result.status !== 0) { + warn('this tar has no --sort/--owner support; writing a plain archive instead'); + result = spawnSync('tar', ['-czf', tarPath, '-C', workRoot, 'Luminary'], { stdio: 'inherit' }); + } + if (result.error || result.status !== 0) fail('tar could not create the archive'); + const list = spawnSync('tar', ['-tzf', tarPath], { encoding: 'utf8' }); + if (list.status !== 0) fail('the archive could not be read back'); + const entries = list.stdout.split('\n').filter(Boolean); + for (const required of [ + 'Luminary/luminary', + 'Luminary/runtime/bin/node', + 'Luminary/app/server/index.mjs', + 'Luminary/app/dist/index.html', + ]) { + if (!entries.includes(required)) fail(`the archive is missing ${required}`); + } + return { files: entries.length, bytes: statSync(tarPath).size }; +} + +/* ----------------------------------------------------------------- main ---- */ + +async function main() { + const options = parseArgs(process.argv.slice(2)); + if (options.help) { + process.stdout.write(HELP); + return 0; + } + assertOutsideRepo(options.out); + const pkg = readPackage(); + log('repo', `${pkg.name} ${pkg.version} at ${ROOT}`); + log('out', options.out); + checkRepoClean(options); + ensureUi(options); + + // Build into a sibling and swap at the end, so a failed run never replaces + // the last complete bundle with a partial tree. + const stageRoot = path.join(options.out, 'stage'); + const workRoot = path.join(options.out, 'stage.next'); + const bundle = path.join(workRoot, 'Luminary'); + rmSync(workRoot, { recursive: true, force: true }); + mkdirSync(path.join(bundle, 'app'), { recursive: true }); + + log('stage', 'copying dist/ and server/ (unchanged layout the server expects)'); + cpSync(path.join(ROOT, 'dist'), path.join(bundle, 'app', 'dist'), { recursive: true }); + copyServer(bundle); + copyLegal(bundle); + installLinuxDeps(bundle); + + const node = await ensureNode(options.out, options.node); + const nodeBin = installRuntime(bundle, node.archive); + // Remember the size now: the bundle is renamed into stage/ before the summary. + const nodeBinSize = statSync(nodeBin).size; + + installLauncher(bundle); + await writeIcon(bundle); + + const info = writeVersion( + bundle, + pkg, + options.node, + node.hash, + statSync(node.archive).size, + ); + writeBundleReadme(bundle, info); + + const tarPath = path.join(options.out, `Luminary-${pkg.version}-linux-x64.tar.gz`); + log('tar', path.basename(tarPath)); + const archive = createArchive(workRoot, tarPath); + + // The .deb is built from the same staged bundle, before it is moved into + // stage/, so both artifacts are guaranteed to come from one build. + const debPath = buildDeb(options.out, pkg, bundle); + + rmSync(stageRoot, { recursive: true, force: true }); + renameSync(workRoot, stageRoot); + + // The isolation contract: nothing outside linux/ may have changed. + if (!options.allowDirty) checkRepoClean(options); + const stagedBundle = path.join(stageRoot, 'Luminary'); + + // Hand-off copy. Staging and the archives stay outside the checkout; this is + // the one write into the repository, into linux/releases. + const published = []; + if (options.publish) { + mkdirSync(RELEASES_DIR, { recursive: true }); + const sums = []; + for (const artifact of [tarPath, ...(debPath ? [debPath] : [])]) { + const target = path.join(RELEASES_DIR, path.basename(artifact)); + cpSync(artifact, target); + sums.push(`${sha256File(target)} ${path.basename(target)}`); + log('publish', path.relative(ROOT, target)); + published.push(target); + } + writeFileSync(path.join(RELEASES_DIR, 'SHA256SUMS.txt'), `${sums.join('\n')}\n`); + } + + process.stdout.write( + [ + '', + 'linux build PASSED', + ` artifact ${tarPath}`, + ` size ${(archive.bytes / 1024 / 1024).toFixed(1)} MB (${archive.files} entries)`, + ` sha256 ${sha256File(tarPath)}`, + ` node ${options.node} linux-x64 (${(nodeBinSize / 1024 / 1024).toFixed(0)} MB binary)`, + ` launcher luminary (bash)`, + ...(debPath + ? [ + ` deb ${debPath}`, + ` deb size ${(statSync(debPath).size / 1024 / 1024).toFixed(1)} MB`, + ] + : []), + ` staged ${stagedBundle}`, + ...published.map((file) => ` publish ${path.relative(ROOT, file)}`), + '', + published.length + ? 'Only linux/ was written: the archives in linux/releases are ready to transfer.' + : 'The repository was not modified; only linux/ and the output directory were touched.', + '', + ].join('\n'), + ); + return 0; +} + +main().then( + (code) => { + process.exitCode = code; + }, + (error) => { + fail(error instanceof Error ? error.message : String(error)); + }, +); diff --git a/linux/launcher/install.sh b/linux/launcher/install.sh new file mode 100755 index 0000000..79d4f11 --- /dev/null +++ b/linux/launcher/install.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +# Add this Luminary bundle to the Ubuntu applications menu. +# +# Creates ~/.local/share/applications/luminary.desktop pointing at this folder, +# so keep the folder where it is (or re-run this after moving it). Photos and the +# catalog stay in ~/.local/share/luminary and are never touched by the menu entry. +set -euo pipefail + +here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +exec "$here/luminary" --install diff --git a/linux/launcher/luminary b/linux/launcher/luminary new file mode 100755 index 0000000..57b3607 --- /dev/null +++ b/linux/launcher/luminary @@ -0,0 +1,357 @@ +#!/usr/bin/env bash +# Luminary desktop launcher for Linux. +# +# Starts the bundled server in single-user desktop mode on a free loopback port, +# waits for /api/health, then opens the UI in a chromeless app window (Chrome, +# Chromium, Edge, Brave or Vivaldi). Firefox, or the default browser, is the +# fallback. +# +# ./luminary start and open the window +# ./luminary --stop stop the running server +# ./luminary --status report pid, URL, data folder and health +# ./luminary --browser open a normal browser tab instead +# ./luminary --verify check that this is a complete bundle +# ./luminary --install add Luminary to the applications menu +# ./luminary --uninstall remove that menu entry +# +# Everything the app writes lives in ~/.local/share/luminary (or $LUMINARY_DATA), +# never inside this folder, so the bundle can be moved or deleted safely. + +set -u + +SELF="$(readlink -f "${BASH_SOURCE[0]}")" +BUNDLE="$(dirname "$SELF")" +APP="$BUNDLE/app" +DATA_DIR="${LUMINARY_DATA:-${XDG_DATA_HOME:-$HOME/.local/share}/luminary}" +LOG_DIR="$DATA_DIR/logs" +PID_FILE="$DATA_DIR/luminary.pid" +RUNTIME_FILE="$DATA_DIR/runtime.json" +FIRST_PORT=8787 +LAST_PORT=8887 +WINDOW_MODE="${LUMINARY_WINDOW:-window}" + +say() { printf '%s\n' "$*"; } +problem() { printf 'Luminary: %s\n' "$*" >&2; } + +usage() { + sed -n '2,18p' "$SELF" | sed 's/^# \{0,1\}//' +} + +find_node() { + if [ -x "$BUNDLE/runtime/bin/node" ]; then + NODE="$BUNDLE/runtime/bin/node" + return 0 + fi + if command -v node >/dev/null 2>&1; then + NODE="$(command -v node)" + return 0 + fi + problem "No Node runtime found: runtime/bin/node is missing and there is no node on PATH." + problem "Download this bundle again, or install Node 24 (https://nodejs.org)." + return 1 +} + +node_is_recent() { + "$NODE" -e 'process.exit(Number(process.versions.node.split(".")[0]) >= 24 ? 0 : 1)' 2>/dev/null +} + +port_free() { + ! (exec 3<>"/dev/tcp/127.0.0.1/$1") 2>/dev/null +} + +choose_port() { + local port="$FIRST_PORT" + while [ "$port" -le "$LAST_PORT" ]; do + if port_free "$port"; then + printf '%s' "$port" + return 0 + fi + port=$((port + 1)) + done + return 1 +} + +running_pid() { + [ -f "$PID_FILE" ] || return 1 + local pid + pid="$(cat "$PID_FILE" 2>/dev/null)" + [ -n "$pid" ] || return 1 + kill -0 "$pid" 2>/dev/null || return 1 + printf '%s' "$pid" +} + +current_port() { + [ -f "$RUNTIME_FILE" ] || return 1 + sed -n 's/.*"port": *\([0-9][0-9]*\).*/\1/p' "$RUNTIME_FILE" | head -n 1 +} + +wait_health() { + local url="http://127.0.0.1:$1/api/health" tries=0 + while [ "$tries" -lt 150 ]; do + if "$NODE" -e "fetch('$url').then(r => process.exit(r.ok ? 0 : 1)).catch(() => process.exit(1))" >/dev/null 2>&1; then + return 0 + fi + tries=$((tries + 1)) + sleep 0.2 + done + return 1 +} + +verify_bundle() { + local missing=0 + for rel in runtime/bin/node app/server/index.mjs app/dist/index.html luminary; do + if [ ! -e "$BUNDLE/$rel" ]; then + problem "missing: $rel" + missing=1 + fi + done + if [ -d "$APP/node_modules" ]; then + say "node_modules: present" + else + problem "missing: app/node_modules (production dependencies)" + missing=1 + fi + if [ "$missing" -ne 0 ]; then + problem "This folder is not a complete Luminary bundle; extract the whole tarball." + return 1 + fi + say "Bundle: $BUNDLE" + say "Version: $(sed -n '1p' "$BUNDLE/version.txt" 2>/dev/null)" + if find_node; then + say "Node: $("$NODE" --version 2>/dev/null) ($NODE)" + fi + return 0 +} + +start() { + local pid port + pid="$(running_pid)" && { + port="$(current_port)" + if [ -n "${port:-}" ]; then + say "Luminary is already running at http://127.0.0.1:$port (pid $pid)." + open_window "http://127.0.0.1:$port" + return 0 + fi + say "Luminary is already running (pid $pid)." + return 0 + } + + verify_bundle >/dev/null || return 1 + find_node || return 1 + if ! node_is_recent; then + problem "Node $("$NODE" --version 2>/dev/null) is too old; Luminary needs Node 24 or newer." + return 1 + fi + + mkdir -p "$DATA_DIR" "$LOG_DIR" || { + problem "could not create $DATA_DIR" + return 1 + } + chmod 700 "$DATA_DIR" 2>/dev/null || true + + port="$(choose_port)" || { + problem "no free loopback port between $FIRST_PORT and $LAST_PORT" + return 1 + } + + ( + cd "$APP" || exit 1 + LUMINARY_LOCAL=1 \ + PORT="$port" \ + HOST=127.0.0.1 \ + NODE_ENV=production \ + LUMINARY_DATA="$DATA_DIR" \ + nohup "$NODE" server/index.mjs >>"$LOG_DIR/server.out.log" 2>>"$LOG_DIR/server.err.log" & + printf '%s\n' "$!" >"$PID_FILE" + ) + + pid="$(cat "$PID_FILE" 2>/dev/null)" + if ! wait_health "$port"; then + problem "the server did not answer on /api/health." + problem "See $LOG_DIR/server.err.log, or run: cd \"$APP\" && \"$NODE\" server/index.mjs" + return 1 + fi + + printf '{"pid": %s, "port": %s, "url": "http://127.0.0.1:%s", "data": "%s"}\n' \ + "$pid" "$port" "$port" "$DATA_DIR" >"$RUNTIME_FILE" + + say "Luminary is running at http://127.0.0.1:$port (pid $pid)" + say "Data: $DATA_DIR" + if [ "$WINDOW_MODE" = "browser" ]; then + open_tab "http://127.0.0.1:$port" + elif [ "$WINDOW_MODE" = "none" ]; then + # Used by SMOKE-LINUX.sh: start the server but do not open anything. + : + else + open_window "http://127.0.0.1:$port" || open_tab "http://127.0.0.1:$port" + fi + return 0 +} + +stop() { + local pid + if ! pid="$(running_pid)"; then + rm -f "$PID_FILE" "$RUNTIME_FILE" + say "Luminary is not running." + return 0 + fi + kill "$pid" 2>/dev/null + local tries=0 + while kill -0 "$pid" 2>/dev/null && [ "$tries" -lt 50 ]; do + tries=$((tries + 1)) + sleep 0.1 + done + if kill -0 "$pid" 2>/dev/null; then + kill -9 "$pid" 2>/dev/null + fi + rm -f "$PID_FILE" "$RUNTIME_FILE" + say "Stopped Luminary (pid $pid)." +} + +status() { + local pid port + say "Bundle: $BUNDLE" + say "Data: $DATA_DIR" + if pid="$(running_pid)"; then + port="$(current_port)" + say "Status: running (pid $pid)" + if [ -n "${port:-}" ]; then + say "URL: http://127.0.0.1:$port" + find_node >/dev/null 2>&1 && + "$NODE" -e "fetch('http://127.0.0.1:$port/api/health').then(r => process.exit(r.ok ? 0 : 1)).catch(() => process.exit(1))" >/dev/null 2>&1 && + say "Health: ok" || say "Health: unreachable" + fi + else + say "Status: stopped" + fi + say "Logs: $LOG_DIR" +} + +browser_candidates() { + printf '%s\n' google-chrome google-chrome-stable chromium chromium-browser \ + microsoft-edge microsoft-edge-stable brave-browser vivaldi-stable +} + +open_window() { + local url="$1" name browser + while IFS= read -r name; do + if browser="$(command -v "$name" 2>/dev/null)"; then + say "Opening the app window with $name" + setsid "$browser" \ + --app="$url" \ + --user-data-dir="$DATA_DIR/window-profile" \ + --class=Luminary \ + --no-first-run \ + --no-default-browser-check \ + >/dev/null 2>&1 & + return 0 + fi + done </dev/null 2>&1; then + say "No Chromium-based browser found; opening Firefox." + setsid firefox --new-window "$url" >/dev/null 2>&1 & + return 0 + fi + return 1 +} + +open_tab() { + local url="$1" + if command -v xdg-open >/dev/null 2>&1; then + setsid xdg-open "$url" >/dev/null 2>&1 & + say "Opening $url in your browser." + return 0 + fi + say "Open $url in your browser." + return 0 +} + +desktop_dir() { + printf '%s' "${XDG_DATA_HOME:-$HOME/.local/share}/applications" +} + +icon_dir() { + printf '%s' "${XDG_DATA_HOME:-$HOME/.local/share}/icons/hicolor/256x256/apps" +} + +install_menu_entry() { + local apps icons entry + apps="$(desktop_dir)" + icons="$(icon_dir)" + mkdir -p "$apps" "$icons" || { + problem "could not create $apps" + return 1 + } + if [ -f "$BUNDLE/Luminary.png" ]; then + cp "$BUNDLE/Luminary.png" "$icons/luminary.png" + fi + entry="$apps/luminary.desktop" + cat >"$entry" </dev/null 2>&1; then + update-desktop-database "$apps" >/dev/null 2>&1 || true + fi + say "Added Luminary to your applications menu: $entry" + say "If it does not appear yet, log out and back in." +} + +uninstall_menu_entry() { + local entry + entry="$(desktop_dir)/luminary.desktop" + rm -f "$entry" + rm -f "$(icon_dir)/luminary.png" + if command -v update-desktop-database >/dev/null 2>&1; then + update-desktop-database "$(desktop_dir)" >/dev/null 2>&1 || true + fi + say "Removed the menu entry. Your photos and catalog in $DATA_DIR were kept." +} + +case "${1:-}" in + ""|--start) + start + ;; + --stop) + stop + ;; + --status) + status + ;; + --browser) + WINDOW_MODE=browser + start + ;; + --verify) + verify_bundle + ;; + --install) + install_menu_entry + ;; + --uninstall) + uninstall_menu_entry + ;; + --help|-h) + usage + ;; + *) + problem "unknown option $1" + usage >&2 + exit 2 + ;; +esac diff --git a/linux/releases/.gitignore b/linux/releases/.gitignore new file mode 100644 index 0000000..83c67d4 --- /dev/null +++ b/linux/releases/.gitignore @@ -0,0 +1,3 @@ +# Transfer-only release archives: keep the checksums reviewable, not the tarballs. +*.tar.gz +*.deb diff --git a/linux/releases/README.md b/linux/releases/README.md new file mode 100644 index 0000000..fba50e5 --- /dev/null +++ b/linux/releases/README.md @@ -0,0 +1,29 @@ +# Linux release hand-off + +`node linux/build.mjs --skip-build --publish` drops the finished artifacts here: + +``` +Luminary-0.5.1-linux-x64.tar.gz portable bundle +Luminary-0.5.1-linux-amd64.deb Ubuntu package +SHA256SUMS.txt +``` + +The archives are git-ignored; only `SHA256SUMS.txt` and this note are tracked, +so the checksums stay reviewable while the multi-hundred-megabyte archives do +not end up in the repository (or in the deploy rsync). + +Verify a copy with: + +```bash +sha256sum -c SHA256SUMS.txt +tar -tzf Luminary-0.5.1-linux-x64.tar.gz | head +dpkg-deb --info Luminary-0.5.1-linux-amd64.deb +``` + +On Ubuntu the easiest install is `sudo apt install ./Luminary-0.5.1-linux-amd64.deb`, +which adds Luminary to the applications menu. The portable route is to extract +the whole tarball and run `./luminary` from the extracted `Luminary` folder; +`./install.sh` adds that copy to the applications menu. + +After publishing, the product site needs the new `.deb` copied to +`luminary-site/downloads/` with the size and SHA-256 in its download card. diff --git a/linux/releases/SHA256SUMS.txt b/linux/releases/SHA256SUMS.txt new file mode 100644 index 0000000..a41b141 --- /dev/null +++ b/linux/releases/SHA256SUMS.txt @@ -0,0 +1,2 @@ +7b2f91d603b49aa19734e681278a16f8024018c618b1c342d2607c75a2e6722f Luminary-0.5.1-linux-x64.tar.gz +5649939b748946409a99d6e8e99a4d5a5613f7602458b23d9af23ef9b7f65d04 Luminary-0.5.1-linux-amd64.deb