#!/usr/bin/env bash # Corre `test-foco-egress.sh` donde SÍ hay root: empaqueta los artefactos VIGENTES, los manda al # worker y trae el veredicto. # # scripts/foco-egress-remoto.sh [--broken-rules] [host] (host default: 1º de scripts/farm/.fleet) # # ⚠ Los artefactos se resuelven con `takana hash`, NO con `ls store/*-gmp`. La diferencia no es # estética: el store guarda artefactos VIEJOS con el mismo nombre, y la primera corrida de esto # empaquetó un `gmp` de otra época que sólo traía `libgmp.a` ⇒ `libnftables.so` no relocaba. En el # hub no se veía porque el lab tiene su propia libgmp y la tapaba. Sellado ≠ vigente. set -euo pipefail cd "$(dirname "$0")/.." ROTO="" if [ "${1:-}" = "--broken-rules" ]; then ROTO="--broken-rules"; shift; fi HOST="${1:-}" if [ -z "$HOST" ]; then HOST="$(awk 'NR==1{print $1}' scripts/farm/.fleet 2>/dev/null || true)" [ -n "$HOST" ] || { echo "✗ no hay host: pasalo por argumento o poné uno en scripts/farm/.fleet" >&2; exit 2; } fi LLAVE="${SSH_KEY:-$HOME/.ssh/github5}" TAKANA=./target/release/takana TMP="$(mktemp -d)"; trap 'rm -rf "$TMP"' EXIT echo "== artefactos vigentes" DIRS=() for r in nftables libmnl libnftnl gmp; do h="$($TAKANA --store ./store hash "recipes/$r.toml" | tail -1)"; h="${h#b3:}" d="store/$h-$r" [ -d "$d" ] || { echo "✗ $r vigente no está sellado ($d) — construilo antes" >&2; exit 1; } [ -n "$(ls -A "$d")" ] || { echo "✗ $r vigente está VACÍO: eso no es un artefacto, es un nombre" >&2; exit 1; } echo " $r → ${h:0:12}" DIRS+=("$h-$r") done tar czf "$TMP/artefactos-nft.tar.gz" -C store "${DIRS[@]}" echo "== enviando a $HOST" scp -i "$LLAVE" -o StrictHostKeyChecking=no -q \ scripts/test-foco-egress.sh .dev-fs/alpine-minirootfs.tar.gz "$TMP/artefactos-nft.tar.gz" \ "root@$HOST:/root/" # `set -e` mataría el script antes de leer $? de un ssh que falla, y entonces el veredicto ROJO del # guardián llegaría como si nunca hubiera corrido. Se captura explícitamente. SALIDA=0 ssh -i "$LLAVE" -o BatchMode=yes "root@$HOST" \ "bash /root/test-foco-egress.sh --rootfs /root/alpine-minirootfs.tar.gz --artifacts /root/artefactos-nft.tar.gz $ROTO" \ || SALIDA=$? ssh -i "$LLAVE" -o BatchMode=yes "root@$HOST" \ 'rm -f /root/test-foco-egress.sh /root/alpine-minirootfs.tar.gz /root/artefactos-nft.tar.gz' || true exit $SALIDA