#!/bin/bash # This code should not be run as `sh find_all_modules.sh`, as some distros # link sh to dash, which is POSIX-compliant and doesn't do arrays. # Adapted from Linux Kernel in a Nutshell: http://www.kroah.com/lkn/ # By Rob Sears, Sept 22, 2013. # Get a newline-separated list of modules in use: MODLIST=`for i in $(find /sys/ -name modalias -exec cat {} \; 2>/dev/null); do /sbin/modprobe --config /dev/null --show-depends $i 2> /dev/null;done | rev | cut -f 1 -d '/' | rev | sort -u` # Convert the newline-separated list to an array: IFS=$'\n' read -d '' -r -a MODULES <<< "${MODLIST}" # Iterate over the array and print out details: for i in "${MODULES[@]}" do # Get the module name (turn "module.ko" to "module"): MOD=`echo "${i}" | sed -e "s/\([0-9a-zA-Z]\)\.ko/\1/"` # Get the module description: DESC=`modinfo $MOD | grep description | sed -r "s/[\ ]+{2,}/\ /g; " | sed -e "s/^description\: \([0-9a-zA-Z]\)/\1/"` # Get the module's dependancies: DEPS=`modinfo $MOD | grep depends | sed -r "s/[\ ]+{2,}/\ /g; " | sed -e "s/^depends\: \([0-9a-zA-Z]\)/\1/"` # Determine whether to print a description: if [ -z "${DESC}" ]; then DESCRIPTION="" else DESCRIPTION="${DESC} " fi # Determine whether to print a dependancy list: if [[ "${DEPS}" =~ "depends:" ]]; then DEPENDANCIES="" else DEPENDANCIES="Depends on ${DEPS}" fi # Generate the notes to display: NOTES="${DESCRIPTION}${DEPENDANCIES}" if [ -z "${NOTES}" ]; then MESSAGE="$i: No information" else MESSAGE="$i (${NOTES})" fi # Print the module name, description and dependancies: echo "${MESSAGE}" done