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.

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