Each shipped template is offered once (recorded in /etc/shellbook/templates-offered) and copied as the service user only when the file does not exist, so updates add new templates without overwriting files or restoring deleted ones.
41 lines
2.9 KiB
Bash
Executable File
41 lines
2.9 KiB
Bash
Executable File
#!/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; }
|
|
# Templates: new ones reach existing workspaces once; existing and deleted files stay as they are.
|
|
offer=$(sed -n '/^offer_templates() {/,/^}$/p' "$dir/install.sh")
|
|
[[ -n $offer ]] || { echo 'install.sh: offer_templates missing' >&2; exit 1; }
|
|
tmp=$(mktemp -d); trap 'rm -rf "$tmp"' EXIT
|
|
(
|
|
runuser() { shift 3; "$@"; } # stub: run as the current user
|
|
eval "$offer"
|
|
mkdir -p "$tmp/t/notebooks/infra" "$tmp/w/notebooks"
|
|
printf 'new\n' > "$tmp/t/notebooks/infra/lxc.md"; printf 'shipped\n' > "$tmp/t/notebooks/a.md"
|
|
printf 'mine\n' > "$tmp/w/notebooks/a.md"
|
|
offer_templates "$tmp/t" "$tmp/w" "$tmp/offered"
|
|
[[ $(cat "$tmp/w/notebooks/a.md") == mine && $(cat "$tmp/w/notebooks/infra/lxc.md") == new ]] || { echo 'offer_templates: wrong copy' >&2; exit 1; }
|
|
rm "$tmp/w/notebooks/infra/lxc.md"
|
|
offer_templates "$tmp/t" "$tmp/w" "$tmp/offered"
|
|
[[ ! -e $tmp/w/notebooks/infra/lxc.md ]] || { echo 'offer_templates: deleted template came back' >&2; exit 1; }
|
|
[[ $(sort "$tmp/offered" | tr '\n' ' ') == 'notebooks/a.md notebooks/infra/lxc.md ' ]] || { echo 'offer_templates: wrong list' >&2; exit 1; }
|
|
)
|
|
printf '9 install script checks passed\n'
|