# The kernel version is stored in a question-mark field
# separator format, like "2?4?26?rc3?gentoo?r2?1", where the
# final 1 is the build number.
#
local KV=kernel-$(uname -rv | awk '{gsub("[.\\-#]","?"); print $1$2}')

# This weird format acts here as a wilcard pattern. The
# purpose is to find a file whose name is at least part of
# our kernel version.
#
while [ ! $(ls /etc/modules.autoload.d/${KV} 2>/dev/null) ]
do
# Let's drop the last field in the version number
# to check if the corresponding file exists
#
KV_reduced=$(echo ${KV} | awk '{sub("\\?[^\\?]*$",""); print}')

# If we tried all the possibilities unsucessfully,
# then fallback with the ligther name (hopefully the
# most general, like kernel-2.4) and print a warning.
#
if [ ${KV_reduced} == ${KV} ]
then
KV=$(ls -1 /etc/modules.autoload.d/ | awk '{if(!drop)print;drop++}')
ewarn "Missing /etc/modules.autoload.d/kernel-VERSION"
break
fi

KV=${KV_reduced}
done

# Now we have found the file with the closest name, we just
# need to load the modules it lists. Note that if
# /etc/modules.autoload.d/ is empty, KV is an empty string.
#
[ ${KV} ] && load_modules $(ls /etc/modules.autoload.d/${KV})