Compare commits
3
Commits
4fe64ee110
...
5e923b9c30
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5e923b9c30 | ||
|
|
399628bf16 | ||
|
|
5e60973ebf |
@@ -11,5 +11,6 @@
|
||||
- [2026-11-16] **Settings (#10):** browser setup consumes private setup-token; cookies are bound to the password hash, and sign-out-all atomically rotates the persisted secret. Browser auth mutations serialize and close active WebSockets.
|
||||
- [2026-11-16] **Notebook management (#9):** a shared mutation queue serializes saves/create/move/duplicate/delete. Exclusive hard-link publication prevents target replacement; saves use temp+rename. The recursive watcher updates lists; deleted open drafts are retained. Frontmatter helpers use YAML document nodes.
|
||||
- [2026-11-16] **Host credentials (#7):** write-only AES-256-GCM files under dataDir, host-name AAD; shared SSH connect selects per-host password/key. ssh2 1.17.0 has no client user-certificate pairing API. Hosts plugin owns management routes and preserves inventory comments/version checks.
|
||||
- [2026-11-16] **Deploy/update:** host one-liner `bootstrap.sh` (temp dir, nothing left on host); `install.sh` is install-or-update; root-owned `shellbook-update` fetches the installer over HTTPS because root must never run code from the service-user-writable `/opt/shellbook`.
|
||||
|
||||
## Archive
|
||||
|
||||
@@ -14,5 +14,6 @@
|
||||
- [2026-11-16] **Path conventions:** web/API notebook paths are relative to `notebooks/`; chat protocol paths are workspace-relative (`notebooks/...`). Convert at the ChatPanel boundary.
|
||||
- [2026-11-16] **Watcher timing tests:** full parallel test run on Windows delays fs events >100 ms; keep watcher test debounce/quiet windows generous.
|
||||
- [2026-11-16] **HTTP errors:** server httpError messages (4xx/502/503) are user-facing and shown by the web client; 500 messages are not. Keep 4xx/502 messages free of secrets.
|
||||
- [2026-11-16] **CJS named imports in the bundle:** `import { utils } from "ssh2"` passes Vitest but crashes `node dist/main.js`; import CommonJS packages via default export. `test/bundle.test.ts` starts the real bundle.
|
||||
|
||||
## Archive
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
## Current Focus
|
||||
- [2026-11-16] M0–M3 (#1–#4) and the UI-first follow-ups (#7 hosts/credentials, #8 chat, #9 notebook management, #10 settings/setup) closed.
|
||||
- [2026-11-16] Open: #5/#6 need a real CT 501 deploy (update.sh, setup token, real SSH run, tmux terminal). Not yet verified in a real browser or against real OpenSSH.
|
||||
- [2026-11-16] Open: #5/#6 need a real CT 501 deploy (bootstrap.sh one-liner, setup token, real SSH run, tmux terminal). Not yet verified in a real browser or against real OpenSSH.
|
||||
|
||||
## Invariants
|
||||
- Displayed script == executed script (one substitution path).
|
||||
@@ -15,7 +15,7 @@
|
||||
- Everything doable from the web UI; files are storage, not the only way in.
|
||||
|
||||
## Table of Contents
|
||||
- `architecture.md` — 8 entries — why custom app, stack, AI integration, workspace split
|
||||
- `architecture.md` — 12 entries — why custom app, stack, AI integration, workspace split, deploy/update
|
||||
- `attempts.md` — 4 entries — marimo + marimo-pair trial and why it was dropped
|
||||
- `open.md` — 2 entries — open design questions (sudo password, chat history)
|
||||
- `gotchas.md` — 11 entries — integration foot-guns (CRLF, host-key events, tmux/systemd, env names, pct exec PATH, TUN, chat paths, watcher timing)
|
||||
- `gotchas.md` — 12 entries — integration foot-guns (CRLF, host-key events, tmux/systemd, env names, pct exec PATH, TUN, chat paths, watcher timing)
|
||||
|
||||
@@ -6,3 +6,4 @@ coverage/
|
||||
.env.*
|
||||
# runtime data when running from the repo
|
||||
data/
|
||||
apps/server/.bundle-test-*/
|
||||
|
||||
@@ -14,7 +14,9 @@ import {
|
||||
realpath,
|
||||
} from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { utils } from "ssh2";
|
||||
// ssh2 is CommonJS: Node's ESM loader cannot see `utils` as a named export (see test/bundle.test.ts).
|
||||
import ssh2 from "ssh2";
|
||||
const { utils } = ssh2;
|
||||
import type {
|
||||
HostCredentialInput,
|
||||
HostCredentialMetadata,
|
||||
|
||||
@@ -2,7 +2,9 @@ import { readFile, writeFile, rename, rm } from "node:fs/promises";
|
||||
import { randomUUID } from "node:crypto";
|
||||
import path from "node:path";
|
||||
import { parseDocument, isSeq, isMap } from "yaml";
|
||||
import { utils } from "ssh2";
|
||||
// ssh2 is CommonJS: Node's ESM loader cannot see `utils` as a named export (see test/bundle.test.ts).
|
||||
import ssh2 from "ssh2";
|
||||
const { utils } = ssh2;
|
||||
import {
|
||||
shellQuote,
|
||||
type HostActionRequest,
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
import { execFile, spawn } from "node:child_process";
|
||||
import { mkdtemp, readFile, rm } from "node:fs/promises";
|
||||
import { createServer } from "node:net";
|
||||
import { tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
import { promisify } from "node:util";
|
||||
import { expect, it } from "vitest";
|
||||
|
||||
// Vitest resolves CommonJS packages differently than Node's ESM loader, so only the
|
||||
// real production bundle shows whether externals like ssh2 import correctly.
|
||||
const serverDir = path.resolve(__dirname, "..");
|
||||
|
||||
async function freePort() {
|
||||
const probe = createServer();
|
||||
await new Promise<void>(resolve => probe.listen(0, "127.0.0.1", resolve));
|
||||
const { port } = probe.address() as { port: number };
|
||||
await new Promise(resolve => probe.close(resolve));
|
||||
return port;
|
||||
}
|
||||
|
||||
it("starts the production bundle with Node and answers the health check", async () => {
|
||||
const outdir = await mkdtemp(path.join(serverDir, ".bundle-test-"));
|
||||
const work = await mkdtemp(path.join(tmpdir(), "shellbook-bundle-"));
|
||||
try {
|
||||
const { scripts } = JSON.parse(await readFile(path.join(serverDir, "package.json"), "utf8")) as { scripts: { build: string } };
|
||||
const args = scripts.build.split(" ").slice(1).map(arg => arg.startsWith("--outdir=") ? `--outdir=${outdir}` : arg);
|
||||
await promisify(execFile)(path.join(serverDir, "node_modules", ".bin", "esbuild"), args, { cwd: serverDir, shell: process.platform === "win32" });
|
||||
const port = await freePort();
|
||||
const child = spawn(process.execPath, [path.join(outdir, "main.js")], {
|
||||
cwd: serverDir,
|
||||
env: { ...process.env, SHELLBOOK_HOST: "127.0.0.1", SHELLBOOK_PORT: String(port), SHELLBOOK_WORKSPACE: path.join(work, "workspace"), SHELLBOOK_DATA_DIR: path.join(work, "data"), SHELLBOOK_SSH_KEY: path.join(work, "data", "id_ed25519") },
|
||||
stdio: ["ignore", "ignore", "pipe"],
|
||||
});
|
||||
let stderr = "";
|
||||
child.stderr.on("data", chunk => { stderr += chunk; });
|
||||
const exited = new Promise<number | null>(resolve => child.on("exit", resolve));
|
||||
try {
|
||||
const healthy = await Promise.race([
|
||||
(async () => {
|
||||
for (let attempt = 0; attempt < 100; attempt++) {
|
||||
try { if ((await fetch(`http://127.0.0.1:${port}/api/health`)).ok) return true; } catch { /* not listening yet */ }
|
||||
await new Promise(r => setTimeout(r, 100));
|
||||
}
|
||||
return false;
|
||||
})(),
|
||||
exited.then(code => { throw new Error(`Server exited with ${code}: ${stderr}`); }),
|
||||
]);
|
||||
expect(healthy).toBe(true);
|
||||
} finally {
|
||||
child.kill();
|
||||
await exited;
|
||||
}
|
||||
} finally {
|
||||
await rm(outdir, { recursive: true, force: true });
|
||||
await rm(work, { recursive: true, force: true });
|
||||
}
|
||||
}, 60_000);
|
||||
+26
-11
@@ -4,8 +4,15 @@ Access is root-equivalent across managed hosts. Restrict CT port 8080 to the
|
||||
Traefik host with the Proxmox firewall; use HTTPS and limit the router to your
|
||||
LAN/Tailscale addresses. No password is set initially: API access fails closed.
|
||||
|
||||
1. Copy `deploy/` to the Proxmox VE 9 host. As root run
|
||||
`bash deploy/proxmox/create-ct.sh`. Defaults: unprivileged Debian 13 CT 501,
|
||||
1. On the Proxmox VE 9 host, as root, run (installs or updates; nothing stays on the host):
|
||||
|
||||
```bash
|
||||
bash -c "$(curl -fsSL https://git.finalfactory.de/FinalFactory/ShellBook/raw/branch/main/deploy/proxmox/bootstrap.sh)"
|
||||
```
|
||||
|
||||
It unpacks the repository into a temporary directory, runs
|
||||
`deploy/proxmox/create-ct.sh` from it, and removes it again; the installer files
|
||||
pushed into the CT are removed too. Defaults: unprivileged Debian 13 CT 501,
|
||||
2 cores, 2 GiB RAM, 16 GiB disk, DHCP on vmbr0, onboot, nesting and TUN.
|
||||
Overrides: `CTID`, `CT_STORAGE`, `TEMPLATE_STORAGE`, `CT_BRIDGE`, `CT_IP`
|
||||
(Proxmox ip syntax), `CT_HOSTNAME`, `CT_CORES`, `CT_MEMORY`, `CT_DISK_GB`.
|
||||
@@ -15,12 +22,13 @@ LAN/Tailscale addresses. No password is set initially: API access fails closed.
|
||||
`SHELLBOOK_PORT`, `SHELLBOOK_TRUSTED_PROXIES` (comma-separated proxy IPs),
|
||||
and `TS_AUTHKEY` in the host environment. Auth keys are transferred in a
|
||||
mode-0600 temporary file and removed, never stored in the service env.
|
||||
3. Open ShellBook in your browser. In the CT run `cat /var/lib/shellbook/setup-token`
|
||||
and enter the token with a new password (at least 12 characters) in the setup screen.
|
||||
This token is private, survives restart, and is deleted after setup. It is never logged.
|
||||
3. Open the address the installer prints and enter the one-time setup token it prints
|
||||
(also `cat /var/lib/shellbook/setup-token` in the CT) with a new password (at least
|
||||
12 characters). The token survives restart, is deleted after setup, and the server
|
||||
never logs it; only the installer shows it to the admin running it.
|
||||
Alternative password CLI: `SHELLBOOK_DATA_DIR=/var/lib/shellbook pnpm --filter @shellbook/server set-password`
|
||||
from the checkout (hidden prompt or one password line on stdin; never arguments).
|
||||
4. Run `claude` as shellbook and use `/login`. Authorize
|
||||
4. Unless a Claude login already exists: Settings > "Open terminal to log in", then `/login`. Authorize
|
||||
`/home/shellbook/.ssh/id_ed25519.pub` on managed hosts. The service user has
|
||||
no sudo access. Initialize notebooks manually if templates were absent.
|
||||
5. Install the Traefik example in its file-provider directory and replace the
|
||||
@@ -30,10 +38,16 @@ LAN/Tailscale addresses. No password is set initially: API access fails closed.
|
||||
detection (and thus Secure cookies). TLS terminates at Traefik.
|
||||
|
||||
Standalone CT installation: run `bash deploy/install.sh` as root on Debian 13.
|
||||
The installer can be rerun; it preserves env, password, workspace, SSH key and
|
||||
session signing secret. It builds the checkout but does not pull on rerun.
|
||||
Updates: `bash /opt/shellbook/deploy/update.sh` (root). Failure before restart
|
||||
leaves the running service in place. Check `journalctl -u shellbook`.
|
||||
|
||||
Updates: `shellbook-update` as root in the CT (from the Proxmox host:
|
||||
`pct exec 501 -- shellbook-update`), or rerun the bootstrap command. It downloads
|
||||
the installer from the repository (`/etc/shellbook/installer-url`, override with
|
||||
`SHELLBOOK_INSTALLER_URL`) and reruns it: pull (fast-forward; a `SHELLBOOK_REF`
|
||||
pin is kept), install, build, restart, health check. Env, password, workspace,
|
||||
SSH key, Claude login and session secret are preserved. Root never executes
|
||||
scripts from `/opt/shellbook`, which the service user (and the terminal panel)
|
||||
can modify. A failed build leaves the running service in place; check
|
||||
`journalctl -u shellbook`.
|
||||
|
||||
Configuration is `/etc/shellbook/env`; data is `/var/lib/shellbook` (back it up
|
||||
along with workspace and service-user home). `SHELLBOOK_SESSION_SECONDS` defaults
|
||||
@@ -66,7 +80,8 @@ Node 22 security releases; unattended upgrades cover Debian packages only.
|
||||
Build tools support node-pty compilation. Claude uses its native installer.
|
||||
|
||||
Local deployment regressions: `bash deploy/test/template-picker.test.sh` and
|
||||
`bash deploy/test/ct-config.test.sh`, `bash deploy/test/install-script.test.sh`. Existing CTs with a manual TUN mount entry
|
||||
`bash deploy/test/ct-config.test.sh`, `bash deploy/test/install-script.test.sh`,
|
||||
`bash deploy/test/bootstrap.test.sh` (needs root; run it in a Debian container). Existing CTs with a manual TUN mount entry
|
||||
(earlier Tailscale setups) keep it; no `dev0` is added on top.
|
||||
The scripts require bash, use LF endings, and avoid early-consuming pipelines
|
||||
under pipefail. Proxmox, systemd, Tailscale and SSH require deployment validation.
|
||||
|
||||
+52
-13
@@ -1,4 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
# Installs ShellBook on Debian 13, or updates an existing installation (rerunnable).
|
||||
# Keeps env, password, workspace, SSH key, Claude login and session secret.
|
||||
# Also installs `shellbook-update`, which reruns this installer fetched over HTTPS.
|
||||
set -euo pipefail
|
||||
[[ $EUID == 0 ]] || { echo 'Run as root inside Debian 13' >&2; exit 1; }
|
||||
# `pct exec` starts with PATH=/sbin:/bin:/usr/sbin:/usr/bin; Node and pnpm live in /usr/local/bin.
|
||||
@@ -44,7 +47,10 @@ if [[ ! -e /opt/shellbook ]]; then
|
||||
install -d -o shellbook -g shellbook /opt/shellbook
|
||||
runuser -u shellbook -- git clone "$repo" /opt/shellbook
|
||||
fi
|
||||
if [[ -n ${SHELLBOOK_REF:-} ]]; then runuser -u shellbook -- git -C /opt/shellbook checkout "$SHELLBOOK_REF"; fi
|
||||
git_app() { runuser -u shellbook -- git -C /opt/shellbook "$@"; }
|
||||
if [[ -n ${SHELLBOOK_REF:-} ]]; then git_app fetch --tags origin; git_app checkout "$SHELLBOOK_REF"; fi
|
||||
if git_app symbolic-ref -q HEAD >/dev/null; then git_app pull --ff-only
|
||||
else echo "Not pulling: /opt/shellbook is pinned to $(git_app rev-parse --short HEAD) (SHELLBOOK_REF)"; fi
|
||||
runuser -u shellbook -- bash -c 'cd /opt/shellbook; pnpm install --frozen-lockfile; pnpm build'
|
||||
workspace=/home/shellbook/workspace
|
||||
install -d -o shellbook -g shellbook "$workspace"
|
||||
@@ -60,6 +66,27 @@ if [[ ! -x /home/shellbook/.local/bin/claude ]]; then
|
||||
runuser -u shellbook -- env HOME=/home/shellbook bash -o pipefail -c 'curl -fsSL https://claude.ai/install.sh | bash'
|
||||
fi
|
||||
install -d -m 0750 /etc/shellbook
|
||||
# Where `shellbook-update` fetches the installer; remembered across updates.
|
||||
installer_url=${SHELLBOOK_INSTALLER_URL:-$(cat /etc/shellbook/installer-url 2>/dev/null || echo https://git.finalfactory.de/FinalFactory/ShellBook/raw/branch/main/deploy/install.sh)}
|
||||
[[ $installer_url =~ ^(https|file)://[^[:space:]]+$ ]] || { echo 'Invalid SHELLBOOK_INSTALLER_URL' >&2; exit 1; }
|
||||
printf '%s\n' "$installer_url" > /etc/shellbook/installer-url
|
||||
# Root must never execute code from /opt/shellbook: the service user (and its
|
||||
# terminal panel) can write there. The updater runs the installer from the repository.
|
||||
cat > /usr/local/sbin/shellbook-update <<'EOF'
|
||||
#!/usr/bin/env bash
|
||||
# Updates ShellBook: reruns the installer fetched from the repository.
|
||||
set -euo pipefail
|
||||
[[ $EUID == 0 ]] || { echo 'Run as root' >&2; exit 1; }
|
||||
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||
url=${SHELLBOOK_INSTALLER_URL:-$(cat /etc/shellbook/installer-url)}
|
||||
installer=$(mktemp)
|
||||
trap 'rm -f -- "$installer"' EXIT
|
||||
curl -fsSL "$url" -o "$installer"
|
||||
[[ $(head -n1 "$installer") == '#!/usr/bin/env bash' ]] || { echo "Not an installer: $url" >&2; exit 1; }
|
||||
cd /
|
||||
bash "$installer"
|
||||
EOF
|
||||
chmod 0755 /usr/local/sbin/shellbook-update
|
||||
if [[ ! -f /etc/shellbook/env ]]; then
|
||||
host=${SHELLBOOK_HOST:-0.0.0.0}
|
||||
port=${SHELLBOOK_PORT:-8080}
|
||||
@@ -120,16 +147,28 @@ fi
|
||||
systemctl daemon-reload
|
||||
systemctl enable shellbook
|
||||
systemctl restart shellbook
|
||||
cat <<'EOF'
|
||||
Next steps:
|
||||
1. Open ShellBook in the browser and enter the setup token shown by:
|
||||
cat /var/lib/shellbook/setup-token
|
||||
Alternative password CLI (hidden prompt):
|
||||
runuser -u shellbook -- env SHELLBOOK_DATA_DIR=/var/lib/shellbook node /opt/shellbook/apps/server/dist/cli/set-password.js
|
||||
2. Log into Claude as the service user:
|
||||
runuser -l shellbook -c '/home/shellbook/.local/bin/claude'
|
||||
Then use /login.
|
||||
3. Authorize this public SSH key on managed servers:
|
||||
EOF
|
||||
# Wait until the server answers before reporting success.
|
||||
listen_host=$(sed -n 's/^SHELLBOOK_HOST=//p' /etc/shellbook/env)
|
||||
listen_port=$(sed -n 's/^SHELLBOOK_PORT=//p' /etc/shellbook/env)
|
||||
case ${listen_host:-0.0.0.0} in 0.0.0.0|::|'[::]') probe=127.0.0.1 ;; *:*) probe="[$listen_host]" ;; *) probe=$listen_host ;; esac
|
||||
for ((attempt=0; attempt<60; attempt++)); do
|
||||
if curl -fsS "http://$probe:${listen_port:-8080}/api/health" >/dev/null 2>&1; then break; fi
|
||||
sleep 1
|
||||
done
|
||||
curl -fsS "http://$probe:${listen_port:-8080}/api/health" >/dev/null 2>&1 || {
|
||||
echo 'ShellBook did not start; see: journalctl -u shellbook -n 50' >&2; exit 1;
|
||||
}
|
||||
address=$(hostname -I 2>/dev/null | awk '{print $1}')
|
||||
echo
|
||||
echo "ShellBook $(git_app describe --always --dirty) is running: http://${address:-<container-ip>}:${listen_port:-8080}"
|
||||
if [[ -f /var/lib/shellbook/setup-token ]]; then
|
||||
echo "First-time setup token (one-time, deleted after setup): $(cat /var/lib/shellbook/setup-token)"
|
||||
echo 'Enter it in the browser together with your new password.'
|
||||
fi
|
||||
if [[ ! -f /home/shellbook/.claude/.credentials.json ]]; then
|
||||
echo 'Claude is not logged in yet: Settings > "Open terminal to log in", then /login.'
|
||||
fi
|
||||
echo "ShellBook's SSH public key (the Hosts page can install it on your servers):"
|
||||
cat /home/shellbook/.ssh/id_ed25519.pub
|
||||
echo '4. Configure Traefik, trusted proxy IPs and the LAN/Tailscale firewall; see deploy/README.md.'
|
||||
echo 'Update later with: shellbook-update (from the Proxmox host: pct exec <ctid> -- shellbook-update)'
|
||||
echo 'Behind Traefik: see deploy/README.md for the proxy and firewall settings.'
|
||||
|
||||
Executable
+15
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env bash
|
||||
# Install or update ShellBook in a Proxmox CT in one step, leaving nothing on the host.
|
||||
# Run on the Proxmox host as root:
|
||||
# bash -c "$(curl -fsSL https://git.finalfactory.de/FinalFactory/ShellBook/raw/branch/main/deploy/proxmox/bootstrap.sh)"
|
||||
# Accepts the overrides of create-ct.sh (CTID, CT_*, SHELLBOOK_*, TS_AUTHKEY).
|
||||
# The repository is unpacked into a temporary directory that is always removed.
|
||||
set -euo pipefail
|
||||
[[ $EUID == 0 ]] && command -v pct >/dev/null || { echo 'Run on the Proxmox host as root' >&2; exit 1; }
|
||||
archive=${SHELLBOOK_ARCHIVE_URL:-https://git.finalfactory.de/FinalFactory/ShellBook/archive/${SHELLBOOK_REF:-main}.tar.gz}
|
||||
work=$(mktemp -d)
|
||||
trap 'rm -rf -- "$work"' EXIT
|
||||
curl -fsSL "$archive" | tar -xz -C "$work" --strip-components=1 --no-same-owner
|
||||
[[ -f $work/deploy/proxmox/create-ct.sh ]] || { echo "No ShellBook deploy scripts in $archive" >&2; exit 1; }
|
||||
# stdin stays away from pct exec: callers may pipe this script into bash.
|
||||
bash "$work/deploy/proxmox/create-ct.sh" </dev/null
|
||||
@@ -67,4 +67,5 @@ for key in SHELLBOOK_REPO SHELLBOOK_REF SHELLBOOK_HOST SHELLBOOK_PORT SHELLBOOK_
|
||||
if [[ -v $key ]]; then printf 'export %s=%q\n' "$key" "${!key}" >> "$settings"; fi
|
||||
done
|
||||
pct push "$ctid" "$settings" /root/shellbook-install.env --perms 0600
|
||||
pct exec "$ctid" -- bash -c 'trap "rm -f /root/shellbook-install.env" EXIT; source /root/shellbook-install.env; bash /root/shellbook-install.sh'
|
||||
# Leave no installer files behind in the CT either; later updates use `shellbook-update`.
|
||||
pct exec "$ctid" -- bash -c 'trap "rm -f /root/shellbook-install.env /root/shellbook-install.sh" EXIT; source /root/shellbook-install.env; bash /root/shellbook-install.sh'
|
||||
|
||||
Executable
+40
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
# Runs bootstrap.sh against a stub `pct` (existing CT 501) and checks that the
|
||||
# host keeps no files and the CT keeps no installer files. Needs root (Linux/Docker).
|
||||
[[ $EUID == 0 ]] || { echo 'bootstrap test skipped: needs root (run it in a Debian container)'; exit 0; }
|
||||
repo=$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)
|
||||
test_dir=$(mktemp -d)
|
||||
trap 'rm -rf -- "$test_dir"' EXIT
|
||||
mkdir "$test_dir/bin" "$test_dir/tmp" "$test_dir/ct"
|
||||
# Archive of the working tree, shaped like Gitea's (one top-level folder).
|
||||
tar -C "$repo/.." -czf "$test_dir/archive.tar.gz" --exclude=node_modules --exclude=.git "$(basename "$repo")/deploy"
|
||||
cat > "$test_dir/bin/pct" <<'STUB'
|
||||
#!/usr/bin/env bash
|
||||
log=$STUB_DIR/pct.log; ct=$STUB_DIR/ct
|
||||
echo "$*" >> "$log"
|
||||
case $1 in
|
||||
config) printf 'arch: amd64\nfeatures: nesting=1\nostype: debian\nunprivileged: 1\nlxc.mount.entry: /dev/net/tun dev/net/tun none bind,create=file\n' ;;
|
||||
status) echo 'status: running' ;;
|
||||
start|set|shutdown) ;;
|
||||
push) cp "$3" "$ct/$(basename "$4")" ;;
|
||||
exec)
|
||||
shift 3
|
||||
if [[ $1 == dpkg ]]; then echo amd64
|
||||
elif [[ $1 == bash && $2 == -c ]]; then
|
||||
# Run the real cleanup wrapper with /root mapped into the fake CT.
|
||||
script=${3//\/root\//$ct/}; script=${script//bash $ct\/shellbook-install.sh/echo installer-ran}
|
||||
bash -c "$script"
|
||||
fi ;;
|
||||
esac
|
||||
STUB
|
||||
printf '#!/usr/bin/env bash\necho amd64\n' > "$test_dir/bin/dpkg"
|
||||
chmod +x "$test_dir/bin/pct" "$test_dir/bin/dpkg"
|
||||
out=$(PATH="$test_dir/bin:$PATH" STUB_DIR="$test_dir" TMPDIR="$test_dir/tmp" CTID=501 SHELLBOOK_ARCHIVE_URL="file://$test_dir/archive.tar.gz" \
|
||||
bash "$repo/deploy/proxmox/bootstrap.sh")
|
||||
[[ $out == *installer-ran* ]] || { echo "installer did not run: $out" >&2; exit 1; }
|
||||
[[ -z $(ls -A "$test_dir/tmp") ]] || { echo "host temp files left: $(ls -A "$test_dir/tmp")" >&2; exit 1; }
|
||||
[[ -z $(ls -A "$test_dir/ct") ]] || { echo "CT files left: $(ls -A "$test_dir/ct")" >&2; exit 1; }
|
||||
grep -q '^push 501 .*/install.sh /root/shellbook-install.sh' "$test_dir/pct.log" || { echo 'installer not pushed' >&2; exit 1; }
|
||||
! grep -q -- '--dev0' "$test_dir/pct.log" || { echo 'dev0 added despite TUN mount' >&2; exit 1; }
|
||||
printf '5 bootstrap checks passed\n'
|
||||
@@ -3,12 +3,21 @@ set -euo pipefail
|
||||
# Static guards for regressions seen on a real Proxmox deploy (full run needs Debian 13 as root).
|
||||
dir="$(dirname "${BASH_SOURCE[0]}")/.."
|
||||
path_line='export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
|
||||
for script in install.sh update.sh; do
|
||||
# pct exec omits /usr/local/bin: PATH must be set before the first command that needs node/pnpm.
|
||||
first_path=$(grep -nxF "$path_line" "$dir/$script" | head -n1 | cut -d: -f1)
|
||||
first_use=$(grep -nE '\b(node|pnpm|npm|corepack)\b' "$dir/$script" | grep -v '^[0-9]*:#' | head -n1 | cut -d: -f1)
|
||||
[[ -n $first_path && $first_path -lt $first_use ]] || { echo "$script: PATH not set before node/pnpm use" >&2; exit 1; }
|
||||
done
|
||||
# pct exec omits /usr/local/bin: PATH must be set before the first command that needs node/pnpm.
|
||||
first_path=$(grep -nxF "$path_line" "$dir/install.sh" | head -n1 | cut -d: -f1)
|
||||
first_use=$(grep -nE '\b(node|pnpm|npm|corepack)\b' "$dir/install.sh" | grep -v '^[0-9]*:#' | head -n1 | cut -d: -f1)
|
||||
[[ -n $first_path && $first_path -lt $first_use ]] || { echo 'install.sh: PATH not set before node/pnpm use' >&2; exit 1; }
|
||||
# Node tarball must not hand /usr/local to the archive's uid.
|
||||
grep -qE '^tar --no-same-owner .*node_file' "$dir/install.sh" || { echo 'install.sh: tar keeps archive owners' >&2; exit 1; }
|
||||
printf '3 install script checks passed\n'
|
||||
# The root-run updater must not execute anything from the service-user-writable checkout.
|
||||
updater=$(sed -n "/^cat > \/usr\/local\/sbin\/shellbook-update <<'EOF'$/,/^EOF$/p" "$dir/install.sh" | sed '1d;$d')
|
||||
[[ -n $updater ]] || { echo 'install.sh: shellbook-update not generated' >&2; exit 1; }
|
||||
bash -n <<< "$updater" || { echo 'shellbook-update: syntax error' >&2; exit 1; }
|
||||
[[ $updater != */opt/shellbook* ]] || { echo 'shellbook-update: references /opt/shellbook' >&2; exit 1; }
|
||||
[[ $updater == *"$path_line"* ]] || { echo 'shellbook-update: PATH not set' >&2; exit 1; }
|
||||
# An existing checkout must be updated, not just rebuilt.
|
||||
grep -q 'git_app pull --ff-only' "$dir/install.sh" || { echo 'install.sh: existing checkout is not pulled' >&2; exit 1; }
|
||||
# Nothing may remain in the CT's /root after the Proxmox install.
|
||||
grep -q 'rm -f /root/shellbook-install.env /root/shellbook-install.sh' "$dir/proxmox/create-ct.sh" \
|
||||
|| { echo 'create-ct.sh: installer files left in the CT' >&2; exit 1; }
|
||||
printf '8 install script checks passed\n'
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
[[ $EUID == 0 ]] || { echo 'Run as root' >&2; exit 1; }
|
||||
# `pct exec` omits /usr/local/bin, where Node and pnpm live.
|
||||
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||
runuser -u shellbook -- bash -c 'cd /opt/shellbook; git pull --ff-only; pnpm install --frozen-lockfile; pnpm build'
|
||||
systemctl restart shellbook
|
||||
systemctl --no-pager status shellbook
|
||||
Reference in New Issue
Block a user