ff_fix_batman 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/bin/sh
  2. #
  3. # Maximilian Wilhelm <max@rfc2324.org>
  4. # -- Thu 07 Jul 2016 03:28:44 PM CEST
  5. #
  6. # Make sure that the correct B.A.T.M.A.N version is installed on this machine,
  7. # reconfigure batman interfaces and restart services depending on batman (alfred
  8. # and fastd). Beware that this restarts ALL fastd instances. As we are only using
  9. # fastd for batman'ish things currently, that's fine.
  10. #
  11. batman_version_wanted="2013.4.0"
  12. # Bail on error
  13. set -e
  14. only_fix_module=false
  15. if [ "$1" = "--only-fix-module" ]; then
  16. only_fix_module=true
  17. fi
  18. export only_fix_module
  19. batman_version_installed=$(modinfo batman-adv | awk -F: '/^version:/ { print $2 }' | tr -d '[:space:]')
  20. my_name="ff_fix_batman"
  21. logfile="/var/log/ff_fix_batman-$(date +%Y.%m.%d-%H:%M).log"
  22. if [ "${batman_version_wanted}" = "${batman_version_installed}" ]; then
  23. msg="Version ${batman_version_wanted} of batman-adv already installed."
  24. echo ${msg}
  25. logger -t "${my_name}" "${msg}"
  26. exit 0
  27. fi
  28. msg="Version ${batman_version_wanted} of batman-adv wanted, but ${batman_version_installed} found. Fixing, see ${logfile} for details."
  29. echo "${msg}"
  30. logger -t "${my_name}" "${msg}"
  31. (
  32. # Be safe and shutdown all batman interfaces before removing the module
  33. for iface in $(ip l | awk -F: '/^[0-9]/ { print $2 }' | tr -d ' ' | grep ^bat); do
  34. ifdown "${iface}" || true
  35. done
  36. if lsmod | grep batman-adv; then
  37. rmmod batman-adv
  38. fi
  39. dkms remove "batman-adv/${batman_version_wanted}" --all || true
  40. dkms install "batman-adv/${batman_version_wanted}" --force
  41. # Load the newly compiled B.A.T.M.A.N. module
  42. modprobe batman-adv
  43. if [ ! "${only_fix_module}" ]; then
  44. # Configure all B.A.T.M.A.N. broken before
  45. ifup -a
  46. # Restart fastd, if installed
  47. if dpkg -l fastd >/dev/null 2>/dev/null; then
  48. service fastd restart
  49. fi
  50. # Restart alfred, if installed
  51. if dpkg -l alfred >/dev/null 2>/dev/null; then
  52. service alfred restart
  53. fi
  54. fi
  55. ) >>"${logfile}" 2>>"${logfile}"