freedombone-app-batman 4.1KB

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