5 获得驱动模块的脚本
转载请注明出处[By SELinux+]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
#!/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 |