6aac43
From a6c4171117924cacaa727a9828e72f70e09b1fa9 Mon Sep 17 00:00:00 2001
6aac43
From: Pavel Valena <pvalena@redhat.com>
6aac43
Date: Tue, 12 Jul 2022 14:15:25 +0200
6aac43
Subject: [PATCH] fix(fips): enhance commit 'handle s390x OSTree systems'
d1a34d
6aac43
78557f05a69fe718a97df85d2ed741ce10d3f806
6aac43
6aac43
Refactored to enhance readability.
6aac43
6aac43
Related: rhbz#2050567
d1a34d
---
6aac43
 modules.d/01fips/fips.sh         | 15 +++++++++++----
6aac43
 modules.d/01fips/module-setup.sh |  2 +-
6aac43
 2 files changed, 12 insertions(+), 5 deletions(-)
d1a34d
6aac43
diff --git a/modules.d/01fips/fips.sh b/modules.d/01fips/fips.sh
6aac43
index 26f65414..6ad61df8 100755
6aac43
--- a/modules.d/01fips/fips.sh
6aac43
+++ b/modules.d/01fips/fips.sh
6aac43
@@ -132,10 +132,17 @@ do_fips() {
6aac43
                 if [ -e "/boot/vmlinuz-${KERNEL}" ]; then
6aac43
                     BOOT_IMAGE="vmlinuz-${KERNEL}"
6aac43
                 elif [ -d /boot/loader/entries ]; then
6aac43
-                    bls=$(find /boot/loader/entries -name '*.conf' | sort -rV | sed -n "$((BOOT_IMAGE + 1))p")
6aac43
-                    if [ -e "${bls}" ]; then
6aac43
-                        BOOT_IMAGE=$(grep ^linux "${bls}" | cut -d' ' -f2)
6aac43
-                    fi
6aac43
+                    i=0
6aac43
+                    # shellcheck disable=SC2012
6aac43
+                    for bls in $(ls -d /boot/loader/entries/*.conf | sort -rV); do
6aac43
+                        if [ "$i" -eq "${BOOT_IMAGE:-0}" ] && [ -r "$bls" ]; then
6aac43
+                            BOOT_IMAGE="$(grep -e '^linux' "$bls" | grep -o ' .*$')"
6aac43
+                            BOOT_IMAGE=${BOOT_IMAGE## }
6aac43
+                            break
6aac43
+                        fi
6aac43
+
6aac43
+                        i=$((i + 1))
6aac43
+                    done
6aac43
                 fi
6aac43
             fi
d1a34d
 
6aac43
diff --git a/modules.d/01fips/module-setup.sh b/modules.d/01fips/module-setup.sh
6aac43
index 8860159d..cc9d15ce 100755
6aac43
--- a/modules.d/01fips/module-setup.sh
6aac43
+++ b/modules.d/01fips/module-setup.sh
6aac43
@@ -67,7 +67,7 @@ install() {
6aac43
     inst_hook pre-udev 01 "$moddir/fips-load-crypto.sh"
6aac43
     inst_script "$moddir/fips.sh" /sbin/fips.sh
d1a34d
 
6aac43
-    inst_multiple sha512hmac rmmod insmod mount uname umount grep sed cut find sort
6aac43
+    inst_multiple sha512hmac rmmod insmod mount uname umount grep sed sort
d1a34d
 
6aac43
     inst_simple /etc/system-fips
6aac43
     [ -c "${initdir}"/dev/random ] || mknod "${initdir}"/dev/random c 1 8 \
d1a34d