#!/bin/sh # # run-local.sh - build and run latd in place for VT1200 experiments. # # Nothing is installed system-wide: binaries, unix sockets, logs and pcaps all # live under lat/. latd advertises the VT1200 login services through # tools/osc-filter.py (strips OSC strings that crash the terminal emulator). # # Usage: run-local.sh {build|start|stop|restart|status|capture} # # build bootstrap + configure + make into lat/local/build[-debug] # start start latd (root) + apply multicast/group/service config # stop stop latd # restart stop then start # status show latd configuration and advertised services # capture tcpdump LAT frames (ethetype 0x6004) to lat/local/capture-*.pcap # # Environment overrides: # IFACE=enp197s0f3u1 interface latd uses (VT1200's segment) # VARIANT=debug|release which build tree (default: debug) # set -eu SELF_DIR=$(cd "$(dirname "$0")" && pwd) SRC="$SELF_DIR/code/latd" LOCAL="$SELF_DIR/local" FILTER="$SELF_DIR/tools/osc-filter.py" IFACE="${IFACE:-enp197s0f3u1}" VARIANT="${VARIANT:-debug}" case "$VARIANT" in debug) BUILDDIR="$LOCAL/build-debug"; CONFOPTS="--enable-debug" ;; release) BUILDDIR="$LOCAL/build"; CONFOPTS="" ;; *) echo "VARIANT must be 'release' or 'debug'" >&2; exit 2 ;; esac LATCP="$BUILDDIR/latcp" SOCK_LATCP="$LOCAL/run/latcp" SOCK_LLOGIN="$LOCAL/run/latlogin" LOG="$LOCAL/latd.log" need_root() { [ "$(id -u)" = 0 ] || { echo "must run as root (use sudo)" >&2; exit 1; } } do_build() { mkdir -p "$LOCAL/run" "$BUILDDIR" [ -x "$SRC/configure" ] || ( cd "$SRC" && ./bootstrap.sh ) if ! ( cd "$BUILDDIR" && "$SRC/configure" $CONFOPTS \ --with-latcp-socket="$SOCK_LATCP" \ --with-llogin-socket="$SOCK_LLOGIN" \ && make -j"$(nproc)" ) >"$LOCAL/build.log" 2>&1; then echo "build failed - see $LOCAL/build.log" >&2 exit 1 fi echo "built: $BUILDDIR/{latd,latcp,llogin,moprc} (log: $LOCAL/build.log)" } do_stop() { [ -x "$LATCP" ] || return 0 "$LATCP" -h 2>/dev/null || true } do_start() { need_root [ -x "$LATCP" ] || { echo "not built yet: run '$0 build'" >&2; exit 1; } do_stop; sleep 1 # -d: do not fork (foreground); setsid detaches it from this shell. setsid "$LATCP" -s -d -v -v -i "$IFACE" >"$LOG" 2>&1 &2; exit 1; } "$LATCP" -m 10 # advertise every 10s (default 60) "$LATCP" -G 1 # group 1: match the VT1200's group code # latd creates a default service named after the node (SID) that runs # /bin/login UNFILTERED. Replace it (and add a VT1200 alias) with the # OSC-filtered login, so the terminal never sees control strings. "$LATCP" -D -a SID 2>/dev/null || true "$LATCP" -D -a VT1200 2>/dev/null || true "$LATCP" -A -a SID -i 'filtered login (node name)' -r 100 -C "$FILTER" "$LATCP" -A -a VT1200 -i 'filtered login' -r 100 -C "$FILTER" echo "latd up on $IFACE (variant=$VARIANT)" echo "services: SID, VT1200 -> login through $FILTER" echo "log: $LOG stop with: sudo $0 stop" } do_status() { need_root "$LATCP" -d } do_capture() { need_root out="$LOCAL/capture-$(date +%H%M%S).pcap" echo "capturing LAT (0x6004) on $IFACE -> $out (Ctrl-C to stop)" exec tcpdump -i "$IFACE" -w "$out" 'ether proto 0x6004' } case "${1:-}" in build) do_build ;; start) do_start ;; stop) need_root; do_stop; echo "latd stopped" ;; restart) need_root; do_stop; sleep 1; do_start ;; status) do_status ;; capture) do_capture ;; *) echo "usage: $0 {build|start|stop|restart|status|capture}" >&2; exit 2 ;; esac