freedombone-app-batman 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # batman adv 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. VARIANTS='mesh'
  31. ENABLE_BATMAN="no"
  32. BATMAN_CELLID='any'
  33. function configure_firewall_for_batma {
  34. if grep -Fxq "configure_firewall_for_batman" $COMPLETION_FILE; then
  35. return
  36. fi
  37. if [[ $ENABLE_BATMAN != "yes" ]]; then
  38. return
  39. fi
  40. function_check save_firewall_settings
  41. save_firewall_settings
  42. echo 'configure_firewall_for_batman' >> $COMPLETION_FILE
  43. }
  44. function reconfigure_batman {
  45. echo -n ''
  46. }
  47. function upgrade_batman {
  48. echo -n ''
  49. }
  50. function backup_local_batman {
  51. echo -n ''
  52. }
  53. function restore_local_batman {
  54. echo -n ''
  55. }
  56. function backup_remote_batman {
  57. echo -n ''
  58. }
  59. function restore_remote_batman {
  60. echo -n ''
  61. }
  62. function remove_batman {
  63. if ! grep -Fxq "install_batman" $COMPLETION_FILE; then
  64. return
  65. fi
  66. ${PROJECT_NAME}-mesh-install -f batman --remove yes
  67. if [ ! "$?" = "0" ]; then
  68. echo $'Failed to remove batman'
  69. exit 79353
  70. fi
  71. sed -i '/install_batman/d' $COMPLETION_FILE
  72. sed -i '/configure_firewall_for_batman/d' $COMPLETION_FILE
  73. }
  74. function mesh_install_batman {
  75. chroot "$rootdir" apt-get -y install iproute bridge-utils libnetfilter-conntrack3 batctl
  76. chroot "$rootdir" apt-get -y install python-dev libevent-dev ebtables python-pip git
  77. chroot "$rootdir" apt-get -y install wireless-tools rfkill
  78. if ! grep -q "batman_adv" $rootdir/etc/modules; then
  79. echo 'batman_adv' >> $rootdir/etc/modules
  80. fi
  81. BATMAN_SCRIPT=$rootdir/var/lib/batman
  82. if [ -f /usr/local/bin/${PROJECT_NAME}-mesh-batman ]; then
  83. cp /usr/local/bin/${PROJECT_NAME}-mesh-batman $BATMAN_SCRIPT
  84. else
  85. cp /usr/bin/${PROJECT_NAME}-mesh-batman $BATMAN_SCRIPT
  86. fi
  87. BATMAN_DAEMON=$rootdir/etc/systemd/system/batman.service
  88. echo '[Unit]' > $BATMAN_DAEMON
  89. echo 'Description=B.A.T.M.A.N. Advanced' >> $BATMAN_DAEMON
  90. echo 'After=network.target' >> $BATMAN_DAEMON
  91. echo '' >> $BATMAN_DAEMON
  92. echo '[Service]' >> $BATMAN_DAEMON
  93. echo 'RemainAfterExit=yes' >> $BATMAN_DAEMON
  94. echo "ExecStart=/var/lib/batman start" >> $BATMAN_DAEMON
  95. echo "ExecStop=/var/lib/batman stop" >> $BATMAN_DAEMON
  96. echo 'Restart=on-failure' >> $BATMAN_DAEMON
  97. echo 'SuccessExitStatus=3 4' >> $BATMAN_DAEMON
  98. echo 'RestartForceExitStatus=3 4' >> $BATMAN_DAEMON
  99. echo '' >> $BATMAN_DAEMON
  100. echo '# Allow time for the server to start/stop' >> $BATMAN_DAEMON
  101. echo 'TimeoutSec=300' >> $BATMAN_DAEMON
  102. echo '' >> $BATMAN_DAEMON
  103. echo '[Install]' >> $BATMAN_DAEMON
  104. echo 'WantedBy=multi-user.target' >> $BATMAN_DAEMON
  105. chroot "$rootdir" systemctl enable batman
  106. }
  107. function install_batman {
  108. if [ $INSTALLING_MESH ]; then
  109. mesh_install_batman
  110. return
  111. fi
  112. if grep -Fxq "install_batman" $COMPLETION_FILE; then
  113. return
  114. fi
  115. if [[ $ENABLE_BATMAN != "yes" ]]; then
  116. return
  117. fi
  118. ${PROJECT_NAME}-mesh-install -f batman
  119. if [ ! "$?" = "0" ]; then
  120. echo $'Failed to install batman'
  121. exit 72524
  122. fi
  123. if ! grep -q "Mesh Networking (B.A.T.M.A.N)" /home/$MY_USERNAME/README; then
  124. echo '' >> /home/$MY_USERNAME/README
  125. echo '' >> /home/$MY_USERNAME/README
  126. echo 'Mesh Networking (B.A.T.M.A.N)' >> /home/$MY_USERNAME/README
  127. echo '=============================' >> /home/$MY_USERNAME/README
  128. echo "Mesh ESSID: $WIFI_SSID" >> /home/$MY_USERNAME/README
  129. echo "Mesh cell ID: $BATMAN_CELLID" >> /home/$MY_USERNAME/README
  130. echo "Mesh wifi channel: $WIFI_CHANNEL" >> /home/$MY_USERNAME/README
  131. chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
  132. chmod 600 /home/$MY_USERNAME/README
  133. fi
  134. function_check configure_firewall_for_batman
  135. configure_firewall_for_batman
  136. echo 'install_batman' >> $COMPLETION_FILE
  137. }
  138. # NOTE: deliberately no exit 0