]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
dracut-lib.sh: fixed getargs()
authorHarald Hoyer <harald@redhat.com>
Wed, 20 Jul 2011 19:12:17 +0000 (21:12 +0200)
committerHarald Hoyer <harald@redhat.com>
Wed, 20 Jul 2011 19:12:17 +0000 (21:12 +0200)
if $1 has a "=<value>", we want the exact match
if cmdline argument has no "=<value>", we assume "=1"

modules.d/99base/dracut-lib.sh

index 10025bdbb84e76a3e96b1e9331b03632ebbb4902..c2202f127909abd748995f07174aa72e7beb6eb2 100755 (executable)
@@ -45,19 +45,36 @@ _getcmdline() {
 }
 
 _dogetarg() {
-    local _o _val
+    local _o _val _doecho
     unset _val
     unset _o
+    unset _doecho
     _getcmdline
 
     for _o in $CMDLINE; do
-        if [ "$_o" = "$1" ]; then
-            return 0;
+        if [ "${_o%%=*}" = "${1%=}" ]; then
+            if [ -n "${1#*=}" -a "${1#*=*}" != "${1}" ]; then
+                # if $1 has a "=<value>", we want the exact match
+                if [ "$_o" = "$1" ]; then
+                    _val="1";
+                    unset _doecho
+                fi
+                continue
+            fi
+
+            if [ "${_o#*=}" = "$_o" ]; then
+                # if cmdline argument has no "=<value>", we assume "=1"
+                _val="1";
+                unset _doecho
+                continue
+            fi
+
+            _val=${_o#*=};
+            _doecho=1
         fi
-        [ "${_o%%=*}" = "${1%=}" ] && _val=${_o#*=};
     done
     if [ -n "$_val" ]; then
-        echo $_val;
+        [ "x$_doecho" != "x" ] && echo $_val;
         return 0;
     fi
     return 1;
@@ -67,13 +84,13 @@ getarg() {
     set +x
     while [ $# -gt 0 ]; do
         case $1 in
-            -y) if _dogetarg $2; then
+            -y) if _dogetarg $2 >/dev/null; then
                     echo 1
                     [ "$RD_DEBUG" = "yes" ] && set -x
                     return 0
                 fi
                 shift 2;;
-            -n) if _dogetarg $2; then
+            -n) if _dogetarg $2 >/dev/null; then
                     echo 0;
                     [ "$RD_DEBUG" = "yes" ] && set -x
                     return 1