freedombone-mesh 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # A script to easily locate mesh peers and start communicating
  12. # License
  13. # =======
  14. #
  15. # Copyright (C) 2015 Bob Mottram <bob@robotics.uk.to>
  16. #
  17. # This program is free software: you can redistribute it and/or modify
  18. # it under the terms of the GNU General Public License as published by
  19. # the Free Software Foundation, either version 3 of the License, or
  20. # (at your option) any later version.
  21. #
  22. # This program is distributed in the hope that it will be useful,
  23. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. # GNU General Public License for more details.
  26. #
  27. # You should have received a copy of the GNU General Public License
  28. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  29. IRC_PORT=6697
  30. PEERS_FILE=/tmp/meshpeers.txt
  31. avahi-browse -at | awk -F ' ' '{print $4}' > $PEERS_FILE
  32. if [ ! -f $PEERS_FILE ]; then
  33. echo 'No peers were found'
  34. exit 0
  35. fi
  36. ctr=0
  37. while IFS='' read -r line || [[ -n "$line" ]]; do
  38. ctr=$((ctr + 1))
  39. done < "$PEERS_FILE"
  40. if [ ${ctr} -lt "2" ]; then
  41. echo 'No peers were found'
  42. exit 0
  43. fi
  44. echo 'Choose a peer to connect to:'
  45. idx=1
  46. while IFS='' read -r line || [[ -n "$line" ]]; do
  47. echo " $idx. $line"
  48. idx=$((idx + 1))
  49. done < "$PEERS_FILE"
  50. peer_index=0
  51. read peer_index
  52. # get the avahi domain name
  53. AVAHI_DOMAIN=
  54. idx=1
  55. while IFS='' read -r line || [[ -n "$line" ]]; do
  56. if [ ${idx} -eq "$peer_index" ]; then
  57. AVAHI_DOMAIN=${line}.local
  58. fi
  59. idx=$((idx + 1))
  60. done < "$PEERS_FILE"
  61. if [ ! $AVAHI_DOMAIN ]; then
  62. echo 'No domain name'
  63. exit 2
  64. fi
  65. # Connect to IRC
  66. if [ ! -f /usr/bin/irssi ]; then
  67. if [ ! -f /usr/local/bin/irssi ]; then
  68. echo 'You need irssi installed on your system'
  69. exit 3
  70. fi
  71. fi
  72. irssi -c $AVAHI_DOMAIN -p $IRC_PORT -n $USER
  73. exit 0