summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Reisner <dreisner@archlinux.org>2017-03-10 22:39:52 +0100
committerDave Reisner <dreisner@archlinux.org>2017-03-11 19:09:07 +0100
commitf6275f0d91c8ad06bf0847eb7542755b8ea9e3c7 (patch)
treeeddc7b4392a29a70ddd9ea5d5187951935c4df3c
parent70511e5ccb7e2500213e04173a70c067a7c9aa35 (diff)
downloadmkinitcpio-f6275f0d91c8ad06bf0847eb7542755b8ea9e3c7.tar.gz
mkinitcpio-f6275f0d91c8ad06bf0847eb7542755b8ea9e3c7.tar.xz
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.
-rwxr-xr-xlsinitcpio20
1 files changed, 14 insertions, 6 deletions
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