#!/bin/sh # The dispatcher script rouses on the events that change where packets go, and on nothing else. # # Checked by running it with a stub systemctl on PATH, because the thing worth testing is which # events it acts on — a script that rouses on `down` would reconnect into a network that is gone, # and one that rouses on nothing is the timeout it was written to avoid. set -eu here=$(cd "$(dirname "$0")" && pwd) work=$(mktemp -d) trap 'rm -rf "$work"' EXIT mkdir -p "$work/bin" cat > "$work/bin/systemctl" <<'STUB' #!/bin/sh echo "$@" >> "$ROUSED_LOG" STUB chmod +x "$work/bin/systemctl" export PATH="$work/bin:$PATH" export ROUSED_LOG="$work/rousings" : > "$ROUSED_LOG" for event in up dhcp4-change connectivity-change routes-change; do sh "$here/nox-mesh-host-network.sh" wlan0 "$event" done count=$(grep -c "nox-mesh-host-roused" "$ROUSED_LOG" || true) if [ "$count" -ne 4 ]; then echo "FAIL: four events that change where packets go roused $count time(s)" >&2 exit 1 fi : > "$ROUSED_LOG" for event in down pre-up hostname ""; do sh "$here/nox-mesh-host-network.sh" wlan0 "$event" done if [ -s "$ROUSED_LOG" ]; then echo "FAIL: an event that does not change where packets go roused the host:" >&2 cat "$ROUSED_LOG" >&2 exit 1 fi echo "the dispatcher rouses on route changes and nothing else"