updated on Tue Jan 10 04:01:21 UTC 2012
[aur-mirror.git] / udev-ubuntu / load-modules.sh
bloba42d376339be4124419cd315a86dac09a3babea2
1 #!/bin/bash
2 # Implement blacklisting for udev-loaded modules
4 [ $# -ne 1 ] && exit 1
6 . /etc/rc.conf
8 # grab modules from rc.conf
9 BLACKLIST="${MOD_BLACKLIST[@]}"
10 MODPROBE="/sbin/modprobe"
11 LOGGER="/usr/bin/logger"
12 RESOLVEALIAS="/bin/resolve-modalias"
13 USEBLACKLIST="--use-blacklist"
15 if [ -f /proc/cmdline ]; then
16 for cmd in $(cat /proc/cmdline); do
17 case $cmd in
18 disablemodules=*) eval $cmd ;;
19 load_modules=off) exit ;;
20 esac
21 done
22 #parse cmdline entries of the form "disablemodules=x,y,z"
23 if [ -n "$disablemodules" ]; then
24 BLACKLIST="$BLACKLIST $(echo $disablemodules | sed 's|,| |g')"
28 #MODULES entries in rc.conf that begin with ! are blacklisted
29 for mod in ${MODULES[@]}; do
30 if [ "${mod}" != "${mod#!}" ]; then
31 BLACKLIST="$BLACKLIST ${mod#!}"
33 done
35 if [ "$MOD_AUTOLOAD" = "yes" -o "$MOD_AUTOLOAD" = "YES" ]; then
36 if [ -n "${BLACKLIST}" ]; then
37 # If an alias name is on the blacklist, load no modules for this device
38 if echo "${BLACKLIST}" | /bin/grep -q -e " $1 " -e "^$1 " -e " $1\$"; then
39 $LOGGER -p info -t "$(basename $0)" "Not loading module alias '$1' because it is blacklisted"
40 exit
42 #sanitize the blacklist
43 BLACKLIST="$(echo "$BLACKLIST" | sed -e 's|-|_|g')"
44 # Try to find all modules for the alias
45 mods=$($RESOLVEALIAS /lib/modules/$(uname -r)/modules.alias $1)
46 # If no modules could be found, try if the alias name is a module name
47 # In that case, omit the --use-blacklist parameter to imitate normal modprobe behaviour
48 [ -z "${mods}" ] && $MODPROBE -qni $1 && mods="$1" && USEBLACKLIST=""
49 [ -z "${mods}" ] && $LOGGER -p info -t "$(basename $0)" "'$1' is not a valid module or alias name"
50 for mod in ${mods}; do
51 # Find the module and all its dependencies
52 deps="$($MODPROBE -i --show-depends ${mod})"
53 [ $? -ne 0 ] && continue
55 #sanitize the module names
56 deps="$(echo "$deps" | sed \
57 -e "s#^insmod /lib.*/\(.*\)\.ko.*#\1#g" \
58 -e 's|-|_|g')"
60 # If the module or any of its dependencies is blacklisted, don't load it
61 for dep in $deps; do
62 if echo "${BLACKLIST}" | /bin/grep -q -e " ${dep} " -e "^${dep} " -e " ${dep}\$"; then
63 if [ "${dep}" = "${mod}" ]; then
64 $LOGGER -p info -t "$(basename $0)" "Not loading module '${mod}' for alias '$1' because it is blacklisted"
65 else
66 $LOGGER -p info -t "$(basename $0)" "Not loading module '${mod}' for alias '$1' because its dependency '${dep}' is blacklisted"
68 continue 2
70 done
71 # modprobe usually uses the "blacklist" statements from modprobe.conf only to blacklist all aliases
72 # of a module, but not the module itself. We use --use-blacklist here so that modprobe also blacklists
73 # module names if we resolved alias names manually above
74 $MODPROBE $USEBLACKLIST ${mod}
75 done
76 else
77 $MODPROBE $1
80 # vim: set et ts=4: