#!/bin/sh -e

KREL=$1

{ cat /lib/modules/$KREL/modules.dep ;
cat /lib/modules/$KREL/modules.softdep | grep : | sed -e 's/^softdep //' -e 's/ \(pre\|post\):/:/' ; } \
	    | \
while read l ; do
	MOD=$(echo "$l" | sed -e 's/:.*//')
	MOD=$(basename $MOD)
	case $MOD in
	    *.ko.xz|*.ko.gz|*.ko.zst)
		MOD=${MOD%.*};;
	esac
	MOD=${MOD%.ko}
	DEPS="$(echo "$l" | sed -e 's/.*://')"
	moddeps=""
	for dep in $DEPS ; do
		dep=$(basename $dep)
		case $dep in
		    *.ko.xz|*.ko.gz|*.ko.zst)
			dep=${dep%.*};;
		esac
		dep=${dep%.ko}
		moddeps="$moddeps $dep"
	done
	[ -n "$moddeps" ] && echo $MOD:$moddeps ||:
done
