meta-phosphor: initrdscripts: fix shellcheck issues

Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: Iab07f5079bad00f3cb821f60329e5ad88e45ef4b
diff --git a/meta-phosphor/recipes-phosphor/initrdscripts/files/obmc-init.sh b/meta-phosphor/recipes-phosphor/initrdscripts/files/obmc-init.sh
index c493160..8354b2b 100644
--- a/meta-phosphor/recipes-phosphor/initrdscripts/files/obmc-init.sh
+++ b/meta-phosphor/recipes-phosphor/initrdscripts/files/obmc-init.sh
@@ -7,6 +7,7 @@
 work=$rwdir/work
 
 cd /
+# shellcheck disable=SC2086
 mkdir -p $fslist
 mount dev dev -tdevtmpfs
 mount sys sys -tsysfs
@@ -27,7 +28,7 @@
 	m=$(grep -xl "$1" /sys/class/mtd/*/name)
 	m=${m%/name}
 	m=${m##*/}
-	echo $m
+	echo "$m"
 }
 
 blkid_fs_type() {
@@ -36,12 +37,12 @@
 	#    # blkid /dev/mtdblock5
 	#    /dev/mtdblock5: TYPE="squashfs"
 	# Process output to extract TYPE value "squashfs".
-	blkid $1 | sed -e 's/^.*TYPE="//' -e 's/".*$//'
+	blkid "$1" | sed -e 's/^.*TYPE="//' -e 's/".*$//'
 }
 
 probe_fs_type() {
-	fst=$(blkid_fs_type $1)
-	echo ${fst:=jffs2}
+	fst=$(blkid_fs_type "$1")
+	echo "${fst:=jffs2}"
 }
 
 # This fw_get_env_var is a possibly broken version of fw_printenv that
@@ -65,10 +66,9 @@
 	# * print the value of the variable name passed as argument
 
 	envdev=$(findmtd u-boot-env)
-	if test -n $envdev
+	if test -n "$envdev"
 	then
-		cat /dev/$envdev |
-		tr '\n\000' '\r\n' |
+		tr '\n\000' '\r\n' < "/dev/$envdev" |
 		tail -c +5 | tail -c +${copies-1} |
 		sed -ne '/^$/,$d' -e "s/^$1=//p"
 	fi
@@ -98,10 +98,10 @@
 
 	rest="${1#tftp://}"
 	path=${rest#*/}
-	host=${rest%$path}
+	host=${rest%"$path"}
 	host="${host%/}"
-	port="${host#${host%:*}}"
-	host="${host%$port}"
+	port="${host#"${host%:*}"}"
+	host="${host%"$port"}"
 	port="${port#:}"
 
 	setup_resolv
@@ -156,7 +156,7 @@
 
 Warning: No job control!  Shell exit will panic the system!
 HERE
-		export PS1=init#\ 
+		export PS1=init#\
 		exec /bin/sh
 	fi
 }
@@ -176,7 +176,7 @@
 consider_download_ftp=y
 
 rofst=squashfs
-rwfst=$(probe_fs_type $rwdev)
+rwfst=$(probe_fs_type "$rwdev")
 roopts=ro
 rwopts=rw
 
@@ -211,7 +211,7 @@
 	get_fw_env_var openbmconce >> $optfile
 fi
 
-echo rofs = $rofs $rofst   rwfs = $rwfs $rwfst
+echo "rofs = $rofs $rofst   rwfs = $rwfs $rwfst"
 
 if grep -w debug-init-sh $optfile
 then
@@ -223,7 +223,7 @@
 	fi
 fi
 
