feat(deploy): one-step install/update from the Proxmox host (#6)

bootstrap.sh runs on the Proxmox host via
  bash -c "$(curl -fsSL .../deploy/proxmox/bootstrap.sh)"
It unpacks the repository into a temporary directory, runs
create-ct.sh and removes everything again; create-ct.sh also removes
the installer files it pushed into the CT. Nothing stays on the host.

install.sh now installs or updates: an existing checkout is pulled
(fast-forward, SHELLBOOK_REF pins are kept), the service is restarted
and health-checked, and the summary prints the address, the one-time
setup token while setup is pending, the Claude login state and the
SSH public key.

It also installs a root-owned `shellbook-update` that downloads the
installer from the repository and reruns it. Root never executes
scripts from /opt/shellbook, which the service user and its terminal
panel can modify, so deploy/update.sh is removed.

Verified in a Debian 13 container: fresh install, then an update that
pulls a new commit while a tampered checkout script is not executed;
bootstrap.test.sh checks that host and CT keep no installer files.
This commit is contained in:
Florian Schmidt
2026-11-16 10:57:42 +01:00
parent 5e60973ebf
commit 399628bf16
8 changed files with 152 additions and 41 deletions
+40
View File
@@ -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'
+16 -7
View File
@@ -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'