#!/bin/sh
# systemd makes /usr read-only in the initrd (ProtectSystem=auto), so the
# new module indexes are generated in /run and bind mounted over the old
set -e
kver="$1"
moddir="/usr/lib/modules/$kver"
out=/run/uki-addon-depmod
depmod -o "$out" "$kver"
test -d "$out$moddir"
for f in "$out$moddir"/modules.*; do
	t="$moddir/${f##*/}"
	[ -e "$t" ] || continue
	mount --bind "$f" "$t"
done
