Matches rules filename if it's specified without prefix number. Thanks to Victor Lowther for advice of not using ls command. Use globbing and parameter expansion instead. --- dracut-functions | 31 +++++++++++++++++++++++++++---- 1 files changed, 27 insertions(+), 4 deletions(-) diff --git a/dracut-functions b/dracut-functions index 0caf0d6..7a1d82f 100755 --- a/dracut-functions +++ b/dracut-functions @@ -319,13 +319,36 @@ 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 rd f files=() + [[ -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; } + + for rd in . /lib/udev/rules.d /etc/udev/rules.d $dracutbasedir/rules.d; do + for f in "$rd/$1" "$rd"/*-"$1" + do + [[ -f $f ]] || continue + [[ ${f##*/} =~ [0-9][0-9]-.*\.rules ]] || continue + files+=($f) + done + # If detecting ambiguousness among different directories isn't desired, + # uncomment this: + # (( ${#files[@]} >= 1 )) && break done - return 1 + + (( ${#files[@]} < 1 )) && return 1 + (( ${#files[@]} > 1 )) && { + derror "Ambigous rules filename. Matches: ${files[@]}" + return 1 + } + + echo "$files" } # udev rules always get installed in the same place, so -- 1.7.1
Attachment:
signature.asc
Description: PGP signature