Browse Source

Set up batman_adv kernel module in desired version.

  This state installs the batman_adv DKMS package from repo.universe-factory.net
  and makes sure the desired version is compiled and loaded after install and
  at boot time (possibly after a kernel upgrade).

Signed-off-by: Maximilian Wilhelm <max@rfc2324.org>
Maximilian Wilhelm 8 years ago
parent
commit
adae2477bb
4 changed files with 182 additions and 0 deletions
  1. 5 0
      batman/batman-adv.module.conf
  2. 70 0
      batman/ff_fix_batman
  3. 14 0
      batman/ff_fix_batman.service
  4. 93 0
      batman/init.sls

+ 5 - 0
batman/batman-adv.module.conf

@@ -0,0 +1,5 @@
+#
+# Load batman-adv module on system boot (Salt managed)
+#
+batman-adv
+dummy

+ 70 - 0
batman/ff_fix_batman

@@ -0,0 +1,70 @@
+#!/bin/sh
+#
+# Maximilian Wilhelm <max@rfc2324.org>
+#  --  Thu 07 Jul 2016 03:28:44 PM CEST
+#
+# Make sure that the correct B.A.T.M.A.N version is installed on this machine,
+# reconfigure batman interfaces and restart services depending on batman (alfred
+# and fastd). Beware that this restarts ALL fastd instances. As we are only using
+# fastd for batman'ish things currently, that's fine.
+#
+
+batman_version_wanted="2013.4.0"
+
+# Bail on error
+set -e
+
+only_fix_module=false
+if [ "$1" = "--only-fix-module" ]; then
+	only_fix_module=true
+fi
+export only_fix_module
+
+batman_version_installed=$(modinfo batman-adv | awk -F: '/^version:/ { print $2 }' | tr -d '[:space:]')
+my_name="ff_fix_batman"
+logfile="/var/log/ff_fix_batman-$(date +%Y.%m.%d-%H:%M).log"
+
+if [ "${batman_version_wanted}" = "${batman_version_installed}" ]; then
+	msg="Version ${batman_version_wanted} of batman-adv already installed."
+	echo ${msg}
+	logger -t "${my_name}" "${msg}"
+	exit 0
+fi
+
+msg="Version ${batman_version_wanted} of batman-adv wanted, but ${batman_version_installed} found. Fixing, see ${logfile} for details."
+echo "${msg}"
+logger -t "${my_name}" "${msg}"
+
+(
+
+# Be safe and shutdown all batman interfaces before removing the module
+for iface in $(ip l | awk -F: '/^[0-9]/ { print $2 }' | tr -d ' ' | grep ^bat); do
+	ifdown "${iface}"
+done
+
+if lsmod | grep batman-adv; then
+	rmmod batman-adv
+fi
+
+dkms remove  "batman-adv/${batman_version_wanted}" --all || true
+dkms install "batman-adv/${batman_version_wanted}" --force
+
+# Load the newly compiled B.A.T.M.A.N. module
+modprobe batman-adv
+
+if [ ! "${only_fix_module}" ]; then
+	# Configure all B.A.T.M.A.N. broken before
+	ifup -a
+	
+	# Restart fastd, if installed
+	if dpkg -l fastd >/dev/null 2>/dev/null; then
+		service fastd restart
+	fi
+	
+	# Restart alfred, if installed
+	if dpkg -l alfred >/dev/null 2>/dev/null; then
+		service alfred restart
+	fi
+fi
+
+) >>"${logfile}" 2>>"${logfile}"

+ 14 - 0
batman/ff_fix_batman.service

@@ -0,0 +1,14 @@
+[Unit]
+Description=Fix B.A.T.M.A.N. Kernel module version
+ConditionFileIsExecutable=/usr/local/sbin/ff_fix_batman
+Before=network.target
+
+[Service]
+Type=forking
+ExecStart=/usr/local/sbin/ff_fix_batman --only-fix-module
+TimeoutSec=0
+RemainAfterExit=yes
+SysVStartPriority=99
+
+[Install]
+WantedBy=multi-user.target

+ 93 - 0
batman/init.sls

@@ -0,0 +1,93 @@
+#
+# Set up B.A.T.M.A.N. module 'n stuff
+#
+
+#
+# Only set up batman and load batman_adv kernel module if the role »batman«
+# has been configured for this node.
+#
+{%- if 'batman' in salt['pillar.get']('nodes:' ~ grains['id']  ~ ':roles', ()) %}
+include:
+  - apt
+
+batman-adv-dkms:
+  pkg.installed:
+    - require:
+      - pkgrepo: apt-neoraider
+
+batctl:
+  pkg.installed:
+    - require:
+      - pkgrepo: apt-neoraider
+
+
+# The ff_fix_batman script ensures that the preferred (currently older) version
+# of the batman_adv kernel module is compiled via DKMS and installed into the
+# system.
+/usr/local/sbin/ff_fix_batman:
+  file.managed:
+    - source: salt://batman/ff_fix_batman
+    - user: root
+    - group: root
+    - mode: 744
+    - require:
+      - pkg: batctl
+
+ff_fix_batman:
+  cmd.wait:
+    - name: /usr/local/sbin/ff_fix_batman
+    - require:
+      - file: /usr/local/sbin/ff_fix_batman
+    - watch:
+      - pkg: batman-adv-dkms
+
+
+# Install and enable a ff-fix-batman service which runs at boot time
+# to fix the kernel module after a kernel upgrade + reboot if neccessary.
+/lib/systemd/system/ff-fix-batman.service:
+  file.managed:
+    - source: salt://batman/ff_fix_batman.service
+    - user: root
+    - group: root
+    - mode: 644
+    - require:
+      - file: /usr/local/sbin/ff_fix_batman
+
+enable-ff-fix-batman-service:
+  service.enabled:
+    - name: ff-fix-batman
+    - require:
+      - file: /lib/systemd/system/ff-fix-batman.service
+
+
+# Make sure the batman_adv module is loaded at boot time
+/etc/modules-load.d/batman-adv.conf:
+  file.managed:
+      - source: salt://batman/batman-adv.module.conf
+
+
+#
+# If the role »batman» is NOT configured for this node, make sure to purge any
+# traces of a previous installation, if present.
+#
+{% else %}
+
+batctl:
+  pkg.purged
+
+batman-adv-dkms:
+  pkg.purged
+
+/usr/local/sbin/ff_fix_batman:
+  file.absent
+
+disable-ff-fix-batman-service:
+  service.disabled:
+    - name: ff-fix-batman
+
+/lib/systemd/system/ff-fix-batman.service:
+  file.absent
+
+/etc/modules-load.d/batman-adv.conf:
+  file.absent
+{% endif %}