freedombone-app-batman 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #!/bin/bash
  2. # _____ _ _
  3. # | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
  4. # | __| _| -_| -_| . | . | | . | . | | -_|
  5. # |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___|
  6. #
  7. # Freedom in the Cloud
  8. #
  9. # batman adv mesh functions
  10. #
  11. # License
  12. # =======
  13. #
  14. # Copyright (C) 2014-2018 Bob Mottram <bob@freedombone.net>
  15. #
  16. # This program is free software: you can redistribute it and/or modify
  17. # it under the terms of the GNU Affero General Public License as published by
  18. # the Free Software Foundation, either version 3 of the License, or
  19. # (at your option) any later version.
  20. #
  21. # This program is distributed in the hope that it will be useful,
  22. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. # GNU Affero General Public License for more details.
  25. #
  26. # You should have received a copy of the GNU Affero General Public License
  27. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  28. VARIANTS=''
  29. IN_DEFAULT_INSTALL=0
  30. SHOW_ON_ABOUT=0
  31. ENABLE_BATMAN="no"
  32. BATMAN_CELLID='any'
  33. batman_variables=(MY_USERNAME
  34. BATMAN_CELLID)
  35. function logging_on_batman {
  36. echo -n ''
  37. }
  38. function logging_off_batman {
  39. echo -n ''
  40. }
  41. function install_interactive_batman {
  42. echo -n ''
  43. APP_INSTALLED=1
  44. }
  45. function configure_firewall_for_batman {
  46. if [[ $(is_completed "${FUNCNAME[0]}") == "1" ]]; then
  47. return
  48. fi
  49. if [[ $ENABLE_BATMAN != "yes" ]]; then
  50. return
  51. fi
  52. function_check save_firewall_settings
  53. save_firewall_settings
  54. mark_completed "${FUNCNAME[0]}"
  55. }
  56. function reconfigure_batman {
  57. echo -n ''
  58. }
  59. function upgrade_batman {
  60. echo -n ''
  61. }
  62. function backup_local_batman {
  63. echo -n ''
  64. }
  65. function restore_local_batman {
  66. echo -n ''
  67. }
  68. function backup_remote_batman {
  69. echo -n ''
  70. }
  71. function restore_remote_batman {
  72. echo -n ''
  73. }
  74. function remove_batman {
  75. if ! "${PROJECT_NAME}-mesh-install" -f batman --remove yes; then
  76. echo $'Failed to remove batman'
  77. exit 79353
  78. fi
  79. remove_completion_param install_batman
  80. remove_completion_param configure_firewall_for_batman
  81. }
  82. function mesh_install_batman {
  83. # shellcheck disable=SC2154
  84. chroot "$rootdir" apt-get -yq install iproute bridge-utils libnetfilter-conntrack3 batctl
  85. chroot "$rootdir" apt-get -yq install python-dev libevent-dev ebtables python-pip git
  86. chroot "$rootdir" apt-get -yq install wireless-tools rfkill
  87. if ! grep -q "batman_adv" "$rootdir/etc/modules"; then
  88. echo 'batman_adv' >> "$rootdir/etc/modules"
  89. fi
  90. if ! grep -q "tunnel6" "$rootdir/etc/modules"; then
  91. echo 'tunnel6' >> "$rootdir/etc/modules"
  92. fi
  93. if ! grep -q "ip6_tunnel" "$rootdir/etc/modules"; then
  94. echo 'ip6_tunnel' >> "$rootdir/etc/modules"
  95. fi
  96. BATMAN_SCRIPT=$rootdir/var/lib/batman
  97. if [ -f "/usr/local/bin/${PROJECT_NAME}-mesh-batman" ]; then
  98. cp "/usr/local/bin/${PROJECT_NAME}-mesh-batman" "$BATMAN_SCRIPT"
  99. else
  100. cp "/usr/bin/${PROJECT_NAME}-mesh-batman" "$BATMAN_SCRIPT"
  101. fi
  102. BATMAN_DAEMON=$rootdir/etc/systemd/system/batman.service
  103. { echo '[Unit]';
  104. echo 'Description=B.A.T.M.A.N. Advanced';
  105. echo 'After=network.target';
  106. echo '';
  107. echo '[Service]';
  108. echo 'RemainAfterExit=yes';
  109. echo "ExecStart=/var/lib/batman start";
  110. echo "ExecStop=/var/lib/batman stop";
  111. echo 'Restart=on-failure';
  112. echo 'SuccessExitStatus=3 4';
  113. echo 'RestartForceExitStatus=3 4';
  114. echo '';
  115. echo '# Allow time for the server to start/stop';
  116. echo 'TimeoutSec=300';
  117. echo '';
  118. echo '[Install]';
  119. echo 'WantedBy=multi-user.target'; } > "$BATMAN_DAEMON"
  120. chroot "$rootdir" systemctl enable batman
  121. }
  122. function install_batman {
  123. if [ "$INSTALLING_MESH" ]; then
  124. mesh_install_batman
  125. return
  126. fi
  127. if [[ $ENABLE_BATMAN != "yes" ]]; then
  128. return
  129. fi
  130. if ! "${PROJECT_NAME}-mesh-install" -f batman; then
  131. echo $'Failed to install batman'
  132. exit 72524
  133. fi
  134. function_check configure_firewall_for_batman
  135. configure_firewall_for_batman
  136. APP_INSTALLED=1
  137. }
  138. # NOTE: deliberately no exit 0