summaryrefslogtreecommitdiffstats
path: root/scripts/rpm2cpio.sh
diff options
context:
space:
mode:
authorAlexander Kanavin <alexander.kanavin@linux.intel.com>2017-01-26 18:04:31 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-03-14 14:42:17 +0000
commitaa17362d339164e8d6c9fcc9d0c24862a191af29 (patch)
tree3847e29acc4e00bbb1fa6902741f1427257aad63 /scripts/rpm2cpio.sh
parent67615e01751bdba4e2186c86c44bebd9ded5233b (diff)
downloadpoky-aa17362d339164e8d6c9fcc9d0c24862a191af29.tar.gz
scripts/rpm2cpio.sh: replace 5.x version with 4.x version
(From OE-Core rev: a7da1aade118d1ccf1b286f82556cd9f706bd2a4) Signed-off-by: Alexander Kanavin <alexander.kanavin@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/rpm2cpio.sh')
-rwxr-xr-xscripts/rpm2cpio.sh108
1 files changed, 55 insertions, 53 deletions
diff --git a/scripts/rpm2cpio.sh b/scripts/rpm2cpio.sh
index 5df8c0f705..cf23472ba9 100755
--- a/scripts/rpm2cpio.sh
+++ b/scripts/rpm2cpio.sh
@@ -1,53 +1,55 @@
1#!/bin/sh 1#!/bin/sh -efu
2 2
3# This comes from the RPM5 5.4.0 distribution. 3# This file comes from rpm 4.x distribution
4 4
5pkg=$1 5fatal() {
6if [ "$pkg" = "" -o ! -e "$pkg" ]; then 6 echo "$*" >&2
7 echo "no package supplied" 1>&2 7 exit 1
8 exit 1 8}
9fi 9
10 10pkg="$1"
11leadsize=96 11[ -n "$pkg" -a -e "$pkg" ] ||
12o=`expr $leadsize + 8` 12 fatal "No package supplied"
13set `od -j $o -N 8 -t u1 $pkg` 13
14il=`expr 256 \* \( 256 \* \( 256 \* $2 + $3 \) + $4 \) + $5` 14_dd() {
15dl=`expr 256 \* \( 256 \* \( 256 \* $6 + $7 \) + $8 \) + $9` 15 local o="$1"; shift
16# echo "sig il: $il dl: $dl" 16 dd if="$pkg" skip="$o" iflag=skip_bytes status=none $*
17 17}
18sigsize=`expr 8 + 16 \* $il + $dl` 18
19o=`expr $o + $sigsize + \( 8 - \( $sigsize \% 8 \) \) \% 8 + 8` 19calcsize() {
20set `od -j $o -N 8 -t u1 $pkg` 20 offset=$(($1 + 8))
21il=`expr 256 \* \( 256 \* \( 256 \* $2 + $3 \) + $4 \) + $5` 21
22dl=`expr 256 \* \( 256 \* \( 256 \* $6 + $7 \) + $8 \) + $9` 22 local i b b0 b1 b2 b3 b4 b5 b6 b7
23# echo "hdr il: $il dl: $dl" 23
24 24 i=0
25hdrsize=`expr 8 + 16 \* $il + $dl` 25 while [ $i -lt 8 ]; do
26o=`expr $o + $hdrsize` 26 b="$(_dd $(($offset + $i)) bs=1 count=1)"
27EXTRACTOR="dd if=$pkg ibs=$o skip=1" 27 [ -z "$b" ] &&
28 28 b="0" ||
29COMPRESSION=`($EXTRACTOR |file -) 2>/dev/null` 29 b="$(exec printf '%u\n' "'$b")"
30if echo $COMPRESSION |grep -iq gzip; then 30 eval "b$i=\$b"
31 DECOMPRESSOR=gunzip 31 i=$(($i + 1))
32elif echo $COMPRESSION |grep -iq bzip2; then 32 done
33 DECOMPRESSOR=bunzip2 33
34elif echo $COMPRESSION |grep -iq xz; then 34 rsize=$((8 + ((($b0 << 24) + ($b1 << 16) + ($b2 << 8) + $b3) << 4) + ($b4 << 24) + ($b5 << 16) + ($b6 << 8) + $b7))
35 DECOMPRESSOR=unxz 35 offset=$(($offset + $rsize))
36elif echo $COMPRESSION |grep -iq cpio; then 36}
37 DECOMPRESSOR=cat 37
38else 38case "$(_dd 0 bs=8 count=1)" in
39 # Most versions of file don't support LZMA, therefore we assume 39 "$(printf '\355\253\356\333')"*) ;; # '\xed\xab\xee\xdb'
40 # anything not detected is LZMA 40 *) fatal "File doesn't look like rpm: $pkg" ;;
41 DECOMPRESSOR=`which unlzma 2>/dev/null` 41esac
42 case "$DECOMPRESSOR" in 42
43 /* ) ;; 43calcsize 96
44 * ) DECOMPRESSOR=`which lzmash 2>/dev/null` 44sigsize=$rsize
45 case "$DECOMPRESSOR" in 45
46 /* ) DECOMPRESSOR="lzmash -d -c" ;; 46calcsize $(($offset + (8 - ($sigsize % 8)) % 8))
47 * ) DECOMPRESSOR=cat ;; 47hdrsize=$rsize
48 esac 48
49 ;; 49case "$(_dd $offset bs=3 count=1)" in
50 esac 50 "$(printf '\102\132')"*) _dd $offset | bunzip2 ;; # '\x42\x5a'
51fi 51 "$(printf '\037\213')"*) _dd $offset | gunzip ;; # '\x1f\x8b'
52 52 "$(printf '\375\067')"*) _dd $offset | xzcat ;; # '\xfd\x37'
53$EXTRACTOR 2>/dev/null | $DECOMPRESSOR 53 "$(printf '\135\000')"*) _dd $offset | unlzma ;; # '\x5d\x00'
54 *) fatal "Unrecognized rpm file: $pkg" ;;
55esac