]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
Add dracutmodules=auto functionality
authorVictor Lowther <victor.lowther@gmail.com>
Fri, 6 Mar 2009 20:23:37 +0000 (14:23 -0600)
committerVictor Lowther <victor.lowther@gmail.com>
Fri, 6 Mar 2009 20:23:37 +0000 (14:23 -0600)
To use this, your module needs to supply a check script which returns 0
if the module is applicable to this system, 1 otherwise.

If a module does not include a check script, it will be sourced. If no modules
have check scripts, then dracutmodules=auto behaves exactly like
dracutmodules=all

dracut

diff --git a/dracut b/dracut
index 04c64573054ec7dc7a286068bd624762536a8f11..12d343141f09ea7ac44fdf581e37f5dee3153124 100755 (executable)
--- a/dracut
+++ b/dracut
@@ -50,14 +50,23 @@ for d in bin sbin usr/bin usr/sbin usr/lib etc proc sys sysroot dev/pts; do
     mkdir -p "$initdir/$d"; 
 done
 
+can_source_module() {
+    # $1 = location of module
+    mod=${1##*/}; mod=${mod#[0-9][0-9]};
+    case $dracutmodules in
+       all) return 0;;
+       auto) [[ -x $1/check ]] || return 0
+           "$1/check" >/dev/null 2>&1 && return 0 ;;
+       *) strstr "$dracutmodules" "$mod" && return 0;;
+    esac
+    return 1
+}
+
 # source all our modules
 for moddir in "$dsrc/modules.d"/*; do
     [[ -d $moddir || -L $moddir ]] || continue
-    mod=${moddir##*/}; mod=${mod#[0-9][0-9]};
-    if [[ $dracutmodules = all ]] || strstr "$dracutmodules " "$mod "; then 
-       echo "== Module $moddir == "
-       [[ -x $moddir/install ]] && . "$moddir/install"
-    fi
+    can_source_module "$moddir" || continue
+    [[ -x $moddir/install ]] && . "$moddir/install"
 done
 unset moddir