Harald Hoyer 460d2c
From 3b92d8bf84d8dac57ffc1293f6f5c6d621ddd267 Mon Sep 17 00:00:00 2001
Harald Hoyer 460d2c
From: =?UTF-8?q?=C3=89rico=20Rolim?= <erico.erc@gmail.com>
Harald Hoyer 460d2c
Date: Sun, 23 Aug 2020 18:15:32 -0300
Harald Hoyer 460d2c
Subject: [PATCH] dracut.sh: fix errors pointed out by shellcheck.
Harald Hoyer 460d2c
Harald Hoyer 460d2c
- use [ ] instead of calling test manually, as most of the script is
Harald Hoyer 460d2c
doing.
Harald Hoyer 460d2c
Harald Hoyer 460d2c
- use quotes in hostonly_cmdline blocks, specially when dealing with the
Harald Hoyer 460d2c
conf files, whose names are set by users/system administrators
Harald Hoyer 460d2c
Harald Hoyer 460d2c
- uefi_splash_image was being assigned set to `${dracutsysroot}...`, which
Harald Hoyer 460d2c
is a variable that doesn't exist.
Harald Hoyer 460d2c
Harald Hoyer 460d2c
- we don't want the conditional to run the output of fsfreeze as
Harald Hoyer 460d2c
commands. Instead, we just need to know if any of the fsfreeze commands
Harald Hoyer 460d2c
failed.
Harald Hoyer 460d2c
---
Harald Hoyer 460d2c
 dracut.sh | 16 ++++++++--------
Harald Hoyer 460d2c
 1 file changed, 8 insertions(+), 8 deletions(-)
Harald Hoyer 460d2c
Harald Hoyer 460d2c
diff --git a/dracut.sh b/dracut.sh
Harald Hoyer 460d2c
index c439fa02..fa2388fe 100755
Harald Hoyer 460d2c
--- a/dracut.sh
Harald Hoyer 460d2c
+++ b/dracut.sh
Harald Hoyer 460d2c
@@ -1731,7 +1731,7 @@ fi
Harald Hoyer 460d2c
 if [[ $do_strip = yes ]] ; then
Harald Hoyer 460d2c
     # Prefer strip from elfutils for package size
Harald Hoyer 460d2c
     declare strip_cmd=$(command -v eu-strip)
Harald Hoyer 460d2c
-    test -z "$strip_cmd" && strip_cmd="strip"
Harald Hoyer 460d2c
+    [ -z "$strip_cmd" ] && strip_cmd="strip"
Harald Hoyer 460d2c
 
Harald Hoyer 460d2c
     for p in $strip_cmd xargs find; do
Harald Hoyer 460d2c
         if ! type -P $p >/dev/null; then
Harald Hoyer 460d2c
@@ -1824,7 +1824,7 @@ if [[ $hostonly_cmdline == "yes" ]] ; then
Harald Hoyer 460d2c
         dinfo "Stored kernel commandline:"
