From f6275f0d91c8ad06bf0847eb7542755b8ea9e3c7 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Fri, 10 Mar 2017 16:39:52 -0500 Subject: lsinitcpio: avoid null byte warnings with bash 4.3 On compressed images, bash 4.3 gets salty: $ lsinitcpio initrd.gz >/dev/null /usr/bin/lsinitcpio: line 78: warning: command substitution: ignored null byte in input /usr/bin/lsinitcpio: line 90: warning: command substitution: ignored null byte in input Tidy up all of our hexdump comparisons via command substitution to use process substitution instead. --- lsinitcpio | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'lsinitcpio') diff --git a/lsinitcpio b/lsinitcpio index faad720..7be0649 100755 --- a/lsinitcpio +++ b/lsinitcpio @@ -75,7 +75,10 @@ size_to_human() { } detect_filetype() { - case $(hexdump -n 6 -e '"%c"' "$1") in + local bytes + + read -rd '' bytes < <(hexdump -n 6 -e '"%c"' "$1") + case $bytes in '070701') # no compression echo @@ -87,17 +90,20 @@ detect_filetype() { ;; esac - if [[ $(hexdump -n 4 -e '"%c"' "$1") = $'\x89LZO' ]]; then + read -rd '' bytes < <(hexdump -n 4 -e '"%c"' "$1") + if [[ $bytes = $'\x89LZO' ]]; then echo 'lzop' return fi - if [[ $(hexdump -n 2 -e '"%x"' "$1") = '8b1f' ]]; then + read -rd '' bytes < <(hexdump -n 2 -e '"%x"' "$1") + if [[ $bytes = '8b1f' ]]; then echo 'gzip' return fi - case $(hexdump -n 4 -e '"%x"' "$1") in + read -rd '' bytes < <(hexdump -n 4 -e '"%x"' "$1") + case $bytes in 184d2204) error 'Newer lz4 stream format detected! This may not boot!' echo 'lz4' @@ -109,7 +115,8 @@ detect_filetype() { ;; esac - if [[ $(hexdump -n 3 -e '"%c"' "$1") == 'BZh' ]]; then + read -rd '' bytes < <(hexdump -n 3 -e '"%c"' "$1") + if [[ $bytes == 'BZh' ]]; then echo 'bzip2' return fi @@ -118,7 +125,8 @@ detect_filetype() { # do it without reading large portions of the stream. this # check is good enough for GNU tar, apparently, so it's good # enough for me. - if [[ $(hexdump -n 3 -e '"%x"' "$1") = '5d' ]]; then + read -rd '' bytes < <(hexdump -n 3 -e '"%x"' "$1") + if [[ $bytes = '5d' ]]; then echo 'lzma' return fi -- cgit v1.2.3-24-g4f1b