#! /bin/bash
#
# mod_list.sh 0.1 2005/04/19 10:05:26 (Rafal Zajac)
#
# Sacript to generate list available kernel modules with
# descrptions.
#
# Downloaded from http://www.slackware.prv.pl
#
# Copyright (C) 2005 Rafal Zajac <rzajac{at}gmail{dot}com>
# Released under the GPL v2 only.

# Config
OUTPUT_DEF=~/modules.txt
MODPROBE=`cat /proc/sys/kernel/modprobe`
MODINFO=`which modinfo`
BASENAME=`which basename`
GREP=`which grep`

if [ "$MODPROBE" = "" ] || [ "$BASENAME" = "" ] || [ "$GREP" = "" ] || [ "$MODINFO" = "" ]; then
        echo "You must have modprobe, modinfo, basename, grep to run this script"
        exit 1
fi


if [ $# -gt 2 ]; then
        echo
        echo " Usage: $0 [-v] path"
        echo "   -v  : verbose mode"
        echo "  path : path to the output file."
        exit 1
fi

# Check arguments

if [ "$#" = 2 ]  && [ "$1" = "-v" ]; then
        OUTPUT_DEF=$2
fi

if [ "$#" = 1 ] && [ "$1" != "-v" ]; then
        OUTPUT_DEF=$1
fi

echo
echo "Generateing available kernel modules listing with descriptions to file $OUTPUT_DEF"
echo "   Copyright (C) 2005 Rafal Zajac <rzajac{at}gmail{dot}com>"
echo "   Downloaded from http://www.slackware.prv.pl"

# Errase old listing
rm -f $OUTPUT

# Make listing

for mod in $($MODPROBE -l); do
        echo $($BASENAME $mod) >> $OUTPUT_DEF
        echo -n "     " >> $OUTPUT_DEF
        modinfo $mod | $GREP description: >> $OUTPUT_DEF
        echo >> $OUTPUT_DEF
        if [ "$1" = "-v" ]; then
                echo $(basename $mod)
        fi
done



