]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
refactor: use read -r instead of cat
authorkeentux <valentin.lefebvre@suse.com>
Tue, 29 Nov 2022 18:23:54 +0000 (18:23 +0000)
committerAntonio Álvarez Feijoo <antonio.feijoo@suse.com>
Mon, 19 Dec 2022 09:43:37 +0000 (10:43 +0100)
Fixes #2093: Bad style `var=$(cat <file>)`. Replace by `read -r var < file`

Signed-off-by: keentux <valentin.lefebvre@suse.com>
26 files changed:
modules.d/01fips/fips.sh
modules.d/01fips/module-setup.sh
modules.d/35connman/netroot.sh
modules.d/35network-legacy/dhcp-multi.sh
modules.d/35network-legacy/ifup.sh
modules.d/35network-legacy/net-genrules.sh
modules.d/40network/net-lib.sh
modules.d/40network/netroot.sh
modules.d/45ifcfg/write-ifcfg.sh
modules.d/80cms/cms-write-ifcfg.sh
modules.d/90dm/dm-shutdown.sh
modules.d/90dmsquash-live-autooverlay/create-overlay.sh
modules.d/95fcoe/fcoe-up.sh
modules.d/95iscsi/iscsiroot.sh
modules.d/95iscsi/module-setup.sh
modules.d/95lunmask/fc_transport_scan_lun.sh
modules.d/95lunmask/module-setup.sh
modules.d/95lunmask/sas_transport_scan_lun.sh
modules.d/95nfs/nfsroot-cleanup.sh
modules.d/95nvmf/module-setup.sh
modules.d/95rootfs-block/mount-root.sh
modules.d/97masterkey/masterkey.sh
modules.d/98ecryptfs/ecryptfs-mount.sh
modules.d/98integrity/evm-enable.sh
modules.d/98usrmount/mount-usr.sh
modules.d/99base/dracut-lib.sh

