freedombone-app-batman 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. BATMAN_SCRIPT=$rootdir/var/lib/batman
  91. if [ -f "/usr/local/bin/${PROJECT_NAME}-mesh-batman" ]; then
  92. cp "/usr/local/bin/${PROJECT_NAME}-mesh-batman" "$BATMAN_SCRIPT"
  93. else
  94. cp "/usr/bin/${PROJECT_NAME}-mesh-batman" "$BATMAN_SCRIPT"
  95. fi
  96. BATMAN_DAEMON=$rootdir/etc/systemd/system/batman.service
  97. { echo '[Unit]';
  98. echo 'Description=B.A.T.M.A.N. Advanced';
  99. echo 'After=network.target';
  100. echo '';
  101. echo '[Service]';
  102. echo 'RemainAfterExit=yes';
  103. echo "ExecStart=/var/lib/batman start";
  104. echo "ExecStop=/var/lib/batman stop";
  105. echo 'Restart=on-failure';
  106. echo 'SuccessExitStatus=3 4';
  107. echo 'RestartForceExitStatus=3 4';
  108. echo '';
  109. echo '# Allow time for the server to start/stop';
  110. echo 'TimeoutSec=300';
  111. echo '';
  112. echo '[Install]';
  113. echo 'WantedBy=multi-user.target'; } > "$BATMAN_DAEMON"
  114. chroot "$rootdir" systemctl enable batman
  115. }
  116. function install_batman {
  117. if [ "$INSTALLING_MESH" ]; then
  118. mesh_install_batman
  119. return
  120. fi
  121. if [[ $ENABLE_BATMAN != "yes" ]]; then
  122. return
  123. fi
  124. if ! "${PROJECT_NAME}-mesh-install" -f batman; then
  125. echo $'Failed to install batman'
  126. exit 72524
  127. fi
  128. function_check configure_firewall_for_batman
  129. configure_firewall_for_batman
  130. APP_INSTALLED=1
  131. }
  132. # NOTE: deliberately no exit 0