Harald Hoyer 460d2c
         for conf in $initdir/etc/cmdline.d/*.conf ; do
Harald Hoyer 460d2c
             [ -e "$conf" ] || continue
Harald Hoyer 460d2c
-            dinfo "$(< $conf)"
Harald Hoyer 460d2c
+            dinfo "$(< "$conf")"
Harald Hoyer 460d2c
             _stored_cmdline=1
Harald Hoyer 460d2c
         done
Harald Hoyer 460d2c
     fi
Harald Hoyer 460d2c
@@ -2004,10 +2004,10 @@ umask 077
Harald Hoyer 460d2c
 if [[ $uefi = yes ]]; then
Harald Hoyer 460d2c
     if [[ $kernel_cmdline ]]; then
Harald Hoyer 460d2c
         echo -n "$kernel_cmdline" > "$uefi_outdir/cmdline.txt"
Harald Hoyer 460d2c
-    elif [[ $hostonly_cmdline = yes ]] && [ -d $initdir/etc/cmdline.d ];then
Harald Hoyer 460d2c
-        for conf in $initdir/etc/cmdline.d/*.conf ; do
Harald Hoyer 460d2c
+    elif [[ $hostonly_cmdline = yes ]] && [ -d "$initdir/etc/cmdline.d" ];then
Harald Hoyer 460d2c
+        for conf in "$initdir"/etc/cmdline.d/*.conf ; do
Harald Hoyer 460d2c
             [ -e "$conf" ] || continue
Harald Hoyer 460d2c
-            printf "%s " "$(< $conf)" >> "$uefi_outdir/cmdline.txt"
Harald Hoyer 460d2c
+            printf "%s " "$(< "$conf")" >> "$uefi_outdir/cmdline.txt"
Harald Hoyer 460d2c
         done
Harald Hoyer 460d2c
     else
Harald Hoyer 460d2c
         do_print_cmdline > "$uefi_outdir/cmdline.txt"
Harald Hoyer 460d2c
@@ -2020,7 +2020,7 @@ if [[ $uefi = yes ]]; then
Harald Hoyer 460d2c
     [[ -s $dracutsysrootdir/usr/lib/os-release ]] && uefi_osrelease="$dracutsysrootdir/usr/lib/os-release"
Harald Hoyer 460d2c
     [[ -s $dracutsysrootdir/etc/os-release ]] && uefi_osrelease="$dracutsysrootdir/etc/os-release"
Harald Hoyer 460d2c
     [[ -s "${dracutsysrootdir}${uefi_splash_image}" ]] && \
Harald Hoyer 460d2c
-        uefi_splash_image="${dracutsysroot}${uefi_splash_image}" || unset uefi_splash_image
Harald Hoyer 460d2c
+        uefi_splash_image="${dracutsysrootdir}${uefi_splash_image}" || unset uefi_splash_image
Harald Hoyer 460d2c
 
Harald Hoyer 460d2c
     if objcopy \
Harald Hoyer 460d2c
            ${uefi_osrelease:+--add-section .osrel=$uefi_osrelease --change-section-vma .osrel=0x20000} \
Harald Hoyer 460d2c
@@ -2100,7 +2100,7 @@ freeze_ok_for_fstype() {
Harald Hoyer 460d2c
 # and there's no reason to sync, and *definitely* no reason to fsfreeze.
Harald Hoyer 460d2c
 # Another case where this happens is rpm-ostree, which performs its own sync/fsfreeze
Harald Hoyer 460d2c
 # globally.  See e.g. https://github.com/ostreedev/ostree/commit/8642ef5ab3fec3ac8eb8f193054852f83a8bc4d0
Harald Hoyer 460d2c
-if test -d $dracutsysrootdir/run/systemd/system; then
Harald Hoyer 460d2c
+if [ -d "$dracutsysrootdir/run/systemd/system" ]; then
Harald Hoyer 460d2c
     if ! sync "$outfile" 2> /dev/null; then
Harald Hoyer 460d2c
         dinfo "dracut: sync operation on newly created initramfs $outfile failed"
Harald Hoyer 460d2c
         exit 1
Harald Hoyer 460d2c
@@ -2108,7 +2108,7 @@ if test -d $dracutsysrootdir/run/systemd/system; then
Harald Hoyer 460d2c
 
Harald Hoyer 460d2c
     # use fsfreeze only if we're not writing to /
Harald Hoyer 460d2c
     if [[ "$(stat -c %m -- "$outfile")" != "/" ]] && freeze_ok_for_fstype "$outfile"; then
Harald Hoyer 460d2c
-        if ! $(fsfreeze -f $(dirname "$outfile") 2>/dev/null && fsfreeze -u $(dirname "$outfile") 2>/dev/null); then
Harald Hoyer 460d2c
+        if ! (fsfreeze -f "$(dirname "$outfile")" 2>/dev/null && fsfreeze -u "$(dirname "$outfile")" 2>/dev/null); then
Harald Hoyer 460d2c
             dinfo "dracut: warning: could not fsfreeze $(dirname "$outfile")"
Harald Hoyer 460d2c
         fi
Harald Hoyer 460d2c
     fi
Harald Hoyer 460d2c