announce.sh 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #!/bin/sh
  2. if [ -f /lib/functions/jshn.sh ]; then
  3. . /lib/functions/jshn.sh
  4. elif [ -f /usr/share/libubox/jshn.sh ]; then
  5. . /usr/share/libubox/jshn.sh
  6. else
  7. echo "Error: jshn.sh not found!"
  8. exit 1
  9. fi
  10. . /lib/gluon/functions/model.sh
  11. . /lib/gluon/functions/sysconfig.sh
  12. # set defaults
  13. [ -z "$ALFRED_DATA_TYPE" ] && ALFRED_DATA_TYPE=158
  14. [ -z "$NET_IF" ] && NET_IF=br-client
  15. set -e
  16. json_init
  17. json_add_string "hostname" "$(uci get 'system.@system[0].hostname')"
  18. if [ "$(uci -q get 'gluon-node-info.@location[0].share_location')" = 1 ]; then
  19. json_add_object "location"
  20. json_add_double "latitude" "$(uci get 'gluon-node-info.@location[0].latitude')"
  21. json_add_double "longitude" "$(uci get 'gluon-node-info.@location[0].longitude')"
  22. json_close_object # location
  23. fi
  24. if [ -n "$(uci -q get 'gluon-node-info.@owner[0].contact')" ]; then
  25. json_add_object "owner"
  26. json_add_string "contact" "$(uci get 'gluon-node-info.@owner[0].contact')"
  27. json_close_object # owner
  28. fi
  29. json_add_object "software"
  30. json_add_object "firmware"
  31. json_add_string "base" "gluon-$(cat /lib/gluon/gluon-version)"
  32. json_add_string "release" "$(cat /lib/gluon/release)"
  33. json_close_object # firmware
  34. if [ -x /usr/sbin/autoupdater ]; then
  35. json_add_object "autoupdater"
  36. json_add_string "branch" "$(uci -q get autoupdater.settings.branch)"
  37. json_add_boolean "enabled" "$(uci -q get autoupdater.settings.enabled)"
  38. json_close_object # autoupdater
  39. fi
  40. if [ -x /usr/bin/fastd ]; then
  41. json_add_object "fastd"
  42. json_add_string "version" "$(fastd -v | cut -d' ' -f2)"
  43. json_add_boolean "enabled" "$(uci -q get fastd.mesh_vpn.enabled)"
  44. json_close_object # fastd
  45. fi
  46. json_close_object # software
  47. json_add_object "hardware"
  48. json_add_string "model" "$(get_model)"
  49. json_close_object # hardware
  50. json_add_object "network"
  51. json_add_string "mac" "$(sysconfig primary_mac)"
  52. json_add_array "addresses"
  53. for addr in $(ip -o -6 addr show dev "$NET_IF" | grep -oE 'inet6 [0-9a-fA-F:]+' | cut -d' ' -f2); do
  54. json_add_string "" "$addr"
  55. done
  56. json_close_array # adresses
  57. GATEWAY="$(batctl -m bat0 gateways | awk '/^=>/ { print $2 }')"
  58. [ -z "$GATEWAY" ] || json_add_string "gateway" "$GATEWAY"
  59. json_close_object # network
  60. json_add_object "statistics"
  61. json_add_int "uptime" "$(cut -d' ' -f1 /proc/uptime)"
  62. json_add_double "loadavg" "$(cut -d' ' -f1 /proc/loadavg)"
  63. json_add_object "traffic"
  64. TRAFFIC="$(ethtool -S bat0 | sed -e 's/^ *//')"
  65. for class in rx tx forward mgmt_rx mgmt_tx; do
  66. json_add_object "$class"
  67. json_add_int "bytes" "$(echo "$TRAFFIC" | awk -F': ' "/^${class}_bytes:/ { print \$2 }")"
  68. json_add_int "packets" "$(echo "$TRAFFIC" | awk -F': ' "/^${class}:/ { print \$2 }")"
  69. if [ "$class" = "tx" ]; then
  70. json_add_int "dropped" "$(echo "$TRAFFIC" | awk -F': ' "/^${class}_dropped:/ { print \$2 }")"
  71. fi
  72. json_close_object # $class
  73. done
  74. json_close_object # traffic
  75. json_close_object # statistics
  76. json_dump | tr -d '\n' | alfred -s "$ALFRED_DATA_TYPE"