45 lines
1.6 KiB
Bash
Executable File
45 lines
1.6 KiB
Bash
Executable File
#!/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. Compile or recompile native C binary if source is newer or binary missing
|
|
CC_BIN=""
|
|
if command -v gcc >/dev/null 2>&1; then
|
|
CC_BIN="gcc"
|
|
elif command -v clang >/dev/null 2>&1; then
|
|
CC_BIN="clang"
|
|
fi
|
|
|
|
if [ -n "$CC_BIN" ] && [ -f "$BIN_DIR/src/fleet-beacon.c" ]; then
|
|
if [ ! -x "$BIN_DIR/fleet-beacon-c" ] || [ "$BIN_DIR/src/fleet-beacon.c" -nt "$BIN_DIR/fleet-beacon-c" ]; then
|
|
"$CC_BIN" -O2 -Wall -Wextra -pedantic -o "$BIN_DIR/fleet-beacon-c" "$BIN_DIR/src/fleet-beacon.c" 2>/dev/null || true
|
|
fi
|
|
fi
|
|
|
|
# 2. Prefer native C compiled binary (< 1MB RAM, 0% CPU)
|
|
if [ -x "$BIN_DIR/fleet-beacon-c" ]; then
|
|
exec "$BIN_DIR/fleet-beacon-c" "$@"
|
|
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
|