]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
fix(lsinitrd.sh): shellcheck for lsinitrd.sh
authorHarald Hoyer <harald@redhat.com>
Tue, 30 Mar 2021 08:40:13 +0000 (10:40 +0200)
committerHarald Hoyer <harald@hoyer.xyz>
Tue, 30 Mar 2021 10:59:06 +0000 (12:59 +0200)
lsinitrd.sh

index 293d2f726fec3114d7e2647c2a8ae0bd5e036d8e..e13929eabfdd7147db7eb39b081c82e67857a218 100755 (executable)
@@ -57,6 +57,7 @@ TEMP=$(getopt \
     --long verbose \
     -- "$@")
 
+# shellcheck disable=SC2181
 if (($? != 0)); then
     usage
     exit 1
@@ -108,7 +109,7 @@ if [[ $1 ]]; then
         exit 1
     fi
 else
-    [[ -f /etc/machine-id ]] && read MACHINE_ID < /etc/machine-id
+    [[ -f /etc/machine-id ]] && read -r MACHINE_ID < /etc/machine-id
 
     if [[ -d /efi/loader/entries || -L /efi/loader/entries ]] \
         && [[ $MACHINE_ID ]] \
@@ -139,6 +140,7 @@ if ! [[ -f $image ]]; then
 fi
 
 TMPDIR="$(mktemp -d -t lsinitrd.XXXXXX)"
+# shellcheck disable=SC2064
 trap "rm -rf '$TMPDIR'" EXIT
 
 dracutlibdirs() {
@@ -161,6 +163,7 @@ extract_files() {
 
 list_modules() {
     echo "dracut modules:"
+    # shellcheck disable=SC2046
     $CAT "$image" | cpio --extract --verbose --quiet --to-stdout -- \
         $(dracutlibdirs modules.txt) 2> /dev/null
     ((ret += $?))
@@ -203,7 +206,7 @@ unpack_files() {
     fi
 }
 
-read -N 2 bin < "$image"
+read -r -N 2 bin < "$image"
 if [ "$bin" = "MZ" ]; then
     command -v objcopy > /dev/null || {
         echo "Need 'objcopy' to unpack an UEFI executable."
@@ -223,7 +226,7 @@ fi
 if ((${#filenames[@]} <= 0)) && [[ -z $unpack ]] && [[ -z $unpackearly ]]; then
     if [ -n "$uefi" ]; then
         echo -n "initrd in UEFI: $uefi: "
-        du -h $image | while read a b || [ -n "$a" ]; do echo $a; done
+        du -h "$image" | while read -r a _ || [ -n "$a" ]; do echo "$a"; done
         if [ -f "$TMPDIR/osrel.txt" ]; then
             name=$(sed -En '/^PRETTY_NAME/ s/^\w+=["'"'"']?([^"'"'"'$]*)["'"'"']?/\1/p' "$TMPDIR/osrel.txt")
             id=$(sed -En '/^ID/ s/^\w+=["'"'"']?([^"'"'"'$]*)["'"'"']?/\1/p' "$TMPDIR/osrel.txt")
@@ -240,13 +243,13 @@ if ((${#filenames[@]} <= 0)) && [[ -z $unpack ]] && [[ -z $unpackearly ]]; then
         fi
     else
         echo -n "Image: $image: "
-        du -h $image | while read a b || [ -n "$a" ]; do echo $a; done
+        du -h "$image" | while read -r a _ || [ -n "$a" ]; do echo "$a"; done
     fi
 
     echo "========================================================================"
 fi
 
-read -N 6 bin < "$image"
+read -r -N 6 bin < "$image"
 case $bin in
     $'\x71\xc7'* | 070701)
         CAT="cat --"
@@ -281,9 +284,9 @@ case $bin in
 esac
 
 if [[ $SKIP ]]; then
-    bin="$($SKIP "$image" | { read -N 6 bin && echo "$bin"; })"
+    bin="$($SKIP "$image" | { read -r -N 6 bin && echo "$bin"; })"
 else
-    read -N 6 bin < "$image"
+    read -r -N 6 bin < "$image"
 fi
 case $bin in
     $'\x1f\x8b'*)
@@ -324,9 +327,9 @@ fi
 
 if ((${#filenames[@]} > 1)); then
     TMPFILE="$TMPDIR/initrd.cpio"
-    $CAT "$image" 2> /dev/null > $TMPFILE
+    $CAT "$image" 2> /dev/null > "$TMPFILE"
     pre_decompress() {
-        cat $TMPFILE
+        cat "$TMPFILE"
     }
     CAT=pre_decompress
 fi
@@ -338,6 +341,7 @@ if [[ -n $unpack ]]; then
 elif ((${#filenames[@]} > 0)); then
     extract_files
 else
+    # shellcheck disable=SC2046
     version=$($CAT "$image" | cpio --extract --verbose --quiet --to-stdout -- \
         $(dracutlibdirs 'dracut-*') 2> /dev/null)
     ((ret += $?))
@@ -348,6 +352,7 @@ else
         echo "========================================================================"
     else
         echo -n "Arguments: "
+        # shellcheck disable=SC2046
         $CAT "$image" | cpio --extract --verbose --quiet --to-stdout -- \
             $(dracutlibdirs build-parameter.txt) 2> /dev/null
         echo
@@ -357,4 +362,4 @@ else
     fi
 fi
 
-exit $ret
+exit "$ret"