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.

74 lines
1.7 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" 25
  14. echo_pad "IP" 25
  15. echo_pad "APP" 15
  16. echo_pad "VERSION" 15
  17. echo_pad "DEVICE" 30
  18. echo_pad "MEM_SIZE" 10
  19. echo_pad "SDK_SIZE" 10
  20. echo
  21. printf -v line '%*s\n' 134
  22. echo ${line// /-}
  23. counter=0
  24. avahi-browse -t -r -p "_arduino._tcp" 2>/dev/null | grep ^= | sort -t ';' -k 3 | while read line; do
  25. (( counter++ ))
  26. hostname=`echo $line | cut -d ';' -f4`
  27. ip=`echo $line | cut -d ';' -f8`
  28. txt=`echo $line | cut -d ';' -f10`
  29. app_name=`echo $txt | sed -n "s/.*app_name=\([^\"]*\).*/\1/p"`
  30. app_version=`echo $txt | sed -n "s/.*app_version=\([^\"]*\).*/\1/p"`
  31. board=`echo $txt | sed -n "s/.*target_board=\([^\"]*\).*/\1/p"`
  32. mem_size=`echo $txt | sed -n "s/.*mem_size=\([^\"]*\).*/\1/p"`
  33. sdk_size=`echo $txt | sed -n "s/.*sdk_size=\([^\"]*\).*/\1/p"`
  34. echo_pad "$counter" 4
  35. echo_pad "$hostname" 25
  36. echo_pad "http://$ip" 25
  37. echo_pad "$app_name" 15
  38. echo_pad "$app_version" 15
  39. echo_pad "$board" 30
  40. echo_pad "$mem_size" 10
  41. echo_pad "$sdk_size" 10
  42. echo
  43. done
  44. echo
  45. }
  46. # ------------------------------------------------------------------------------
  47. # Welcome
  48. echo
  49. echo "--------------------------------------------------------------"
  50. echo "OTA-UPDATABLE DEVICES"
  51. echo "--------------------------------------------------------------"
  52. echo
  53. if exists avahi-browse; then
  54. useAvahi
  55. else
  56. echo "Avahi not installed"
  57. exit 1
  58. fi