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
+1 -1
View File
@@ -3,7 +3,7 @@
## Current Focus ## 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] 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 ## Invariants
- Displayed script == executed script (one substitution path). - Displayed script == executed script (one substitution path).
+26 -11
View File
@@ -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 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. LAN/Tailscale addresses. No password is set initially: API access fails closed.
1. Copy `deploy/` to the Proxmox VE 9 host. As root run 1. On the Proxmox VE 9 host, as root, run (installs or updates; nothing stays on the host):
`bash deploy/proxmox/create-ct.sh`. Defaults: unprivileged Debian 13 CT 501,
```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. 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` Overrides: `CTID`, `CT_STORAGE`, `TEMPLATE_STORAGE`, `CT_BRIDGE`, `CT_IP`
(Proxmox ip syntax), `CT_HOSTNAME`, `CT_CORES`, `CT_MEMORY`, `CT_DISK_GB`. (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), `SHELLBOOK_PORT`, `SHELLBOOK_TRUSTED_PROXIES` (comma-separated proxy IPs),
and `TS_AUTHKEY` in the host environment. Auth keys are transferred in a 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. 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` 3. Open the address the installer prints and enter the one-time setup token it prints
and enter the token with a new password (at least 12 characters) in the setup screen. (also `cat /var/lib/shellbook/setup-token` in the CT) with a new password (at least
This token is private, survives restart, and is deleted after setup. It is never logged. 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` 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). 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 `/home/shellbook/.ssh/id_ed25519.pub` on managed hosts. The service user has
no sudo access. Initialize notebooks manually if templates were absent. no sudo access. Initialize notebooks manually if templates were absent.
5. Install the Traefik example in its file-provider directory and replace the 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. detection (and thus Secure cookies). TLS terminates at Traefik.
Standalone CT installation: run `bash deploy/install.sh` as root on Debian 13. 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: `shellbook-update` as root in the CT (from the Proxmox host:
Updates: `bash /opt/shellbook/deploy/update.sh` (root). Failure before restart `pct exec 501 -- shellbook-update`), or rerun the bootstrap command. It downloads
leaves the running service in place. Check `journalctl -u shellbook`. 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 Configuration is `/etc/shellbook/env`; data is `/var/lib/shellbook` (back it up
along with workspace and service-user home). `SHELLBOOK_SESSION_SECONDS` defaults 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. Build tools support node-pty compilation. Claude uses its native installer.
Local deployment regressions: `bash deploy/test/template-picker.test.sh` and 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. (earlier Tailscale setups) keep it; no `dev0` is added on top.
The scripts require bash, use LF endings, and avoid early-consuming pipelines The scripts require bash, use LF endings, and avoid early-consuming pipelines
under pipefail. Proxmox, systemd, Tailscale and SSH require deployment validation. under pipefail. Proxmox, systemd, Tailscale and SSH require deployment validation.
+52 -13
View File
@@ -1,4 +1,7 @@
#!/usr/bin/env bash #!/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 set -euo pipefail
[[ $EUID == 0 ]] || { echo 'Run as root inside Debian 13' >&2; exit 1; } [[ $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. # `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 install -d -o shellbook -g shellbook /opt/shellbook
runuser -u shellbook -- git clone "$repo" /opt/shellbook runuser -u shellbook -- git clone "$repo" /opt/shellbook
fi 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' runuser -u shellbook -- bash -c 'cd /opt/shellbook; pnpm install --frozen-lockfile; pnpm build'
workspace=/home/shellbook/workspace workspace=/home/shellbook/workspace
install -d -o shellbook -g 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' runuser -u shellbook -- env HOME=/home/shellbook bash -o pipefail -c 'curl -fsSL https://claude.ai/install.sh | bash'
fi fi
install -d -m 0750 /etc/shellbook 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 if [[ ! -f /etc/shellbook/env ]]; then
host=${SHELLBOOK_HOST:-0.0.0.0} host=${SHELLBOOK_HOST:-0.0.0.0}
port=${SHELLBOOK_PORT:-8080} port=${SHELLBOOK_PORT:-8080}
@@ -120,16 +147,28 @@ fi
systemctl daemon-reload systemctl daemon-reload
systemctl enable shellbook systemctl enable shellbook
systemctl restart shellbook systemctl restart shellbook
cat <<'EOF' # Wait until the server answers before reporting success.
Next steps: listen_host=$(sed -n 's/^SHELLBOOK_HOST=//p' /etc/shellbook/env)
1. Open ShellBook in the browser and enter the setup token shown by: listen_port=$(sed -n 's/^SHELLBOOK_PORT=//p' /etc/shellbook/env)
cat /var/lib/shellbook/setup-token case ${listen_host:-0.0.0.0} in 0.0.0.0|::|'[::]') probe=127.0.0.1 ;; *:*) probe="[$listen_host]" ;; *) probe=$listen_host ;; esac
Alternative password CLI (hidden prompt): for ((attempt=0; attempt<60; attempt++)); do
runuser -u shellbook -- env SHELLBOOK_DATA_DIR=/var/lib/shellbook node /opt/shellbook/apps/server/dist/cli/set-password.js if curl -fsS "http://$probe:${listen_port:-8080}/api/health" >/dev/null 2>&1; then break; fi
2. Log into Claude as the service user: sleep 1
runuser -l shellbook -c '/home/shellbook/.local/bin/claude' done
Then use /login. curl -fsS "http://$probe:${listen_port:-8080}/api/health" >/dev/null 2>&1 || {
3. Authorize this public SSH key on managed servers: echo 'ShellBook did not start; see: journalctl -u shellbook -n 50' >&2; exit 1;
EOF }
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 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.'
+15
View File
@@ -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
+2 -1
View File
@@ -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 if [[ -v $key ]]; then printf 'export %s=%q\n' "$key" "${!key}" >> "$settings"; fi
done done
pct push "$ctid" "$settings" /root/shellbook-install.env --perms 0600 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'
+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). # Static guards for regressions seen on a real Proxmox deploy (full run needs Debian 13 as root).
dir="$(dirname "${BASH_SOURCE[0]}")/.." dir="$(dirname "${BASH_SOURCE[0]}")/.."
path_line='export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' 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.
# 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_path=$(grep -nxF "$path_line" "$dir/$script" | 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)
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 'install.sh: PATH not set before node/pnpm use' >&2; exit 1; }
[[ -n $first_path && $first_path -lt $first_use ]] || { echo "$script: PATH not set before node/pnpm use" >&2; exit 1; }
done
# Node tarball must not hand /usr/local to the archive's uid. # 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; } 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'
-8
View File
@@ -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