#!/usr/bin/env bash # make-sandbox.sh — Build a hermetic kernel-agent sandbox for ka-install tests. # # Usage: make-sandbox.sh [output-dir] # # Fixtures: # happy-path — full build receipt present, no drift # drift — manifest.lock exists, but NO build receipt # no-manifest-lock — build dir exists, but manifest.lock missing # no-host-manifest — fleet/.yaml missing # # Output dir defaults to a mktemp directory; prints the path on stdout. set -euo pipefail repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd)" fixture_name="${1:?fixture name required}" scratch="${2:-$(mktemp -d -t ka-install-test.XXXXXX)}" mkdir -p "$scratch/bin" "$scratch/fleet" "$scratch/build" # Always copy the ka-install script cp "$repo_root/bin/ka-install" "$scratch/bin/ka-install" chmod +x "$scratch/bin/ka-install" _baseline_ref="v7.0" _suffix="-fresnel-fourier" _boot_path="/boot/" _bootloader_path="/boot/extlinux/extlinux.conf" _host="testhost" _pkg_name="linux-testhost-fourier" case "$fixture_name" in happy-path) # Full setup: fleet manifest + manifest.lock + build receipt cat > "$scratch/fleet/${_host}.yaml" < "$scratch/build/${_host}/${_baseline_ref}/manifest.lock" < "$scratch/fleet/${_host}.yaml" < "$scratch/build/${_host}/${_baseline_ref}/manifest.lock" < "$scratch/fleet/${_host}.yaml" <.yaml missing # Don't create fleet/testhost.yaml mkdir -p "$scratch/build/${_host}/${_baseline_ref}" cat > "$scratch/build/${_host}/${_baseline_ref}/manifest.lock" < "$scratch/fleet/${_host}.yaml" < "$scratch/build/${_host}/${_baseline_ref}/manifest.lock" < "$scratch/fleet/${_host}.yaml" < "$scratch/build/${_host}/${_baseline_ref}/manifest.lock" <&2 echo "valid: happy-path drift no-manifest-lock no-host-manifest image-detection ampere-boot-firmware" >&2 exit 1 ;; esac echo "$scratch"