#!/usr/bin/env bash
# fake ssh for phase-06-k8s-bootstrap.sh tests.
# Collects positionals after 'bash -s' to tell GATE 1 (5 args) from 6.4 (8 args).
# Steered by env: VIP_FAIL NET_FAIL BOOT_FAIL.
pos=(); after=0
for a in "$@"; do
  if [ "$after" = 1 ]; then pos+=("$a"); continue; fi
  [ "$a" = "-s" ] && after=1
done
cat >/dev/null 2>&1 || true   # discard the heredoc on stdin
case "${#pos[@]}" in
  5)  # GATE 1 egress probe: khost kport ihost iport timeout
      khost="${pos[0]}"; kport="${pos[1]}"; ihost="${pos[2]}"; iport="${pos[3]}"
      if [ "${VIP_FAIL:-0}" = 1 ]; then echo "VIP-FAIL $khost:$kport"; else echo "VIP-OK $khost:$kport"; fi
      if [ "${NET_FAIL:-0}" = 1 ]; then echo "NET-FAIL $ihost:$iport"; else echo "NET-OK $ihost:$iport"; fi
      if [ "${VIP_FAIL:-0}" = 1 ] || [ "${NET_FAIL:-0}" = 1 ]; then echo "GATE1: FAIL"; else echo "GATE1: PASS"; fi
      ;;
  8)  # 6.4 bootstrap
      if [ "${BOOT_FAIL:-0}" = 1 ]; then
        echo "=== bootstrap ==="; echo "Error: bootstrap failed"
      else
        echo "cluster status:           ready"; echo "network:                  enabled"; echo "BOOT: READY"
      fi
      ;;
  *)  echo "fake-ssh: unexpected positional count ${#pos[@]}" >&2 ;;
esac
exit 0
