Clean up logic for auto vs. hostonly
authorVictor Lowther <victor.lowther@gmail.com>
Sat, 7 Mar 2009 14:25:22 +0000 (08:25 -0600)
committerVictor Lowther <victor.lowther@gmail.com>
Sat, 7 Mar 2009 15:10:35 +0000 (09:10 -0600)
The mass of conditional checking and multiple variables was a little
hard to read, split some of it into its own function.

dracut

diff --git a/dracut b/dracut
index 1172ebb..ce83380 100755 (executable)
--- a/dracut
+++ b/dracut
@@ -35,18 +35,18 @@ done
 dracutfunctions=$dsrc/dracut-functions
 export dracutfunctions
 
-[[ $dracutmodules ]] || dracutmodules="auto" 
+[[ $dracutmodules ]] || dracutmodules="all"
 [[ $dracutmodules = "auto" ]] && {
     dracutmodules="all"
     skipmissing="yes"
 }
-
 [[ $dracutmodules = "hostonly" ]] && {
     dracutmodules="all"
     skipmissing="yes"
     hostonly="-h"
 }
 
+
 [[ $2 ]] && kernel=$2 || kernel=$(uname -r)
 [[ $1 ]] && outfile=$(readlink -f $1) || outfile="/boot/initrd-$kernel.img"
 
@@ -67,20 +67,20 @@ for d in bin sbin usr/bin usr/sbin usr/lib etc proc sys sysroot dev/pts; do
     mkdir -p "$initdir/$d"; 
 done
 
+skip_missing() {
+    # $1 = location of module
+    [[ $skipmissing ]] || return 0
+    [[ -x $1/check ]] || return 0
+    "$1/check" $hostonly
+}
+
 can_source_module() {
     # $1 = location of module
     mod=${1##*/}; mod=${mod#[0-9][0-9]};
-    case $dracutmodules in
-       all) [[ $skipmissing ]] || return 0;;
-       *) strstr "$dracutmodules " "$mod " || return 1;;
-    esac
-
-    [[ $skipmissing ]] && [[ -x $1/check ]] && {
-        return $("$1/check" $hostonly >/dev/null 2>&1;)
-    }
-
-    [[ $skipmissing ]] || return 1
-    return 0
+    if [[ $dracutmodules != all ]]; then
+       strstr "$dracutmodules " "$mod " || return 1;;
+    fi
+    skip_missing "$1"
 }
 
 # source all our modules