Browse Source

fix(lsinitrd.sh): shellcheck for lsinitrd.sh

master
Harald Hoyer 3 years ago committed by Harald Hoyer
parent
commit
0ce54e8033
  1. 25
      lsinitrd.sh

25
lsinitrd.sh

@ -57,6 +57,7 @@ TEMP=$(getopt \
--long verbose \ --long verbose \
-- "$@") -- "$@")


# shellcheck disable=SC2181
if (($? != 0)); then if (($? != 0)); then
usage usage
exit 1 exit 1
@ -108,7 +109,7 @@ if [[ $1 ]]; then
exit 1 exit 1
fi fi
else 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 ]] \ if [[ -d /efi/loader/entries || -L /efi/loader/entries ]] \
&& [[ $MACHINE_ID ]] \ && [[ $MACHINE_ID ]] \
@ -139,6 +140,7 @@ if ! [[ -f $image ]]; then
fi fi


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


dracutlibdirs() { dracutlibdirs() {
@ -161,6 +163,7 @@ extract_files() {


list_modules() { list_modules() {
echo "dracut modules:" echo "dracut modules:"
# shellcheck disable=SC2046
$CAT "$image" | cpio --extract --verbose --quiet --to-stdout -- \ $CAT "$image" | cpio --extract --verbose --quiet --to-stdout -- \
$(dracutlibdirs modules.txt) 2> /dev/null $(dracutlibdirs modules.txt) 2> /dev/null
((ret += $?)) ((ret += $?))
@ -203,7 +206,7 @@ unpack_files() {
fi fi
} }


read -N 2 bin < "$image" read -r -N 2 bin < "$image"
if [ "$bin" = "MZ" ]; then if [ "$bin" = "MZ" ]; then
command -v objcopy > /dev/null || { command -v objcopy > /dev/null || {
echo "Need 'objcopy' to unpack an UEFI executable." echo "Need 'objcopy' to unpack an UEFI executable."
@ -223,7 +226,7 @@ fi
if ((${#filenames[@]} <= 0)) && [[ -z $unpack ]] && [[ -z $unpackearly ]]; then if ((${#filenames[@]} <= 0)) && [[ -z $unpack ]] && [[ -z $unpackearly ]]; then
if [ -n "$uefi" ]; then if [ -n "$uefi" ]; then
echo -n "initrd in UEFI: $uefi: " 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 if [ -f "$TMPDIR/osrel.txt" ]; then
name=$(sed -En '/^PRETTY_NAME/ s/^\w+=["'"'"']?([^"'"'"'$]*)["'"'"']?/\1/p' "$TMPDIR/osrel.txt") name=$(sed -En '/^PRETTY_NAME/ s/^\w+=["'"'"']?([^"'"'"'$]*)["'"'"']?/\1/p' "$TMPDIR/osrel.txt")
id=$(sed -En '/^ID/ 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 fi
else else
echo -n "Image: $image: " 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 fi


echo "========================================================================" echo "========================================================================"
fi fi


read -N 6 bin < "$image" read -r -N 6 bin < "$image"
case $bin in case $bin in
$'\x71\xc7'* | 070701) $'\x71\xc7'* | 070701)
CAT="cat --" CAT="cat --"
@ -281,9 +284,9 @@ case $bin in
esac esac


if [[ $SKIP ]]; then if [[ $SKIP ]]; then
bin="$($SKIP "$image" | { read -N 6 bin && echo "$bin"; })" bin="$($SKIP "$image" | { read -r -N 6 bin && echo "$bin"; })"
else else
read -N 6 bin < "$image" read -r -N 6 bin < "$image"
fi fi
case $bin in case $bin in
$'\x1f\x8b'*) $'\x1f\x8b'*)
@ -324,9 +327,9 @@ fi


if ((${#filenames[@]} > 1)); then if ((${#filenames[@]} > 1)); then
TMPFILE="$TMPDIR/initrd.cpio" TMPFILE="$TMPDIR/initrd.cpio"
$CAT "$image" 2> /dev/null > $TMPFILE $CAT "$image" 2> /dev/null > "$TMPFILE"
pre_decompress() { pre_decompress() {
cat $TMPFILE cat "$TMPFILE"
} }
CAT=pre_decompress CAT=pre_decompress
fi fi
@ -338,6 +341,7 @@ if [[ -n $unpack ]]; then
elif ((${#filenames[@]} > 0)); then elif ((${#filenames[@]} > 0)); then
extract_files extract_files
else else
# shellcheck disable=SC2046
version=$($CAT "$image" | cpio --extract --verbose --quiet --to-stdout -- \ version=$($CAT "$image" | cpio --extract --verbose --quiet --to-stdout -- \
$(dracutlibdirs 'dracut-*') 2> /dev/null) $(dracutlibdirs 'dracut-*') 2> /dev/null)
((ret += $?)) ((ret += $?))
@ -348,6 +352,7 @@ else
echo "========================================================================" echo "========================================================================"
else else
echo -n "Arguments: " echo -n "Arguments: "
# shellcheck disable=SC2046
$CAT "$image" | cpio --extract --verbose --quiet --to-stdout -- \ $CAT "$image" | cpio --extract --verbose --quiet --to-stdout -- \
$(dracutlibdirs build-parameter.txt) 2> /dev/null $(dracutlibdirs build-parameter.txt) 2> /dev/null
echo echo
@ -357,4 +362,4 @@ else
fi fi
fi fi


exit $ret exit "$ret"

Loading…
Cancel
Save