Blob Blame History Raw
From d6b9aac6d0f8d007fa9ebf073a665857d8b0b0b4 Mon Sep 17 00:00:00 2001
From: Mike Gilbert <floppym@gentoo.org>
Date: Tue, 14 Jul 2015 22:22:14 -0400
Subject: [PATCH] Replace echo -n with printf in code with a /bin/sh shebang

POSIX does not mandate that echo support the -n parameter.
printf has more well-defined behavior.

(cherry picked from commit 5899f2f5163de4d68fbb35831e1f2230c22c71b3)
---
 modules.d/04watchdog/watchdog-stop.sh      | 2 +-
 modules.d/40network/net-lib.sh             | 2 +-
 modules.d/45ifcfg/write-ifcfg.sh           | 2 +-
 modules.d/90lvm/lvm_scan.sh                | 4 ++--
 modules.d/98usrmount/mount-usr.sh          | 2 +-
 modules.d/99base/dracut-lib.sh             | 6 ++++--
 modules.d/99base/init.sh                   | 4 ++--
 test/TEST-10-RAID/create-root.sh           | 2 +-
 test/TEST-10-RAID/cryptroot-ask.sh         | 2 +-
 test/TEST-12-RAID-DEG/create-root.sh       | 2 +-
 test/TEST-12-RAID-DEG/cryptroot-ask.sh     | 2 +-
 test/TEST-13-ENC-RAID-LVM/create-root.sh   | 2 +-
 test/TEST-13-ENC-RAID-LVM/cryptroot-ask.sh | 2 +-
 test/TEST-14-IMSM/cryptroot-ask.sh         | 2 +-
 test/TEST-40-NBD/create-root.sh            | 2 +-
 test/TEST-40-NBD/cryptroot-ask.sh          | 2 +-
 16 files changed, 21 insertions(+), 19 deletions(-)

diff --git a/modules.d/04watchdog/watchdog-stop.sh b/modules.d/04watchdog/watchdog-stop.sh
index 91d45d6..921f969 100755
--- a/modules.d/04watchdog/watchdog-stop.sh
+++ b/modules.d/04watchdog/watchdog-stop.sh
@@ -1,2 +1,2 @@
 #!/bin/sh
