Fork of the espurna firmware for `mhsw` switches
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.3 KiB

  1. #!/bin/bash
  2. exists() {
  3. command -v "$1" >/dev/null 2>&1
  4. }
  5. echo_pad() {
  6. string=$1
  7. pad=$2
  8. printf '%s' "$string"
  9. printf '%*s' $(( $pad - ${#string} ))
  10. }
  11. useAvahi() {
  12. echo_pad "#" 4
  13. echo_pad "HOSTNAME" 20
  14. echo_pad "IP" 20
  15. echo_pad "DEVICE" 30
  16. echo_pad "VERSION" 10
  17. echo
  18. printf -v line '%*s\n' 84
  19. echo ${line// /-}
  20. counter=0
  21. avahi-browse -t -r -p "_arduino._tcp" 2>/dev/null | grep ^= | sort -t ';' -k 3 | while read line; do
  22. (( counter++ ))
  23. hostname=`echo $line | cut -d ';' -f4`
  24. ip=`echo $line | cut -d ';' -f8`
  25. txt=`echo $line | cut -d ';' -f10`
  26. board=`echo $txt | sed -n "s/.*espurna_board=\([^\"]*\).*/\1/p"`
  27. version=`echo $txt | sed -n "s/.*espurna_version=\([^\"]*\).*/\1/p"`
  28. echo_pad "$counter" 4
  29. echo_pad "$hostname" 20
  30. echo_pad "$ip" 20
  31. echo_pad "$board" 30
  32. echo_pad "$version" 10
  33. echo
  34. done
  35. echo
  36. }
  37. # ------------------------------------------------------------------------------
  38. # Welcome
  39. echo
  40. echo "--------------------------------------------------------------"
  41. echo "OTA-UPDATABLE DEVICES"
  42. echo "--------------------------------------------------------------"
  43. echo
  44. if exists avahi-browse; then
  45. useAvahi
  46. else
  47. echo "Avahi not installed"
  48. exit 1
  49. fi