freedombone-app-batman 4.1KB

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