-if test "x$consider_download_files" = xy &&
+if test "$consider_download_files" = "y" &&
 	grep -w openbmc-init-download-files $optfile
 then
 	if test -f ${urlfile##*/}
@@ -236,7 +236,7 @@
 	fi
 	url="$(cat $urlfile)"
 	rest="${url#*://}"
-	proto="${url%$rest}"
+	proto="${url%"$rest"}"
 
 	if test -z "$url"
 	then
@@ -246,7 +246,7 @@
 		echo "Download failed."
 	elif test "$proto" = tftp://
 	then
-		if test "x$consider_download_tftp" = xy
+		if test "$consider_download_tftp" = "y"
 		then
 			try_tftp "$url"
 		else
@@ -254,7 +254,7 @@
 		fi
 	elif test "$proto" = http://
 	then
-		if test "x$consider_download_http" = xy
+		if test "$consider_download_http" = "y"
 		then
 			try_wget "$url"
 		else
@@ -262,7 +262,7 @@
 		fi
 	elif test "$proto" = ftp://
 	then
-		if test "x$consider_download_ftp" = xy
+		if test "$consider_download_ftp" = "y"
 		then
 			try_wget "$url"
 		else
@@ -275,15 +275,15 @@
 
 # If there are images in root move them to /run/initramfs/ or /run/ now.
 imagebasename=${image##*/}
-if test -n "${imagebasename}" && ls /${imagebasename}* > /dev/null 2>&1
+if test -n "${imagebasename}" && ls /"${imagebasename}"* > /dev/null 2>&1
 then
-	if test "x$flash_images_before_init" = xy
+	if test "$flash_images_before_init" = "y"
 	then
 		echo "Flash images found, will update before starting init."
-		mv /${imagebasename}* ${image%$imagebasename}
+		mv /"${imagebasename}"* ${image%"$imagebasename"}
 	else
 		echo "Flash images found, will use but deferring flash update."
-		mv /${imagebasename}* /run/
+		mv /"${imagebasename}"* /run/
 	fi
 fi
 
@@ -302,7 +302,7 @@
 	do_save=--save-files
 fi
 
-if test "x$force_rwfst_jffs2" = xy -a $rwfst != jffs2 -a ! -f $trigger
+if test "$force_rwfst_jffs2" = "y" -a "$rwfst" != jffs2 -a ! -f $trigger
 then
 	echo "Converting read-write overlay filesystem to jffs2 forced."
 	touch $trigger
@@ -323,7 +323,7 @@
 		fi
 		$update --no-restore-files $do_save
 		echo "Clearing read-write overlay filesystem."
-		flash_eraseall /dev/$rwfs
+		flash_eraseall "/dev/$rwfs"
 		echo "Restoring saved files to read-write overlay filesystem."
 		touch $trigger
 		$update --no-save-files --clean-saved-files
@@ -331,7 +331,7 @@
 		$update --clean-saved-files $do_save
 	fi
 
-	rwfst=$(probe_fs_type $rwdev)
+	rwfst=$(probe_fs_type "$rwdev")
 	fsck=$fsckbase$rwfst
 fi
 
@@ -356,7 +356,7 @@
 fi
 
 if grep -w copy-base-filesystem-to-ram $optfile &&
-	test ! -e /run/image-rofs && ! cp $rodev /run/image-rofs
+	test ! -e /run/image-rofs && ! cp "$rodev" /run/image-rofs
 then
 	# Remove any partial copy to avoid attempted usage later
 	if test -e  /run/image-rofs
@@ -373,19 +373,19 @@
 	roopts=$roopts,loop
 fi
 
-mount $rodev $rodir -t $rofst -o $roopts
+mount "$rodev" $rodir -t $rofst -o $roopts
 
-if test -x $rodir$fsck
+if test -x "$rodir$fsck"
 then
 	for fs in $fslist
 	do
-		mount --bind $fs $rodir/$fs
+		mount --bind "$fs" "$rodir/$fs"
 	done
-	chroot $rodir $fsck $fsckopts $rwdev
+	chroot $rodir "$fsck" $fsckopts "$rwdev"
 	rc=$?
 	for fs in $fslist
 	do
-		umount $rodir/$fs
+		umount "$rodir/$fs"
 	done
 	if test $rc -gt 1
 	then
@@ -400,7 +400,7 @@
 then
 	echo "Running with read-write overlay in RAM for this boot."
 	echo "No state will be preserved unless flash update performed."
-elif ! mount $rwdev $rwdir -t $rwfst -o $rwopts
+elif ! mount "$rwdev" $rwdir -t "$rwfst" -o $rwopts
 then
 	msg="$(cat)" << HERE
 
@@ -424,7 +424,7 @@
 # written right before rebooting or powercycling. If none exists,
 # use the image build date.
 files="$upper/var/lib/systemd/random-seed $rodir/etc/os-release"
-time=$(find $files -exec stat -c %Y {} \; | sort -n | tail -n 1)
+time=$(find "$files" -exec stat -c %Y {} \; | sort -n | tail -n 1)
 # Allow RTC coordinated time to supersede this setting
 if [ "$(date +%s)" -lt "$time" ]; then
   date -s @$((time + 5)) || true
@@ -446,7 +446,7 @@
 
 for f in $fslist
 do
-	mount --move $f root/$f
+	mount --move "$f" "root/$f"
 done
 
 exec switch_root /root $init
diff --git a/meta-phosphor/recipes-phosphor/initrdscripts/files/obmc-shutdown.sh b/meta-phosphor/recipes-phosphor/initrdscripts/files/obmc-shutdown.sh
index d3c8835..363a1a3 100644
--- a/meta-phosphor/recipes-phosphor/initrdscripts/files/obmc-shutdown.sh
+++ b/meta-phosphor/recipes-phosphor/initrdscripts/files/obmc-shutdown.sh
@@ -2,7 +2,7 @@
 
 echo shutdown: "$@"
 
-export PS1=shutdown-sh#\ 
+export PS1="shutdown-sh# "
 # exec bin/sh
 
 cd /
@@ -24,9 +24,9 @@
 mount --move /oldroot/run /mnt
 
 set -x
-for f in $( awk '/oldroot|mnt/ { print $2 }' < /proc/mounts | sort -r )
+awk '/oldroot|mnt/ { print $2 }' < /proc/mounts | sort -r | while IFS= read -r f
 do
-	umount $f
+	umount "$f"
 done
 set +x
 
@@ -43,7 +43,7 @@
 		if test -c /dev/watchdog
 		then
 			echo Pinging watchdog ${wdt+with args $wdt}
-			watchdog $wdt -F /dev/watchdog &
+			watchdog "$wdt" -F /dev/watchdog &
 			wd=$!
 		else
 			wd=
@@ -63,8 +63,8 @@
 			kill -9 $wd
 			if test -n "$wdrst"
 			then
-				echo Resetting watchdog timeouts to $wdrst
-				watchdog $wdrst -F /dev/watchdog &
+				echo "Resetting watchdog timeouts to $wdrst"
+				watchdog "$wdrst" -F /dev/watchdog &
 				sleep 1
 				# Kill the watchdog daemon, setting a timeout
 				# for the remaining shutdown work
@@ -98,5 +98,5 @@
 
 echo "Execute ${1-reboot} -f if all unmounted ok, or exec /init"
 
-export PS1=shutdown-sh#\ 
+export PS1=shutdown-sh#\
 exec /bin/sh
diff --git a/meta-phosphor/recipes-phosphor/initrdscripts/files/obmc-update.sh b/meta-phosphor/recipes-phosphor/initrdscripts/files/obmc-update.sh
index 278cd41..9f3b587 100755
--- a/meta-phosphor/recipes-phosphor/initrdscripts/files/obmc-update.sh
+++ b/meta-phosphor/recipes-phosphor/initrdscripts/files/obmc-update.sh
@@ -3,7 +3,7 @@
 echo update: "$@"
 
 echoerr() {
-	echo 1>&2 "ERROR: $@"
+	echo 1>&2 "ERROR: $*"
 }
 
 cd /
@@ -31,7 +31,7 @@
 	then
 		return 0
 	fi
-	n=$(cat /sys/class/mtd/mtd$m/name)
+	n=$(cat "/sys/class/mtd/mtd$m/name")
 	if test -n "$n" && grep -s "mtd:$n " /proc/mounts
 	then
 		return 0
@@ -42,18 +42,18 @@
 # Detect child partitions when the whole flash is to be updated.
 # Ignore mtdNro and mtdblockN names in the class subsystem directory.
 childmtds() {
-	for m in /sys/class/mtd/$1/mtd*
+	for m in "/sys/class/mtd/$1/mtd"*
 	do
 		m=${m##*/}
 		if test "${m%ro}" = "${m#mtdblock}"
 		then
-			echo $m
+			echo "$m"
 		fi
 	done
 }
 
 toobig() {
-	if test $(stat -L -c "%s" "$1") -gt $(cat /sys/class/mtd/"$2"/size)
+	if test "$(stat -L -c "%s" "$1")" -gt "$(cat "/sys/class/mtd/$2/size")"
 	then
 		return 0
 	fi
@@ -64,7 +64,7 @@
 	m=$(grep -xl "$1" /sys/class/mtd/*/name)
 	m=${m%/name}
 	m=${m##*/}
-	echo $m
+	echo "$m"
 }
 
 blkid_fs_type() {
@@ -73,12 +73,12 @@
 	#    # blkid /dev/mtdblock5
 	#    /dev/mtdblock5: TYPE="squashfs"
 	# Process output to extract TYPE value "squashfs".
-	blkid $1 | sed -e 's/^.*TYPE="//' -e 's/".*$//'
+	blkid "$1" | sed -e 's/^.*TYPE="//' -e 's/".*$//'
 }
 
 probe_fs_type() {
-	fst=$(blkid_fs_type $1)
-	echo ${fst:=jffs2}
+	fst=$(blkid_fs_type "$1")
+	echo "${fst:=jffs2}"
 }
 
 rwfs=$(findmtd rwfs)
@@ -162,16 +162,16 @@
 	esac
 done
 
-if test "x$dosave" = xy
+if test "$dosave" = "y"
 then
 	if test ! -d $upper -a -n "$rwfs"
 	then
 		mkdir -p $rwdir
-		mount $rwdev $rwdir -t $(probe_fs_type $rwdev) -o $rorwopts
+		mount "$rwdev" $rwdir -t "$(probe_fs_type "$rwdev")" -o "$rorwopts"
 		mounted=$rwdir
 	fi
 
-	while read f
+	while read -r f
 	do
 		# Entries shall start with /, no trailing /.. or embedded /../
 		if test "/${f#/}" != "$f" -o "${f%/..}" != "${f#*/../}"
@@ -209,7 +209,7 @@
 
 for f in $imglist
 do
-	m=$(findmtd ${f#$image})
+	m=$(findmtd "${f#"$image"}")
 	if test -z "$m"
 	then
 		echoerr "Unable to find mtd partition for ${f##*/}."
@@ -220,9 +220,9 @@
 		echoerr "Image ${f##*/} too big for $m."
 		exit 1
 	fi
-	for s in $m $(childmtds $m)
+	for s in $m $(childmtds "$m")
 	do
-		if test -n "$checkmount" && mtdismounted $s
+		if test -n "$checkmount" && mtdismounted "$s"
 		then
 			echoerr "Device $s is mounted, ${f##*/} is busy."
 			exit 1
@@ -234,41 +234,41 @@
 then
 	for f in $imglist
 	do
-		if test ! -s $f
+		if test ! -s "$f"
 		then
-			echo "Skipping empty update of ${f#$image}."
-			rm $f
+			echo "Skipping empty update of ${f#"$image"}."
+			rm "$f"
 			continue
 		fi
-		m=$(findmtd ${f#$image})
-		echo "Updating ${f#$image}..."
-		flashcp -v $f /dev/$m && rm $f
+		m=$(findmtd "${f#"$image"}")
+		echo "Updating ${f#"$image"}..."
+		flashcp -v "$f" "/dev/$m" && rm "$f"
 	done
 fi
 
-if test -d $save -a "x$toram" = xy
+if test -d "$save" -a "$toram" = "y"
 then
 	mkdir -p $upper
-	cp -rp $save/. $upper/
+	cp -rp "$save/." "$upper/"
 fi
 
-if test -d $save -a "x$dorestore" = xy
+if test -d "$save" -a "$dorestore" = "y"
 then
 	odir=$rwdir
 	rwdir=/run/rw
-	upper=$rwdir${upper#$odir}
+	upper=$rwdir${upper#"$odir"}
 
 	mkdir -p $rwdir
-	mount $rwdev $rwdir -t $(probe_fs_type $rwdev) -o $rwopts
-	mkdir -p $upper
-	cp -rp $save/. $upper/
+	mount "$rwdev" $rwdir -t "$(probe_fs_type "$rwdev")" -o $rwopts
+	mkdir -p "$upper"
+	cp -rp "$save/." "$upper/"
 	umount $rwdir
 	rmdir $rwdir
 fi
 
-if test "x$doclean" = xy
+if test "$doclean" = "y"
 then
-	rm -rf $save
+	rm -rf "$save"
 fi
 
 exit
diff --git a/meta-phosphor/scripts/run-repotest b/meta-phosphor/scripts/run-repotest
index bb136fd..69b34ee 100755
--- a/meta-phosphor/scripts/run-repotest
+++ b/meta-phosphor/scripts/run-repotest
@@ -142,9 +142,6 @@
 meta-openpower/recipes-phosphor/network/first-boot-set-hostname/first-boot-set-hostname.sh
 meta-openpower/recipes-phosphor/network/first-boot-set-mac/first-boot-set-mac.sh
 meta-openpower/recipes-phosphor/occ/openpower-occ-control/occ-active.sh
-meta-phosphor/recipes-phosphor/initrdscripts/files/obmc-init.sh
-meta-phosphor/recipes-phosphor/initrdscripts/files/obmc-shutdown.sh
-meta-phosphor/recipes-phosphor/initrdscripts/files/obmc-update.sh
 meta-phosphor/recipes-support/nss-pam-ldapd/files/nslcd.init
 meta-quanta/meta-common/recipes-quanta/network/usb-network/usb-network.sh
 meta-quanta/meta-gbs/recipes-gbs/gbs-bios-update/files/bios-update.sh