#!/bin/sh
# Bounded inspection for guide 453; review commands before running.
# Run only on an approved host with read-only service credentials.
set -eu
umask 077
out=$(mktemp -d "${TMPDIR:-/tmp}/tcinfra-453.XXXXXX")
failed=0
collect() {
  name=$1
  shift
  # stdout/stderr remain private local artifacts, never public telemetry.
  if "$@" >"$out/$name.out" 2>"$out/$name.err"; then
    printf '%s\n' "$name: collected"
  else
    failed=1
    printf '%s\n' "$name: failed; inspect private stderr" >&2
  fi
}
date -u '+%Y-%m-%dT%H:%M:%SZ' >"$out/observed-at.txt"
collect check-1 wg show all latest-handshakes
collect check-2 tailscale status --json
# Inspect results and sanitize them before any external sharing.
# Nonzero collection status must not be normalized into a healthy value.
printf 'Private inspection directory: %s\n' "$out"
# The caller owns retention and secure deletion of this local directory.
# Exit zero means collection completed, not that the environment is compliant.
exit "$failed"
