Blame 0043-dracut-init.sh-Simplify-udev-rule-grepping.patch

Harald Hoyer b38677
From 06a1d0769055f437c938edd40bd9fbd622475864 Mon Sep 17 00:00:00 2001
Harald Hoyer b38677
From: =?UTF-8?q?Ville=20Skytt=C3=A4?= <ville.skytta@iki.fi>
Harald Hoyer b38677
Date: Mon, 28 Mar 2016 12:09:06 +0300
Harald Hoyer b38677
Subject: [PATCH] dracut-init.sh: Simplify udev rule grepping
Harald Hoyer b38677
Harald Hoyer b38677
---
Harald Hoyer b38677
 dracut-init.sh | 102 ++++++++++++++++++++++++++-------------------------------
Harald Hoyer b38677
 1 file changed, 46 insertions(+), 56 deletions(-)
Harald Hoyer b38677
Harald Hoyer b38677
diff --git a/dracut-init.sh b/dracut-init.sh
Harald Hoyer b38677
index a67aca2..b176421 100644
Harald Hoyer b38677
--- a/dracut-init.sh
Harald Hoyer b38677
+++ b/dracut-init.sh
Harald Hoyer b38677
@@ -275,71 +275,61 @@ rev_lib_symlinks() {
Harald Hoyer b38677
 inst_rule_programs() {
Harald Hoyer b38677
     local _prog _bin
Harald Hoyer b38677
 
Harald Hoyer b38677
-    if grep -qE 'PROGRAM==?"[^ "]+' "$1"; then
Harald Hoyer b38677
-        for _prog in $(grep -E 'PROGRAM==?"[^ "]+' "$1" | sed -r 's/.*PROGRAM==?"([^ "]+).*/\1/'); do
Harald Hoyer b38677
-            _bin=""
Harald Hoyer b38677
-            if [ -x ${udevdir}/$_prog ]; then
Harald Hoyer b38677
-                _bin=${udevdir}/$_prog
Harald Hoyer b38677
-            elif [[ "${_prog/\$env\{/}" == "$_prog" ]]; then
Harald Hoyer b38677
-                _bin=$(find_binary "$_prog") || {
Harald Hoyer b38677
-                    dinfo "Skipping program $_prog using in udev rule ${1##*/} as it cannot be found"
Harald Hoyer b38677
-                    continue;
Harald Hoyer b38677
-                }
Harald Hoyer b38677
-            fi
Harald Hoyer b38677
+    for _prog in $(sed -nr 's/.*PROGRAM==?"([^ "]+).*/\1/p'); do
Harald Hoyer b38677
+        _bin=""
Harald Hoyer b38677
+        if [ -x ${udevdir}/$_prog ]; then
Harald Hoyer b38677
+            _bin=${udevdir}/$_prog
Harald Hoyer b38677
+        elif [[ "${_prog/\$env\{/}" == "$_prog" ]]; then
Harald Hoyer b38677
+            _bin=$(find_binary "$_prog") || {
Harald Hoyer b38677
+                dinfo "Skipping program $_prog using in udev rule ${1##*/} as it cannot be found"
Harald Hoyer b38677
+                continue;
Harald Hoyer b38677
+            }
Harald Hoyer b38677
+        fi
Harald Hoyer b38677
 
Harald Hoyer b38677
-            [[ $_bin ]] && inst_binary "$_bin"
Harald Hoyer b38677
-        done
Harald Hoyer b38677
-    fi
Harald Hoyer b38677
-    if grep -qE 'RUN[+=]=?"[^ "]+' "$1"; then
Harald Hoyer b38677
-        for _prog in $(grep -E 'RUN[+=]=?"[^ "]+' "$1" | sed -r 's/.*RUN[+=]=?"([^ "]+).*/\1/'); do
Harald Hoyer b38677
-            _bin=""
Harald Hoyer b38677
-            if [ -x ${udevdir}/$_prog ]; then
Harald Hoyer b38677
-                _bin=${udevdir}/$_prog
Harald Hoyer b38677
-            elif [[ "${_prog/\$env\{/}" == "$_prog" ]] && [[ "${_prog}" != "/sbin/initqueue" ]]; then
Harald Hoyer b38677
-                _bin=$(find_binary "$_prog") || {
Harald Hoyer b38677
-                    dinfo "Skipping program $_prog using in udev rule ${1##*/} as it cannot be found"
Harald Hoyer b38677
-                    continue;
Harald Hoyer b38677
-                }
Harald Hoyer b38677
-            fi
Harald Hoyer b38677
+        [[ $_bin ]] && inst_binary "$_bin"
Harald Hoyer b38677
+    done
Harald Hoyer b38677
+    for _prog in $(sed -nr 's/.*RUN[+=]=?"([^ "]+).*/\1/p'); do
Harald Hoyer b38677
+        _bin=""
Harald Hoyer b38677
+        if [ -x ${udevdir}/$_prog ]; then
Harald Hoyer b38677
+            _bin=${udevdir}/$_prog
Harald Hoyer b38677
+        elif [[ "${_prog/\$env\{/}" == "$_prog" ]] && [[ "${_prog}" != "/sbin/initqueue" ]]; then
Harald Hoyer b38677
+            _bin=$(find_binary "$_prog") || {
Harald Hoyer b38677
+                dinfo "Skipping program $_prog using in udev rule ${1##*/} as it cannot be found"
Harald Hoyer b38677
+                continue;
Harald Hoyer b38677
+            }
Harald Hoyer b38677
+        fi
Harald Hoyer b38677
 
Harald Hoyer b38677
-            [[ $_bin ]] && inst_binary "$_bin"
Harald Hoyer b38677
-        done
Harald Hoyer b38677
-    fi
Harald Hoyer b38677
-    if grep -qE 'IMPORT\{program\}==?"[^ "]+' "$1"; then
Harald Hoyer b38677
-        for _prog in $(grep -E 'IMPORT\{program\}==?"[^ "]+' "$1" | sed -r 's/.*IMPORT\{program\}==?"([^ "]+).*/\1/'); do
Harald Hoyer b38677
-            _bin=""
Harald Hoyer b38677
-            if [ -x ${udevdir}/$_prog ]; then
Harald Hoyer b38677
-                _bin=${udevdir}/$_prog
Harald Hoyer b38677
-            elif [[ "${_prog/\$env\{/}" == "$_prog" ]]; then
Harald Hoyer b38677
-                _bin=$(find_binary "$_prog") || {
Harald Hoyer b38677
-                    dinfo "Skipping program $_prog using in udev rule ${1##*/} as it cannot be found"
Harald Hoyer b38677
-                    continue;
Harald Hoyer b38677
-                }
Harald Hoyer b38677
-            fi
Harald Hoyer b38677
+        [[ $_bin ]] && inst_binary "$_bin"
Harald Hoyer b38677
+    done
Harald Hoyer b38677
+    for _prog in $(sed -nr 's/.*IMPORT\{program\}==?"([^ "]+).*/\1/p'); do
Harald Hoyer b38677
+        _bin=""
Harald Hoyer b38677
+        if [ -x ${udevdir}/$_prog ]; then
Harald Hoyer b38677
+            _bin=${udevdir}/$_prog
Harald Hoyer b38677
+        elif [[ "${_prog/\$env\{/}" == "$_prog" ]]; then
Harald Hoyer b38677
+            _bin=$(find_binary "$_prog") || {
Harald Hoyer b38677
+                dinfo "Skipping program $_prog using in udev rule ${1##*/} as it cannot be found"
Harald Hoyer b38677
+                continue;
Harald Hoyer b38677
+            }
Harald Hoyer b38677
+        fi
Harald Hoyer b38677
 
Harald Hoyer b38677
-            [[ $_bin ]] && dracut_install "$_bin"
Harald Hoyer b38677
-        done
Harald Hoyer b38677
-    fi
Harald Hoyer b38677
+        [[ $_bin ]] && dracut_install "$_bin"
Harald Hoyer b38677
+    done
Harald Hoyer b38677
 }
Harald Hoyer b38677
 
Harald Hoyer b38677
 # attempt to install any programs specified in a udev rule
Harald Hoyer b38677
 inst_rule_group_owner() {
Harald Hoyer b38677
     local i
Harald Hoyer b38677
 
Harald Hoyer b38677
-    if grep -qE 'OWNER=?"[^ "]+' "$1"; then
Harald Hoyer b38677
-        for i in $(grep -E 'OWNER=?"[^ "]+' "$1" | sed -r 's/.*OWNER=?"([^ "]+).*/\1/'); do
Harald Hoyer b38677
-            if ! grep -Eq "^$i:" "$initdir/etc/passwd" 2>/dev/null; then
Harald Hoyer b38677
-                grep -E "^$i:" /etc/passwd 2>/dev/null >> "$initdir/etc/passwd"
Harald Hoyer b38677
-            fi
Harald Hoyer b38677
-        done
Harald Hoyer b38677
-    fi
Harald Hoyer b38677
-    if grep -qE 'GROUP=?"[^ "]+' "$1"; then
Harald Hoyer b38677
-        for i in $(grep -E 'GROUP=?"[^ "]+' "$1" | sed -r 's/.*GROUP=?"([^ "]+).*/\1/'); do
Harald Hoyer b38677
-            if ! grep -Eq "^$i:" "$initdir/etc/group" 2>/dev/null; then
Harald Hoyer b38677
-                grep -E "^$i:" /etc/group 2>/dev/null >> "$initdir/etc/group"
Harald Hoyer b38677
-            fi
Harald Hoyer b38677
-        done
Harald Hoyer b38677
-    fi
Harald Hoyer b38677
+    for i in $(sed -nr 's/.*OWNER=?"([^ "]+).*/\1/p'); do
Harald Hoyer b38677
+        if ! grep -Eq "^$i:" "$initdir/etc/passwd" 2>/dev/null; then
Harald Hoyer b38677
+            grep -E "^$i:" /etc/passwd 2>/dev/null >> "$initdir/etc/passwd"
Harald Hoyer b38677
+        fi
Harald Hoyer b38677
+    done
Harald Hoyer b38677
+    for i in $(sed -nr 's/.*GROUP=?"([^ "]+).*/\1/p' "$1"); do
Harald Hoyer b38677
+        if ! grep -Eq "^$i:" "$initdir/etc/group" 2>/dev/null; then
Harald Hoyer b38677
+            grep -E "^$i:" /etc/group 2>/dev/null >> "$initdir/etc/group"
Harald Hoyer b38677
+        fi
Harald Hoyer b38677
+    done
Harald Hoyer b38677
 }
Harald Hoyer b38677
 
Harald Hoyer b38677
 inst_rule_initqueue() {