-[ -c /dev/watchdog ] && echo -n 'V' > /dev/watchdog
+[ -c /dev/watchdog ] && printf 'V' > /dev/watchdog
diff --git a/modules.d/40network/net-lib.sh b/modules.d/40network/net-lib.sh
index 07ea570..f91d169 100755
--- a/modules.d/40network/net-lib.sh
+++ b/modules.d/40network/net-lib.sh
@@ -211,7 +211,7 @@ set_ifname() {
 fix_bootif() {
     local macaddr=${1}
     local IFS='-'
-    macaddr=$(for i in ${macaddr} ; do echo -n $i:; done)
+    macaddr=$(printf '%s:' ${macaddr})
     macaddr=${macaddr%:}
     # strip hardware type field from pxelinux
     [ -n "${macaddr%??:??:??:??:??:??}" ] && macaddr=${macaddr#??:}
diff --git a/modules.d/45ifcfg/write-ifcfg.sh b/modules.d/45ifcfg/write-ifcfg.sh
index f3a1c10..a5114be 100755
--- a/modules.d/45ifcfg/write-ifcfg.sh
+++ b/modules.d/45ifcfg/write-ifcfg.sh
@@ -50,7 +50,7 @@ print_s390() {
         for i in /sys/class/net/$_netif/device/cdev[0-9]*; do
             [ -e $i ] || continue
             channel=$(readlink -f $i)
-            echo -n "${channel##*/},"
+            printf '%s' "${channel##*/},"
         done
     })
     [ -n "$SUBCHANNELS" ] || return 1
diff --git a/modules.d/90lvm/lvm_scan.sh b/modules.d/90lvm/lvm_scan.sh
index f87831c..ae6f177 100755
--- a/modules.d/90lvm/lvm_scan.sh
+++ b/modules.d/90lvm/lvm_scan.sh
@@ -17,14 +17,14 @@ SNAPSIZE=$(getargs rd.lvm.snapsize -d rd_LVM_SNAPSIZE=)
 lvmdevs=$(
     for f in /tmp/.lvm_scan-*; do
         [ -e "$f" ] || continue
-        echo -n "${f##/tmp/.lvm_scan-} "
+        printf '%s' "${f##/tmp/.lvm_scan-} "
     done
 )
 
 if [ ! -e /etc/lvm/lvm.conf ]; then
     {
         echo 'devices {';
-        echo -n '    filter = [ '
+        printf '    filter = [ '
         for dev in $lvmdevs; do
             printf '"a|^/dev/%s$|", ' $dev;
         done;
diff --git a/modules.d/98usrmount/mount-usr.sh b/modules.d/98usrmount/mount-usr.sh
index de7dcc2..8026db3 100755
--- a/modules.d/98usrmount/mount-usr.sh
+++ b/modules.d/98usrmount/mount-usr.sh
@@ -14,7 +14,7 @@ filtersubvol() {
     while [ $# -gt 0 ]; do
         case $1 in
             subvol\=*) :;;
-            *) echo -n "${1}," ;;
+            *) printf '%s' "${1}," ;;
         esac
         shift
     done
diff --git a/modules.d/99base/dracut-lib.sh b/modules.d/99base/dracut-lib.sh
index 71dcedc..c2b6108 100755
--- a/modules.d/99base/dracut-lib.sh
+++ b/modules.d/99base/dracut-lib.sh
@@ -295,7 +295,7 @@ _dogetargs() {
         fi
     done
     if [ -n "$_found" ]; then
-        [ $# -gt 0 ] && echo -n "$@"
+        [ $# -gt 0 ] && printf '%s' "$*"
         return 0
     fi
     return 1;
@@ -326,7 +326,9 @@ getargs() {
     done
     if [ -n "$_gfound" ]; then
         if [ $# -gt 0 ]; then
-            echo -n "$@"
+            printf '%s' "$*"
+        else
+            printf 1
         fi
         debug_on
         return 0
diff --git a/modules.d/99base/init.sh b/modules.d/99base/init.sh
index dcc62d2..a07d0f9 100755
--- a/modules.d/99base/init.sh
+++ b/modules.d/99base/init.sh
@@ -253,8 +253,8 @@ while :; do
 done
 
 {
-    echo -n "Mounted root filesystem "
-    while read dev mp rest; do [ "$mp" = "$NEWROOT" ] && echo $dev; done < /proc/mounts
+    printf "Mounted root filesystem "
+    while read dev mp rest || [ -n "$dev" ]; do [ "$mp" = "$NEWROOT" ] && echo $dev; done < /proc/mounts
 } | vinfo
 
 # pre pivot scripts are sourced just before we doing cleanup and switch over
diff --git a/test/TEST-10-RAID/create-root.sh b/test/TEST-10-RAID/create-root.sh
index 5055413..be7a3a0 100755
--- a/test/TEST-10-RAID/create-root.sh
+++ b/test/TEST-10-RAID/create-root.sh
@@ -18,7 +18,7 @@ mdadm --create /dev/md0 --run --auto=yes --level=5 --raid-devices=3 /dev/sda2 /d
 # randomly.
 mdadm -W /dev/md0
 set -e
-echo -n test >keyfile
+printf test >keyfile
 cryptsetup -q luksFormat /dev/md0 /keyfile
 echo "The passphrase is test"
 cryptsetup luksOpen /dev/md0 dracut_crypt_test </keyfile
diff --git a/test/TEST-10-RAID/cryptroot-ask.sh b/test/TEST-10-RAID/cryptroot-ask.sh
index 407d067..c39eff6 100755
--- a/test/TEST-10-RAID/cryptroot-ask.sh
+++ b/test/TEST-10-RAID/cryptroot-ask.sh
@@ -1,5 +1,5 @@
 #!/bin/sh
 
 [ -b "/dev/mapper/$2" ] && exit 0
-echo -n test >/keyfile
+printf test >/keyfile
 /sbin/cryptsetup luksOpen "$1" "$2" </keyfile
diff --git a/test/TEST-12-RAID-DEG/create-root.sh b/test/TEST-12-RAID-DEG/create-root.sh
index 699c27c..5709060 100755
--- a/test/TEST-12-RAID-DEG/create-root.sh
+++ b/test/TEST-12-RAID-DEG/create-root.sh
@@ -20,7 +20,7 @@ mdadm --create /dev/md0 --run --auto=yes --level=5 --raid-devices=3 /dev/sdb /de
 # wait for the array to finish initailizing, otherwise this sometimes fails
 # randomly.
 mdadm -W /dev/md0
-echo -n test >keyfile
+printf test >keyfile
 cryptsetup -q luksFormat /dev/md0 /keyfile
 echo "The passphrase is test"
 set -e
diff --git a/test/TEST-12-RAID-DEG/cryptroot-ask.sh b/test/TEST-12-RAID-DEG/cryptroot-ask.sh
index db27c5b..78ed7f5 100755
--- a/test/TEST-12-RAID-DEG/cryptroot-ask.sh
+++ b/test/TEST-12-RAID-DEG/cryptroot-ask.sh
@@ -1,6 +1,6 @@
 #!/bin/sh
 
 [ -b /dev/mapper/$2 ] && exit 0
-echo -n test >/keyfile
+printf test >/keyfile
 /sbin/cryptsetup luksOpen $1 $2 </keyfile
 
diff --git a/test/TEST-13-ENC-RAID-LVM/create-root.sh b/test/TEST-13-ENC-RAID-LVM/create-root.sh
index af83c23..4e10461 100755
--- a/test/TEST-13-ENC-RAID-LVM/create-root.sh
+++ b/test/TEST-13-ENC-RAID-LVM/create-root.sh
@@ -14,7 +14,7 @@ sfdisk -C 2560 -H 2 -S 32 -L /dev/sda <<EOF
 ,800
 EOF
 udevadm settle
-echo -n test >keyfile
+printf test >keyfile
 cryptsetup -q luksFormat /dev/sda2 /keyfile
 cryptsetup -q luksFormat /dev/sda3 /keyfile
 cryptsetup -q luksFormat /dev/sda4 /keyfile
diff --git a/test/TEST-13-ENC-RAID-LVM/cryptroot-ask.sh b/test/TEST-13-ENC-RAID-LVM/cryptroot-ask.sh
index db27c5b..78ed7f5 100755
--- a/test/TEST-13-ENC-RAID-LVM/cryptroot-ask.sh
+++ b/test/TEST-13-ENC-RAID-LVM/cryptroot-ask.sh
@@ -1,6 +1,6 @@
 #!/bin/sh
 
 [ -b /dev/mapper/$2 ] && exit 0
-echo -n test >/keyfile
+printf test >/keyfile
 /sbin/cryptsetup luksOpen $1 $2 </keyfile
 
diff --git a/test/TEST-14-IMSM/cryptroot-ask.sh b/test/TEST-14-IMSM/cryptroot-ask.sh
index db27c5b..78ed7f5 100755
--- a/test/TEST-14-IMSM/cryptroot-ask.sh
+++ b/test/TEST-14-IMSM/cryptroot-ask.sh
@@ -1,6 +1,6 @@
 #!/bin/sh
 
 [ -b /dev/mapper/$2 ] && exit 0
-echo -n test >/keyfile
+printf test >/keyfile
 /sbin/cryptsetup luksOpen $1 $2 </keyfile
 
diff --git a/test/TEST-40-NBD/create-root.sh b/test/TEST-40-NBD/create-root.sh
index cb27a60..4df472a 100755
--- a/test/TEST-40-NBD/create-root.sh
+++ b/test/TEST-40-NBD/create-root.sh
@@ -5,7 +5,7 @@ for x in 64-lvm.rules 70-mdadm.rules 99-mount-rules; do
 done
 rm -f -- /etc/lvm/lvm.conf
 udevadm control --reload
-echo -n test >keyfile
+printf test >keyfile
 cryptsetup -q luksFormat /dev/sdb /keyfile
 echo "The passphrase is test"
 cryptsetup luksOpen /dev/sdb dracut_crypt_test </keyfile && \
diff --git a/test/TEST-40-NBD/cryptroot-ask.sh b/test/TEST-40-NBD/cryptroot-ask.sh
index db27c5b..78ed7f5 100755
--- a/test/TEST-40-NBD/cryptroot-ask.sh
+++ b/test/TEST-40-NBD/cryptroot-ask.sh
@@ -1,6 +1,6 @@
 #!/bin/sh
 
 [ -b /dev/mapper/$2 ] && exit 0
-echo -n test >/keyfile
+printf test >/keyfile
 /sbin/cryptsetup luksOpen $1 $2 </keyfile