Last active
February 8, 2021 12:41
-
-
Save legionus/0a2b1d28e792f1ed720f912df2cf0540 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -efu | |
. shell-error | |
SYSFS_PATH="/sys" | |
BASE_DIR="/" | |
KERNEL_SRC_DIR=/home/legion/scm/kernel/linux-release | |
find_modules() | |
{ | |
:>/tmp/modules | |
find -P "$SYSFS_PATH" \ | |
-name 'uevent' \ | |
-exec grep '^MODALIAS=' '{}' '+' \ | |
2>/dev/null | | |
while | |
IFS=' | |
' read -r event | |
do | |
sysfs_file="${event%%:MODALIAS=*}" | |
alias="${event##*:MODALIAS=}" | |
found=1 | |
names="$(/sbin/modinfo -b "$BASE_DIR" -n "$alias" 2>/dev/null)" || | |
found='' | |
printf 'PATH=%s\n' "$sysfs_file" | |
printf 'MODALIAS=%s\n' "$alias" | |
if [ -n "$found" ]; then | |
for n in $names; do | |
printf 'MODULE=%s\n' "$n" | |
printf '%s\n' "$n" >>/tmp/modules | |
done | |
else | |
printf 'NOTFOUND\n' | |
fi | |
printf '\n' | |
done | |
sort -uo /tmp/modules /tmp/modules | |
} | |
find_modules | |
modules_config() | |
{ | |
while read -r module_path; do | |
path="${module_path#$BASE_DIR}" | |
if [ -n "${path##/lib/modules/*}" ]; then | |
message "unexpected modules path: $module_path" | |
continue | |
fi | |
path="${path#/lib/modules/*/}" | |
if [ -n "${path##kernel/*}" ]; then | |
message "extra kernel modules not supported" | |
continue | |
fi | |
path="${path#kernel/}" | |
modname="${path##*/}" | |
modname="${modname%.ko*}" | |
path="${path%/*}" | |
printf '%s:' "$modname" | |
sed -n \ | |
-e "s/^obj-\$(\(CONFIG_.*\))[[:space:]]*[+:]\?=[[:space:]]*$modname\.o[[:space:]]*$/\1/p" \ | |
"$KERNEL_SRC_DIR/$path/Makefile" | |
done < /tmp/modules | |
} | |
modules_config |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment