01-wifi 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/bin/sh
  2. # WiFi hotplug script - triggers on wireless events
  3. # Install to /etc/hotplug.d/wireless/
  4. #
  5. # Events emitted (must match client2server-unified.lua's handler):
  6. # wifi_connected / wifi_disconnected
  7. #
  8. # Events are spooled to /var/run/client2server/buffer and the Lua agent
  9. # is woken via SIGHUP. If the agent is offline (internet down), events
  10. # accumulate on disk and are flushed on reconnect.
  11. SCRIPT_DIR="$(dirname "$0")"
  12. # Source the shared lib from its canonical install location.
  13. # Falls back to the development path (hotplug/_lib.sh) for tests.
  14. if [ -f /usr/share/client2server/hotplug-lib.sh ]; then
  15. # shellcheck disable=SC1091
  16. . /usr/share/client2server/hotplug-lib.sh
  17. elif [ -f "$SCRIPT_DIR/_lib.sh" ]; then
  18. # shellcheck disable=SC1091
  19. . "$SCRIPT_DIR/_lib.sh"
  20. else
  21. logger -t client2server-hotplug -p user.err "hotplug-lib.sh not found"
  22. exit 1
  23. fi
  24. case "$ACTION" in
  25. associate|associated)
  26. if [ -n "$MACADDR" ]; then
  27. log_msg "WiFi CONNECTED: $MACADDR on $INTERFACE"
  28. send_event "wifi_connected" \
  29. "{\"mac\":\"$MACADDR\",\"interface\":\"$INTERFACE\"}"
  30. fi
  31. ;;
  32. disassociate|disassociated|deauth|expired)
  33. if [ -n "$MACADDR" ]; then
  34. log_msg "WiFi DISCONNECTED: $MACADDR on $INTERFACE"
  35. send_event "wifi_disconnected" \
  36. "{\"mac\":\"$MACADDR\",\"interface\":\"$INTERFACE\"}"
  37. fi
  38. ;;
  39. esac