#!/usr/bin/env bash 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' # 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; } # 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'