freedombone-app-babel 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Babel mesh functions
  12. #
  13. # License
  14. # =======
  15. #
  16. # Copyright (C) 2014-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. # Babel mesh
  31. ENABLE_BABEL="no"
  32. BABEL_PORT=6696
  33. function remove_babel {
  34. if ! grep -Fxq "mesh_babel" $COMPLETION_FILE; then
  35. return
  36. fi
  37. ${PROJECT_NAME}-mesh-install -f babel --remove yes
  38. if [ ! "$?" = "0" ]; then
  39. echo $'Failed to remove babel'
  40. exit 83658
  41. fi
  42. iptables -D INPUT -i $WIFI_INTERFACE -p udp --dport $BABEL_PORT -j ACCEPT
  43. function_check save_firewall_settings
  44. save_firewall_settings
  45. sed -i '/mesh_babel/d' $COMPLETION_FILE
  46. sed -i '/configure_firewall_for_babel/d' $COMPLETION_FILE
  47. }
  48. function configure_firewall_for_babel {
  49. if grep -Fxq "configure_firewall_for_babel" $COMPLETION_FILE; then
  50. return
  51. fi
  52. if [[ $ENABLE_BABEL != "yes" ]]; then
  53. return
  54. fi
  55. iptables -A INPUT -i $WIFI_INTERFACE -p udp --dport $BABEL_PORT -j ACCEPT
  56. function_check save_firewall_settings
  57. save_firewall_settings
  58. OPEN_PORTS+=("Babel $BABEL_PORT")
  59. echo 'configure_firewall_for_babel' >> $COMPLETION_FILE
  60. }
  61. function mesh_babel {
  62. if grep -Fxq "mesh_babel" $COMPLETION_FILE; then
  63. return
  64. fi
  65. if [[ $ENABLE_BABEL != "yes" ]]; then
  66. return
  67. fi
  68. ${PROJECT_NAME}-mesh-install -f babel
  69. if [ ! "$?" = "0" ]; then
  70. echo $'Failed to install babel'
  71. exit 67242
  72. fi
  73. function_check configure_firewall_for_babel
  74. configure_firewall_for_babel
  75. echo 'mesh_babel' >> $COMPLETION_FILE
  76. }
  77. # NOTE: deliberately there is no "exit 0"