freedombone-meshweb 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Web interface for the mesh
  12. #
  13. # License
  14. # =======
  15. #
  16. # Copyright (C) 2015-2016 Bob Mottram <bob@robotics.uk.to>
  17. #
  18. # This program is free software: you can redistribute it and/or modify
  19. # it under the terms of the GNU Affero General Public License as published by
  20. # the Free Software Foundation, either version 3 of the License, or
  21. # (at your option) any later version.
  22. #
  23. # This program is distributed in the hope that it will be useful,
  24. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. # GNU Affero General Public License for more details.
  27. #
  28. # You should have received a copy of the GNU Affero General Public License
  29. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  30. PROJECT_NAME='freedombone'
  31. export TEXTDOMAIN=${PROJECT_NAME}-meshweb
  32. export TEXTDOMAINDIR="/usr/share/locale"
  33. MESH_INSTALL_DIR=/var/lib
  34. PEERS_FILE=/tmp/meshwebstart
  35. if [ -d $MESH_INSTALL_DIR/zeronet ]; then
  36. ZERONET_DIR=$MESH_INSTALL_DIR/zeronet
  37. fi
  38. avahi-browse -atl | awk -F ' ' '{print $4}' | sort -u > $PEERS_FILE
  39. if [ ! -f $PEERS_FILE ]; then
  40. echo $'No peers were found'
  41. exit 0
  42. fi
  43. # count the peers
  44. ctr=0
  45. while IFS='' read -r line || [[ -n "$line" ]]; do
  46. ctr=$((ctr + 1))
  47. done < "$PEERS_FILE"
  48. rm $PEERS_FILE
  49. # enough peers
  50. if [ ${ctr} -lt "1" ]; then
  51. echo $'No peers were found'
  52. exit 0
  53. fi
  54. ZERONET_INDEX=$MESH_INSTALL_DIR/zeronet/mesh.html
  55. if which firefox > /dev/null; then
  56. firefox $ZERONET_INDEX
  57. elif which midori > /dev/null; then
  58. midori $ZERONET_INDEX
  59. elif which iceweasel > /dev/null; then
  60. iceweasel $ZERONET_INDEX
  61. elif which chrome > /dev/null; then
  62. chrome $ZERONET_INDEX
  63. elif which chromium > /dev/null; then
  64. chromium $ZERONET_INDEX
  65. elif which xdg-open > /dev/null; then
  66. xdg-open $ZERONET_INDEX
  67. elif which gnome-open > /dev/null; then
  68. gnome-open $ZERONET_INDEX
  69. fi
  70. exit 0