index 26f654143c599679330cb8ea5933f95ca2b23948..c5e45e5e3fa7e812aaa442bd5591c0c437e9741b 100755 (executable)
@@ -82,7 +82,7 @@ fips_load_crypto() {
     local _module
     local _found
 
-    FIPSMODULES=$(cat /etc/fipsmodules)
+    read -d '' -r FIPSMODULES < /etc/fipsmodules
 
     fips_info "Loading and integrity checking all crypto modules"
     mv /etc/modprobe.d/fips.conf /etc/modprobe.d/fips.conf.bak
index 8860159d29ef991ed64bd91dcfefcf5989df9847..a3e560209782dd1e6ac8f015f27017c0bd779c39 100755 (executable)
@@ -14,7 +14,7 @@ depends() {
 installkernel() {
     local _fipsmodules _mod _bootfstype
     if [[ -f "${srcmods}/modules.fips" ]]; then
-        _fipsmodules="$(cat "${srcmods}/modules.fips")"
+        read -d '' -r _fipsmodules < "${srcmods}/modules.fips"
     else
         _fipsmodules=""
 
index 7fc8397a225f239e1a9cf9be31415a2a606a746c..8f9777434dc724efc35936422e5d51a9f84b8436 100755 (executable)
@@ -26,7 +26,7 @@ netif=$1
 case "$netif" in
     ??:??:??:??:??:??) # MAC address
         for i in /sys/class/net/*/address; do
-            mac=$(cat "$i")
+            read -r mac < "$i"
             if [ "$mac" = "$netif" ]; then
                 i=${i%/address}
                 netif=${i##*/}
index 1c1415a3d27b4280663f3fc88ae9b366002d26ae..788984b57b835099b2e44b1c4f63a26c26cba14f 100755 (executable)
@@ -58,7 +58,7 @@ do_dhclient() {
         # or it finished execution but failed dhcp on that interface.
 
         if [ $retv -eq 127 ]; then
-            pid=$(cat /tmp/dhclient."$netif".pid)
+            read -r pid < /tmp/dhclient."$netif".pid
             info "PID $pid was not found by wait for $netif"
             if [ -e /tmp/dhclient."$netif".lease ]; then
                 info "PID $pid not found but DHCP successful on $netif"
@@ -116,7 +116,7 @@ if [ $ret -eq 0 ]; then
             # Kill all existing dhclient calls for other interfaces, since we
             # already got one successful interface
 
-            npid=$(cat /tmp/dhclient."$netif".pid)
+            read -r npid < /tmp/dhclient."$netif".pid
             pidlist=$(pgrep dhclient)
             for pid in $pidlist; do
                 [ "$pid" -eq "$npid" ] && continue
index df4059615927b68e40b60157e84294095d8c4d38..20044440567233a0acd00b07273bc83e9f06262b 100755 (executable)
@@ -384,7 +384,7 @@ if [ -z "$NO_TEAM_MASTER" ]; then
                     ip link set dev "$slave" down
                     (
                         unset TEAM_PORT_CONFIG
-                        _hwaddr=$(cat "/sys/class/net/$slave/address")
+                        read -r _hwaddr < "/sys/class/net/$slave/address"
                         _subchannels=$(iface_get_subchannels "$slave")
                         if [ -n "$_hwaddr" ] && [ -e "/etc/sysconfig/network-scripts/mac-${_hwaddr}.conf" ]; then
                             # shellcheck disable=SC1090
@@ -531,7 +531,7 @@ done
 if [ -z "$NO_AUTO_DHCP" ] && [ ! -e "/tmp/net.${netif}.up" ]; then
     ret=1
     if [ -e /tmp/net.bootdev ]; then
-        BOOTDEV=$(cat /tmp/net.bootdev)
+        read -r BOOTDEV < /tmp/net.bootdev
         if [ "$netif" = "$BOOTDEV" ] || [ "$BOOTDEV" = "$(cat "/sys/class/net/${netif}/address")" ]; then
             do_dhcp
             ret=$?
index 7e89f73de28455a285ec638f19c35094e30f9ae2..686db593f4e4323f4d4e72b76ca146379a72da63 100755 (executable)
@@ -67,7 +67,7 @@ command -v fix_bootif > /dev/null || . /lib/net-lib.sh
     fi
 
     if [ -e /tmp/net.bootdev ]; then
-        bootdev=$(cat /tmp/net.bootdev)
+        read -r bootdev < /tmp/net.bootdev
     fi
 
     # shellcheck disable=SC2016
index 4797dd6cb6371dbb99c7b74e41a008669f93a2dc..bc1ffcde96df967e195999ad134e0b2b0e843acd 100755 (executable)
@@ -826,7 +826,7 @@ is_persistent_ethernet_name() {
     local _name_assign_type="0"
 
     [ -f "/sys/class/net/$_netif/name_assign_type" ] \
-        && _name_assign_type=$(cat "/sys/class/net/$_netif/name_assign_type" 2> /dev/null)
+        && read -r _name_assign_type < "/sys/class/net/$_netif/name_assign_type" 2> /dev/null
 
     # NET_NAME_ENUM 1
     [ "$_name_assign_type" = "1" ] && return 1
@@ -861,7 +861,7 @@ is_kernel_ethernet_name() {
     local _name_assign_type="1"
 
     if [ -e "/sys/class/net/$_netif/name_assign_type" ]; then
-        _name_assign_type=$(cat "/sys/class/net/$_netif/name_assign_type")
+        read -r _name_assign_type < "/sys/class/net/$_netif/name_assign_type"
 
         case "$_name_assign_type" in
             2 | 3 | 4)
index 7fc8397a225f239e1a9cf9be31415a2a606a746c..8f9777434dc724efc35936422e5d51a9f84b8436 100755 (executable)
@@ -26,7 +26,7 @@ netif=$1
 case "$netif" in
     ??:??:??:??:??:??) # MAC address
         for i in /sys/class/net/*/address; do
-            mac=$(cat "$i")
+            read -r mac < "$i"
             if [ "$mac" = "$netif" ]; then
                 i=${i%/address}
                 netif=${i##*/}
index 854d294dfd4fa7f79e179a7a63a6b9c16ee37937..ddb1dc309144da4a76a6a4d4bc1dc025748185a1 100755 (executable)
@@ -151,7 +151,7 @@ for netup in /tmp/net.*.did-setup; do
     # shellcheck disable=SC1090
     [ -e /tmp/team."${netif}".info ] && . /tmp/team."${netif}".info
 
-    uuid=$(cat /proc/sys/kernel/random/uuid)
+    read -r uuid < /proc/sys/kernel/random/uuid
     if [ "$netif" = "$bridgename" ]; then
         bridge=yes
     elif [ "$netif" = "$teammaster" ]; then
index f73296f6d680616224e7f6bbc254e83c03500c60..ecfd53efb09ec3d48d1244eaac37f83de51ff755 100755 (executable)
@@ -23,7 +23,7 @@ function cms_write_config() {
 
     DEVICE=$(cd "/sys/devices/${driver}/$devbusid/net/" && set -- * && [ "$1" != "*" ] && echo "$1")
 
-    uuid=$(cat /proc/sys/kernel/random/uuid)
+    read -r uuid < /proc/sys/kernel/random/uuid
 
     IFCFGFILE=/run/initramfs/state/etc/sysconfig/network-scripts/ifcfg-$DEVICE
 
index 5f35fa72b5a465bbafc4fe2c19602a0861ab363c..6dbd61758c6af8e41dc6d39a9d9523e3d64b9a6f 100755 (executable)
@@ -17,7 +17,7 @@ _remove_dm() {
             return 0
             ;;
         *)
-            devname=$(cat /sys/block/"${dev}"/dm/name)
+            read -r devname < /sys/block/"${dev}"/dm/name
             dmsetup -v --noudevsync remove "$devname" || return $?
             ;;
     esac
index c89bda2b01783d14f908ab55cf2b63f26f8239b2..45c889d9ef4cf313fdedf867a8461852688ef04d 100755 (executable)
@@ -47,12 +47,12 @@ gatherData() {
     rootDeviceSysfsPath=/sys/class/block/${rootDeviceAbsolutePath##*/}
     if [ -f "${rootDeviceSysfsPath}/partition" ]; then
         # shellcheck disable=SC2086
-        partition=$(cat ${rootDeviceSysfsPath}/partition)
+        read -r partition < ${rootDeviceSysfsPath}/partition
     else
         partition=0
     fi
     # shellcheck disable=SC2086
-    readonly=$(cat ${rootDeviceSysfsPath}/ro)
+    read -r readonly < ${rootDeviceSysfsPath}/ro
     # shellcheck disable=SC2086
     if [ "$partition" != "1" ] || [ "$readonly" != "0" ]; then
         info "Skipping overlay creation: unpartitioned or read-only media detected"
index 3d670b7331ac5e35e45560b4b4a9cc29b45813df..0828f03f5462e52a33bb814732672fffae8fa38c 100755 (executable)
@@ -18,8 +18,8 @@ dcb=$2
 mode=$3
 vlan="yes"
 
-iflink=$(cat /sys/class/net/"$netif"/iflink)
-ifindex=$(cat /sys/class/net/"$netif"/ifindex)
+read -r iflink < /sys/class/net/"$netif"/iflink
+read -r ifindex < /sys/class/net/"$netif"/ifindex
 if [ "$iflink" != "$ifindex" ]; then
     # Skip VLAN devices
     exit 0
index 63b4ce19b9351e5efcf863f97e0961ecfa923d26..b6af7f460538d4d983e5f4f314d961a1c2586b05 100755 (executable)
@@ -59,7 +59,7 @@ handle_firmware() {
             set -- /sys/firmware/ibft/ethernet*
             echo $#
         )
-        retry=$(cat /tmp/session-retry)
+        read -r retry < /tmp/session-retry
 
         if [ "$retry" -lt "$ifaces" ]; then
             retry=$((retry + 1))
index 1ae914ea9c420dfce1a20749c8f35822bd756563..051a284e5e039aabb87c566c035b5b3012d3f95d 100755 (executable)
@@ -78,10 +78,10 @@ install_iscsiroot() {
     for flash in "${host}"/flashnode_sess-*; do
         [ -f "$flash" ] || continue
         [ ! -e "$flash/is_boot_target" ] && continue
-        is_boot=$(cat "$flash"/is_boot_target)
+        read -r is_boot < "$flash"/is_boot_target
         if [ "$is_boot" -eq 1 ]; then
             # qla4xxx flashnode session; skip iBFT discovery
-            iscsi_initiator=$(cat /sys/class/iscsi_host/"${iscsi_host}"/initiatorname)
+            read -r iscsi_initiator < /sys/class/iscsi_host/"${iscsi_host}"/initiatorname
             echo "rd.iscsi.initiator=${iscsi_initiator}"
             return
         fi
@@ -93,14 +93,14 @@ install_iscsiroot() {
                 c=${d##*/}
                 conn=${d}/iscsi_connection/${c}
                 if [ -d "${conn}" ]; then
-                    iscsi_address=$(cat "${conn}"/persistent_address)
-                    iscsi_port=$(cat "${conn}"/persistent_port)
+                    read -r iscsi_address < "${conn}"/persistent_address
+                    read -r iscsi_port < "${conn}"/persistent_port
                 fi
                 ;;
             *session)
                 if [ -d "${d}"/"${iscsi_session}" ]; then
-                    iscsi_initiator=$(cat "${d}"/"${iscsi_session}"/initiatorname)
-                    iscsi_targetname=$(cat "${d}"/"${iscsi_session}"/targetname)
+                    read -r iscsi_initiator < "${d}"/"${iscsi_session}"/initiatorname
+                    read -r iscsi_targetname < "${d}"/"${iscsi_session}"/targetname
                 fi
                 ;;
         esac
index 798b4910f6dd917deae7986ef0912342a7750bd2..d14d2ca1b1ca87c863d683b5a073331b71989a67 100755 (executable)
@@ -20,7 +20,7 @@ HOST=${ID%%:*}
 CHANNEL=${ID%%-*}
 CHANNEL=${CHANNEL#*:}
 if [ -f /sys"$DEVPATH"/scsi_target_id ]; then
-    TARGET=$(cat /sys"$DEVPATH"/scsi_target_id)
+    read -r TARGET < /sys"$DEVPATH"/scsi_target_id
 fi
 [ -z "$TARGET" ] && exit 1
 echo "$CHANNEL" "$TARGET" $LUN > /sys/class/scsi_host/host"$HOST"/scan
index e4f5bdb29d2af77c3427517a2867b82ed1f3f45f..cf6e3d7ef57953b91dfcf5e6c94b7a32bfbf247a 100755 (executable)
@@ -21,7 +21,7 @@ cmdline() {
             _rport="${_rport%%/*}"
             _classdev="/sys/class/fc_remote_ports/rport-${_rport}"
             [ -d "$_classdev" ] || return 1
-            _wwpn=$(cat "${_classdev}"/port_name)
+            read -r _wwpn < "${_classdev}"/port_name
             echo "rd.lunmask=fc,${_wwpn},${_lun}"
             return 0
         fi
@@ -31,7 +31,7 @@ cmdline() {
             _end_device="${_end_device%%/*}"
             _classdev="/sys/class/sas_device/end_device-${_end_device}"
             [ -e "$_classdev" ] || return 1
-            _sas_address=$(cat "${_classdev}"/sas_address)
+            read -r _sas_address < "${_classdev}"/sas_address
             echo "rd.lunmask=sas,${_sas_address},${_lun}"
             return 0
         fi
@@ -46,7 +46,7 @@ cmdline() {
 check() {
     [[ $hostonly ]] || [[ $mount_needs ]] && {
         [ -w /sys/module/scsi_mod/parameters/scan ] || return 255
-        scan_type=$(cat /sys/module/scsi_mod/parameters/scan)
+        read -r scan_type < /sys/module/scsi_mod/parameters/scan
         [ "$scan_type" = "manual" ] && return 0
         return 255
     }
index d10a6a67467892ad517062aa92a426cab9b61e8c..1d1fc4727bd56afc93094e2f36f49f78e887583c 100755 (executable)
@@ -20,7 +20,7 @@ HOST=${ID%%:*}
 CHANNEL=${ID%%-*}
 CHANNEL=${CHANNEL#*:}
 if [ -f /sys"$DEVPATH"/scsi_target_id ]; then
-    TARGET=$(cat /sys"$DEVPATH"/scsi_target_id)
+    read -r TARGET < /sys"$DEVPATH"/scsi_target_id
 fi
 [ -z "$TARGET" ] && exit 1
 echo 0 "$TARGET" $LUN > /sys/class/scsi_host/host"$HOST"/scan
index 95ea26ecca80075324e9f3f19a21af4bacbebee0..d99519b6b43a17f11f87029f1f49f88eebc40e74 100755 (executable)
@@ -2,7 +2,7 @@
 
 type incol2 > /dev/null 2>&1 || . /lib/dracut-lib.sh
 
-[ -f /tmp/nfs.rpc_pipefs_path ] && rpcpipefspath=$(cat /tmp/nfs.rpc_pipefs_path)
+[ -f /tmp/nfs.rpc_pipefs_path ] && read -r rpcpipefspath < /tmp/nfs.rpc_pipefs_path
 [ -z "$rpcpipefspath" ] && rpcpipefspath=var/lib/nfs/rpc_pipefs
 
 pid=$(pidof rpc.statd)
index ce5ccde2bc99bd89be4870f568e14430df949fae..476b7f77237e0c31541df2ec2380aa1b8f1fbde9 100755 (executable)
@@ -18,7 +18,7 @@ check() {
         for d in device/nvme*; do
             [ -L "$d" ] || continue
             if readlink "$d" | grep -q nvme-fabrics; then
-                trtype=$(cat "$d"/transport)
+                read -r trtype < "$d"/transport
                 break
             fi
         done
@@ -75,7 +75,7 @@ cmdline() {
         for d in device/nvme*; do
             [ -L "$d" ] || continue
             if readlink "$d" | grep -q nvme-fabrics; then
-                trtype=$(cat "$d"/transport)
+                read -r trtype < "$d"/transport
                 break
             fi
         done
@@ -98,11 +98,11 @@ cmdline() {
     }
 
     if [ -f /etc/nvme/hostnqn ]; then
-        _hostnqn=$(cat /etc/nvme/hostnqn)
+        read -r _hostnqn < /etc/nvme/hostnqn
         echo -n " rd.nvmf.hostnqn=${_hostnqn}"
     fi
     if [ -f /etc/nvme/hostid ]; then
-        _hostid=$(cat /etc/nvme/hostid)
+        read -r _hostid < /etc/nvme/hostid
         echo -n " rd.nvmf.hostid=${_hostid}"
     fi
 
index 515ed5e95042435fe52c9a68bd4c496b0ff039c9..c488b113369d83d180b5d69be6a57485e7195c54 100755 (executable)
@@ -51,7 +51,7 @@ mount_root() {
 
     if ! getargbool 0 rd.skipfsck; then
         if [ -f "$NEWROOT"/fsckoptions ]; then
-            fsckoptions=$(cat "$NEWROOT"/fsckoptions)
+            read -r fsckoptions < "$NEWROOT"/fsckoptions
         fi
 
         if [ -f "$NEWROOT"/forcefsck ] || getargbool 0 forcefsck; then
index acfb799d1b1fadd94603dec439da2c1406f46bfd..6dd6a4dba3554be21c97a06bee7a93571fb554d6 100755 (executable)
@@ -50,7 +50,7 @@ load_masterkey() {
     fi
 
     # read the kernel master key blob
-    KEYBLOB=$(cat "${MASTERKEYPATH}")
+    read -r KEYBLOB < "${MASTERKEYPATH}"
 
     # add the 'load' prefix if the key type is 'trusted'
     [ "${MASTERKEYTYPE}" = "trusted" ] \
index 2a1dccf2129f530da587791f749ea4b41f9d7975..0c1e2287e047eb18566405f32df8ce4e8d64d9d3 100755 (executable)
@@ -36,7 +36,7 @@ load_ecryptfs_key() {
     fi
 
     # read the eCryptfs encrypted key blob
-    KEYBLOB=$(cat "${ECRYPTFSKEYPATH}")
+    read -r KEYBLOB < "${ECRYPTFSKEYPATH}"
 
     # load the eCryptfs encrypted key blob
     if ! ECRYPTFSKEYID=$(keyctl add ${ECRYPTFSKEYTYPE} ${ECRYPTFSKEYDESC} "load ${KEYBLOB}" @u); then
index 913b5f12abea8568f9634c471efbcf783bc743e5..fbae5f3865e06698c725c32609cba9d4d7173b2e 100755 (executable)
@@ -50,7 +50,7 @@ load_evm_key() {
     fi
 
     # read the EVM encrypted key blob
-    KEYBLOB=$(cat "${EVMKEYPATH}")
+    read -r KEYBLOB < "${EVMKEYPATH}"
 
     # load the EVM encrypted key
     if ! EVMKEYID=$(keyctl add ${EVMKEYTYPE} ${EVMKEYDESC} "load ${KEYBLOB}" @u); then
index c8e1893b5b98e744167d2410db534b12151af916..43ea0205f973e169313fdcf305f9a607fc6c7cdc 100755 (executable)
@@ -26,7 +26,7 @@ fsck_usr() {
     local _fsckoptions
 
     if [ -f "$NEWROOT"/fsckoptions ]; then
-        _fsckoptions=$(cat "$NEWROOT"/fsckoptions)
+        read -r _fsckoptions < "$NEWROOT"/fsckoptions
     fi
 
     if [ -f "$NEWROOT"/forcefsck ] || getargbool 0 forcefsck; then
index 83ca9fab92fe4a5f1f2755e2118da62bb54f58b8..6963a19bd48e71fecabeca69db753cc0db6ca34b 100755 (executable)
@@ -932,7 +932,7 @@ _emergency_shell() {
         if [ -z "$_ctty" ]; then
             _ctty=console
             while [ -f /sys/class/tty/$_ctty/active ]; do
-                _ctty=$(cat /sys/class/tty/$_ctty/active)
+                read -r _ctty < /sys/class/tty/$_ctty/active
                 _ctty=${_ctty##* } # last one in the list
             done
             _ctty=/dev/$_ctty