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:
+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.'
|
||||
|
||||
Reference in New Issue
Block a user