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.
41 lines
2.2 KiB
Bash
Executable File
41 lines
2.2 KiB
Bash
Executable File
#!/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'
|