Blame SOURCES/0004-Add-rd.neednet-1-to-cmdline-only-if-there-are-device.patch

3700a9
From fc0cc6f159857e463aacababdc0735b0972d103c Mon Sep 17 00:00:00 2001
3700a9
From: Sergio Correia <scorreia@redhat.com>
3700a9
Date: Wed, 13 May 2020 23:51:04 -0300
3700a9
Subject: [PATCH 4/8] Add rd.neednet=1 to cmdline only if there are devices
3700a9
 bound to tang
3700a9
3700a9
---
3700a9
 .../dracut/clevis-pin-tang/module-setup.sh.in | 21 +++++++++++++++++--
3700a9
 1 file changed, 19 insertions(+), 2 deletions(-)
3700a9
3700a9
diff --git a/src/luks/systemd/dracut/clevis-pin-tang/module-setup.sh.in b/src/luks/systemd/dracut/clevis-pin-tang/module-setup.sh.in
3700a9
index 1bb2ead..a4984dc 100755
3700a9
--- a/src/luks/systemd/dracut/clevis-pin-tang/module-setup.sh.in
3700a9
+++ b/src/luks/systemd/dracut/clevis-pin-tang/module-setup.sh.in
3700a9
@@ -18,8 +18,23 @@
3700a9
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
3700a9
 #
3700a9
 
3700a9
+has_devices_bound_to_tang() {
3700a9
+    local dev
3700a9
+    for dev in $(lsblk -p -n -s -r \
3700a9
+                 | awk '$6 == "crypt" { getline; print $1 }' | sort -u); do
3700a9
+       if clevis luks list -d "${dev}" 2>/dev/null | grep -q tang; then
3700a9
+           return 0
3700a9
+       fi
3700a9
+    done
3700a9
+    return 1
3700a9
+}
3700a9
+
3700a9
 depends() {
3700a9
-    echo clevis network
3700a9
+    local deps="clevis"
3700a9
+    if has_devices_bound_to_tang; then
3700a9
+         deps=$(printf "%s network" "${deps}")
3700a9
+    fi
3700a9
+    echo "${deps}"
3700a9
     return 0
3700a9
 }
3700a9
 
3700a9
@@ -28,7 +43,9 @@ cmdline() {
3700a9
 }
3700a9
 
3700a9
 install() {
3700a9
-    cmdline > "${initdir}/etc/cmdline.d/99clevis-pin-tang.conf"
3700a9
+    if has_devices_bound_to_tang; then
3700a9
+        cmdline > "${initdir}/etc/cmdline.d/99clevis-pin-tang.conf"
3700a9
+    fi
3700a9
 
3700a9
     inst_multiple \
3700a9
 	clevis-decrypt-tang \
3700a9
-- 
3700a9
2.18.4
3700a9