Harald Hoyer adf00e
From 884e1cda7cf999ef15dd78a54a9ce0bf99afd8de Mon Sep 17 00:00:00 2001
Harald Hoyer adf00e
From: Harald Hoyer <harald@redhat.com>
Harald Hoyer adf00e
Date: Tue, 16 Apr 2013 12:44:25 +0200
Harald Hoyer adf00e
Subject: [PATCH] lsinitrd: drop use of "file"
Harald Hoyer adf00e
Harald Hoyer adf00e
---
Harald Hoyer adf00e
 dracut.spec |  4 +---
Harald Hoyer adf00e
 lsinitrd.sh | 38 ++++++++++++++++++++------------------
Harald Hoyer adf00e
 2 files changed, 21 insertions(+), 21 deletions(-)
Harald Hoyer adf00e
Harald Hoyer adf00e
diff --git a/dracut.spec b/dracut.spec
Harald Hoyer adf00e
index 197e9a0..3d42af2 100644
Harald Hoyer adf00e
--- a/dracut.spec
Harald Hoyer adf00e
+++ b/dracut.spec
Harald Hoyer adf00e
@@ -84,11 +84,9 @@ Requires: findutils
Harald Hoyer adf00e
 Requires: grep
Harald Hoyer adf00e
 Requires: hardlink
Harald Hoyer adf00e
 Requires: gzip xz
Harald Hoyer adf00e
-Requires: module-init-tools >= 3.7-9
Harald Hoyer adf00e
+Requires: kmod
Harald Hoyer adf00e
 Requires: sed
Harald Hoyer adf00e
-Requires: file
Harald Hoyer adf00e
 Requires: kpartx
Harald Hoyer adf00e
-Requires: kbd kbd-misc
Harald Hoyer adf00e
 
Harald Hoyer adf00e
 %if 0%{?fedora} || 0%{?rhel} > 6
Harald Hoyer adf00e
 Requires: util-linux >= 2.21
Harald Hoyer adf00e
diff --git a/lsinitrd.sh b/lsinitrd.sh
Harald Hoyer adf00e
index 42e30d9..0481975 100755
Harald Hoyer adf00e
--- a/lsinitrd.sh
Harald Hoyer adf00e
+++ b/lsinitrd.sh
Harald Hoyer adf00e
@@ -103,37 +103,39 @@ if ! [[ -f "$image" ]]; then
Harald Hoyer adf00e
     exit 1
Harald Hoyer adf00e
 fi
Harald Hoyer adf00e
 
Harald Hoyer adf00e
-CAT=zcat
Harald Hoyer adf00e
-FILE_T=$(file --dereference "$image")
Harald Hoyer adf00e
-
Harald Hoyer adf00e
-if echo "test"|xz|xz -dc --single-stream >/dev/null 2>&1; then
Harald Hoyer adf00e
-    XZ_SINGLE_STREAM="--single-stream"
Harald Hoyer adf00e
-fi
Harald Hoyer adf00e
-
Harald Hoyer adf00e
-if [[ "$FILE_T" =~ :\ gzip\ compressed\ data ]]; then
Harald Hoyer adf00e
-    CAT=zcat
Harald Hoyer adf00e
-elif [[ "$FILE_T" =~ :\ xz\ compressed\ data ]]; then
Harald Hoyer adf00e
-    CAT="xzcat $XZ_SINGLE_STREAM"
Harald Hoyer adf00e
-elif [[ "$FILE_T" =~ :\ XZ\ compressed\ data ]]; then
Harald Hoyer adf00e
-    CAT="xzcat $XZ_SINGLE_STREAM"
Harald Hoyer adf00e
-elif [[ "$FILE_T" =~ :\ LZMA ]]; then
Harald Hoyer adf00e
-    CAT="xzcat $XZ_SINGLE_STREAM"
Harald Hoyer adf00e
-elif [[ "$FILE_T" =~ :\ data ]]; then
Harald Hoyer adf00e
-    CAT="xzcat $XZ_SINGLE_STREAM"
Harald Hoyer adf00e
-fi
Harald Hoyer adf00e
+read -N 6 bin < "$image"
Harald Hoyer adf00e
+case $bin in
Harald Hoyer adf00e
+    $'\x1f\x8b'*)
Harald Hoyer adf00e
+        CAT="zcat";;
Harald Hoyer adf00e
+    BZh*)
Harald Hoyer adf00e
+        CAT="bzcat";;
Harald Hoyer adf00e
+    070701)
Harald Hoyer adf00e
+        CAT="cat";;
Harald Hoyer adf00e
+    *)
Harald Hoyer adf00e
+        CAT="xzcat";
Harald Hoyer adf00e
+        if echo "test"|xz|xzcat --single-stream >/dev/null 2>&1; then
Harald Hoyer adf00e
+            CAT="xzcat --single-stream"
Harald Hoyer adf00e
+        fi
Harald Hoyer adf00e
+        ;;
Harald Hoyer adf00e
+esac
Harald Hoyer adf00e
 
Harald Hoyer adf00e
 if (( ${#filenames[@]} > 0 )); then
Harald Hoyer adf00e
     $CAT $image | cpio --extract --verbose --quiet --to-stdout ${!filenames[@]} 2>/dev/null
Harald Hoyer adf00e
     exit $?
Harald Hoyer adf00e
 fi
Harald Hoyer adf00e
 
Harald Hoyer adf00e
+ret=0
Harald Hoyer adf00e
+
Harald Hoyer adf00e
 echo "$image: $(du -h $image | while read a b; do echo $a;done)"
Harald Hoyer adf00e
 echo "========================================================================"
Harald Hoyer adf00e
 $CAT "$image" | cpio --extract --verbose --quiet --to-stdout '*lib/dracut/dracut-*' 2>/dev/null
Harald Hoyer adf00e
+((ret+=$?))
Harald Hoyer adf00e
 echo "========================================================================"
Harald Hoyer adf00e
 if [ "$sorted" -eq 1 ]; then
Harald Hoyer adf00e
     $CAT "$image" | cpio --extract --verbose --quiet --list | sort -n -k5
Harald Hoyer adf00e
 else
Harald Hoyer adf00e
     $CAT "$image" | cpio --extract --verbose --quiet --list | sort -k9
Harald Hoyer adf00e
 fi
Harald Hoyer adf00e
+((ret+=$?))
Harald Hoyer adf00e
 echo "========================================================================"
Harald Hoyer adf00e
+exit $ret