#!/usr/bin/env bash # ============================================================================= # ~/bin/fleet-beacon — Fleet Realtime Telemetry Beacon Dispatcher # Zero-Bloat Architecture: Native C first, Bash fallback, Python avoided. # ============================================================================= BIN_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # Ensure fleet environment is active if [ -z "$FLEET_NODE" ] || [ -z "$FLEET_ARCH" ]; then [ -f "$BIN_DIR/bin-env" ] && source "$BIN_DIR/bin-env" 2>/dev/null || true fi # 1. Prefer native C compiled binary (< 1MB RAM, 0% CPU) if [ -x "$BIN_DIR/fleet-beacon-c" ]; then exec "$BIN_DIR/fleet-beacon-c" "$@" fi # 2. Compile native C binary on the fly if compiler exists if command -v gcc >/dev/null 2>&1 && [ -f "$BIN_DIR/src/fleet-beacon.c" ]; then gcc -O2 -Wall -Wextra -pedantic -o "$BIN_DIR/fleet-beacon-c" "$BIN_DIR/src/fleet-beacon.c" 2>/dev/null || true if [ -x "$BIN_DIR/fleet-beacon-c" ]; then exec "$BIN_DIR/fleet-beacon-c" "$@" fi fi # 3. Fallback to pure Bash implementation if [ -x "$BIN_DIR/fleet-beacon.sh" ]; then exec "$BIN_DIR/fleet-beacon.sh" "$@" fi # 4. Last-ditch Python fallback if neither is available if [ -x "$BIN_DIR/fleet-beacon.py" ] && command -v python3 >/dev/null 2>&1; then exec python3 "$BIN_DIR/fleet-beacon.py" "$@" fi echo "Error: No viable fleet-beacon runtime found." >&2 exit 1