Re: [PATCH 3/3] dracut-functions: find_rule a bit smarter

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Matches rules filename if it's specified without prefix number.
---
 dracut-functions |   25 +++++++++++++++++++++++--
 1 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/dracut-functions b/dracut-functions
index be6b2e9..1f2528e 100755
--- a/dracut-functions
+++ b/dracut-functions
@@ -319,11 +319,32 @@ inst_symlink() {
     inst "$realsrc" && ln -s "$realsrc" "$target"
 }
 
-# find a udev rule in the usual places.
+# find a udev rule in the usual places and try to be smart (just a bit).
+# See example:
+#   find_rule default.rules
+#   find_rule 50-default.rules
+# All of them will return: /lib/udev/rules.d/50-udev-default.rules
+# If there are few matching files, error message is printed.
 find_rule() {
+    local rule t
+
     [[ -f $1 ]] && { echo "$1"; return 0; }
     for r in . /lib/udev/rules.d /etc/udev/rules.d $dracutbasedir/rules.d; do
-	[[ -f $r/$1 ]] && { echo "$r/$1"; return 0; }
+        if ls $r/*$1 &>/dev/null; then
+            if [[ -f $r/$1 ]]; then
+                echo "$r/$1"
+                return 0
+            else
+                rule=$(ls "$r"/??"-$1" 2>/dev/null)
+                t=($rule)
+                if (( ${#t[@]} > 1 )); then
+                    derror "Ambigous rules filename.  Matches: ${t[@]}"
+                elif [[ -f "$rule" ]]; then
+                    echo $rule
+                    return 0
+                fi
+            fi
+        fi
     done
     return 1
 }
-- 
1.7.1

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Linux Kernel]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]

  Powered by Linux