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

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