generate-ubi: fix shellcheck warnings

Tested: Flashed the generated witherspoon.ubi.mtd file to a witherspoon
        PNOR chip and verified the ubi volumes were present.

Change-Id: I2df088b217d0ed2f34f56b43c15fc9c6cb062338
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/generate-ubi b/generate-ubi
index d54634c..7f7c144 100755
--- a/generate-ubi
+++ b/generate-ubi
@@ -10,9 +10,9 @@
 
 Options:
    -f, --file <file>      Specify destination file. Defaults to
-                          `pwd`/<PNOR Tarball FILE, removing .squashfs.tar>.ubi.mtd
+                          $(pwd)/<PNOR Tarball FILE, removing .squashfs.tar>.ubi.mtd
                           (For example, "generate-ubi my.pnor.squashfs.tar"
-                          would generate `pwd`/my.pnor.ubi.mtd output.)
+                          would generate $(pwd)/my.pnor.ubi.mtd output.)
    -s, --size <MiB>       Specify the size of the PNOR UBI image in MiBs.
                           Defaults to 128.
    -h, --help             Display this help text and exit.
@@ -51,10 +51,10 @@
 
 if [[ -z $outfile ]]; then
     # Remove .squashfs.tar from end if present and add .ubi.mtd
-    outfile=`pwd`/${tarball%".squashfs.tar"}.ubi.mtd
+    outfile=$(pwd)/${tarball%".squashfs.tar"}.ubi.mtd
 else
   if [[ $outfile != /* ]]; then
-    outfile=`pwd`/$outfile
+    outfile=$(pwd)/$outfile
   fi
 fi
 
@@ -64,15 +64,15 @@
 manifest_file_name="MANIFEST"
 
 # Scratch directory for untarring and config file
-scratch_dir=`mktemp -d`
+scratch_dir=$(mktemp -d)
 
 # Make sure scratch directory always gets cleaned up
-trap "{ rm -r ${scratch_dir}; }" EXIT
+trap '{ rm -r ${scratch_dir}; }' EXIT
 
 squashfs_file=${scratch_dir}/${squashfs_file_name}
 manifest_file=${scratch_dir}/${manifest_file_name}
 # Untar tarball
-tar -xvf ${tarball} -C ${scratch_dir} ${squashfs_file_name} ${manifest_file_name}
+tar -xvf "${tarball}" -C "${scratch_dir}" ${squashfs_file_name} ${manifest_file_name}
 
 # All valid PNOR SquashFS Tarballs have a file named "pnor.xz.squashfs"
 if [ ! -f "${squashfs_file}" ]; then
@@ -92,7 +92,7 @@
 FLASH_PEB_SIZE="64"
 
 # Convert image size from MiB to KiB
-image_size=$((${image_size} * 1024))
+image_size=$((image_size * 1024))
 
 # Create UBI volume
 add_volume()
@@ -104,16 +104,20 @@
   image=$5
   vol_size=$6
 
-  echo \[$vol_name\] >> $config_file
-  echo mode=ubi >> $config_file
-  if [ ! -z $image ]; then
-    echo image=$image >> $config_file
+{
+  echo \["$vol_name"\]
+  echo mode=ubi
+} >> "$config_file"
+  if [ -n "$image" ]; then
+    echo image="$image" >> "$config_file"
   fi
-  echo vol_type=$vol_type >> $config_file
-  echo vol_name=$vol_name >> $config_file
-  echo vol_id=$vol_id >> $config_file
-  if [ ! -z $vol_size ]; then
-    echo vol_size=$vol_size >> $config_file
+{
+  echo vol_type="$vol_type"
+  echo vol_name="$vol_name"
+  echo vol_id="$vol_id"
+} >> "$config_file"
+  if [ -n "$vol_size" ]; then
+    echo vol_size="$vol_size" >> "$config_file"
   fi
 }
 
@@ -122,27 +126,27 @@
 {
   image_dst=$1
   image_size_kb=$2
-  dd if=/dev/zero bs=1k count=$image_size_kb | tr '\000' '\377' > $image_dst
+  dd if=/dev/zero bs=1k count="$image_size_kb" | tr '\000' '\377' > "$image_dst"
 }
 
 # Used to temporary hold the UBI image
-tmpfile=$(mktemp ${scratch_dir}/ubinized.XXXXXX)
+tmpfile=$(mktemp "${scratch_dir}"/ubinized.XXXXXX)
 
 # Configuration file used to create UBI image
 config_file=${scratch_dir}/ubinize-PNOR.cfg
 
 # The version is listed in the MANIFEST file as "version=v1.99.10-19"
 # Use the version to calculate the version id, a unique 8 hexadecimal digit id
-version_id=$(sed -ne '/version=/ {s/version=//;p}' ${manifest_file} | head -n1 | \
+version_id=$(sed -ne '/version=/ {s/version=//;p}' "${manifest_file}" | head -n1 | \
   tr -d '\n' | sha512sum | cut -b 1-8)
 
-add_volume $config_file 0 static pnor-ro-${version_id} ${squashfs_file}
-add_volume $config_file 1 dynamic pnor-prsv "" 2MiB
-add_volume $config_file 2 dynamic pnor-rw-${version_id} "" 16MiB
+add_volume "$config_file" 0 static pnor-ro-"${version_id}" "${squashfs_file}"
+add_volume "$config_file" 1 dynamic pnor-prsv "" 2MiB
+add_volume "$config_file" 2 dynamic pnor-rw-"${version_id}" "" 16MiB
 
 # Build the UBI image
-ubinize -p ${FLASH_PEB_SIZE}KiB -m ${FLASH_PAGE_SIZE} -o ${tmpfile} $config_file
-mk_nor_image ${outfile} ${image_size}
-dd bs=1k conv=notrunc seek=0 if=${tmpfile} of=${outfile}
+ubinize -p ${FLASH_PEB_SIZE}KiB -m ${FLASH_PAGE_SIZE} -o "${tmpfile}" "$config_file"
+mk_nor_image "${outfile}" "${image_size}"
+dd bs=1k conv=notrunc seek=0 if="${tmpfile}" of="${outfile}"
 
 echo "PNOR UBI image at ${outfile}"