freedombone-app-batman 4.2KB

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