5 获得驱动模块的脚本
转载请注明出处[By SELinux+]
#!/bin/sh #auth qfong.com #site: www.selinuxplus.com www.qfong.com export black='\033[0m' export boldblack='\033[1;0m' export red='\033[31m' export boldred='\033[1;31m' export green='\033[32m' export boldgreen='\033[1;32m' export yellow='\033[33m' export boldyellow='\033[1;33m' export blue='\033[34m' export boldblue='\033[1;34m' export magenta='\033[35m' export boldmagenta='\033[1;35m' export cyan='\033[36m' export boldcyan='\033[1;36m' export white='\033[37m' export boldwhite='\033[1;37m' cecho () { local default_msg="No message passed." message=${1:-$default_msg} # Defaults to default message. color=${2:-black} # Defaults to black, if not specified. case $color in black) printf "$black" ;; boldblack) printf "$boldblack" ;; red) printf "$red" ;; boldred) printf "$boldred" ;; yellow) printf "$yellow" ;; boldyellow) printf "$boldyellow" ;; blue) printf "$blue" ;; boldblue) printf "$boldblue" ;; magenta) printf "$magenta" ;; boldmagenta) printf "$boldmagenta" ;; cyan) printf "$cyan" ;; boldcyan) printf "$boldcyan" ;; white) printf "$white" ;; boldwhite) printf "$boldwhite" ;; esac printf "%s" "$message" tput sgr0 # Reset to normal. printf "$black" return } cechon () { local default_msg="No message passed." message=${1:-$default_msg} # Defaults to default message. color=${2:-black} # Defaults to black, if not specified. case $color in black) printf "$black" ;; boldblack) printf "$boldblack" ;; red) printf "$red" ;; boldred) printf "$boldred" ;; yellow) printf "$yellow" ;; boldyellow) printf "$boldyellow" ;; blue) printf "$blue" ;; boldblue) printf "$boldblue" ;; magenta) printf "$magenta" ;; boldmagenta) printf "$boldmagenta" ;; cyan) printf "$cyan" ;; boldcyan) printf "$boldcyan" ;; white) printf "$white" ;; boldwhite) printf "$boldwhite" ;; esac printf "%s\n" "$message" tput sgr0 # Reset to normal. printf "$black" return } driver() { if [ $# != "2" ]; then echo cechon "Script to display the drivers and modules for a specified sysfs class device" "boldblue" cechon "Usage: $0 <CLASS_NAME>" "boldred" echo "example usage:" cecho " $0 d " "blue" cechon "sha" "boldmagenta" echo "Will show all drivers and modules for the sda block device." cechon "==============================================================" "white" exit 1 fi ## ## for " find /sys/class -name sda " ## DEV=$2 if test -e "$2";then DEVPATH=$2 else #find sysfs device directory for device DEVPATH=$(find /sys/class -name "$2" |head -1 ) test -z "$DEVPATH" && DEVPATH=$(find /sys/block -name "$2" |head -1 ) test -z "$DEVPATH" && DEVPATH=$(find /sys/bus -name "$2" |head -1 ) if ! test -e "$DEVPATH";then cechon "No Device Found !!!" "red" exit 1 fi fi cechon "==============================================================" "white" cechon " Get Driver Tools ... " "boldred" cechon "==============================================================" "white" printf "Looking at sysfs devices:" cechon "$DEVPATH" "boldmagenta" if test -L "$DEVPATH" ;then # resolve class device link to device directory EDVPATH=$(readlink -f $DEVPATH) printf "Resolve link to:" cechon "$DEVPATH" "boldmagenta" fi if test -d "$DEVPATH";then #resolve old-style "device" loink to the parent device PARENT=$DEVPATH while test "$PARENT" != "/";do if test -L "$PARENT/device"; then DEVPATH=$(readlink -f $PARENT/device) printf "follow 'device' link to parent ::" cechon "$DEVPATH" "boldmagenta" break fi PARENT=$(dirname $PARENT) done fi cechon "##############################################################" "white" while test "$DEVPATH" != "/" ;do DRIVERPATH= DRIVER= MOUDLEPATH= MODULE= if test -e $DEVPATH/driver ;then DRIVERPATH=$(readlink -f $DEVPATH/driver) DRIVER=$(basename $DRIVERPATH) printf "Found driver:" cechon "$DRIVER" "boldmagenta" if test -e $DRIVERPATH/module; then MODULEPATH=$(readlink -f $DRIVERPATH/module) MODULE=$(basename $MODULEPATH) printf "Found module:" cechon "$MODULE" "boldmagenta" fi cechon "--------------------------------------------------------------" "white" fi DEVPATH=$(dirname $DEVPATH) done } modules(){ for i in `find /sys/ -name modalias -exec cat {} \;`; do /sbin/modprobe --config /dev/null --show-depends $i ; done | rev |cut -f 1 -d '/' |rev |sort -u >/tmp/list_modules clear clear clear cechon "==============================================================" "white" cechon " Get Modules Tools ... " "boldred" cechon "==============================================================" "white" cat /tmp/list_modules rm /tmp/list_modules } usages(){ cechon "Usage: $0 <FILES> " "boldred" echo "example usage:" cecho " $0 " "blue" cechon "d|m" "boldmagenta" cechon "==============================================================" "white" } INP=$1 INF=${1:-usage} if [[ $1 == "d" ]];then driver $@ elif [[ $1 == "m" ]];then modules elif [[ $1 == "usages" ]];then usages else usages fi