Skip to content

Commit

Permalink
fix(lsinitrd.sh): shellcheck for lsinitrd.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
haraldh committed Mar 30, 2021
1 parent 43df4ee commit 0ce54e8
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions lsinitrd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ TEMP=$(getopt \
--long verbose \
-- "$@")

# shellcheck disable=SC2181
if (($? != 0)); then
usage
exit 1
Expand Down Expand Up @@ -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 ]] \
Expand Down Expand Up @@ -139,6 +140,7 @@ if ! [[ -f $image ]]; then
fi

TMPDIR="$(mktemp -d -t lsinitrd.XXXXXX)"
# shellcheck disable=SC2064
trap "rm -rf '$TMPDIR'" EXIT

dracutlibdirs() {
Expand All @@ -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 += $?))
Expand Down Expand Up @@ -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."
Expand All @@ -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")
Expand All @@ -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 --"
Expand Down Expand Up @@ -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'*)
Expand Down Expand Up @@ -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
Expand All @@ -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 += $?))
Expand All @@ -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
Expand All @@ -357,4 +362,4 @@ else
fi
fi

exit $ret
exit "$ret"

0 comments on commit 0ce54e8

Please sign in to comment.