summaryrefslogtreecommitdiffstats
path: root/scripts/rpm2cpio.sh
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/rpm2cpio.sh')
-rwxr-xr-xscripts/rpm2cpio.sh53
1 files changed, 53 insertions, 0 deletions
diff --git a/scripts/rpm2cpio.sh b/scripts/rpm2cpio.sh
new file mode 100755
index 0000000000..426fd77bb7
--- /dev/null
+++ b/scripts/rpm2cpio.sh
@@ -0,0 +1,53 @@
1#!/bin/sh
2
3# This comes from the RPM5 5.4.0 distribution.
4
5pkg=$1
6if [ "$pkg" = "" -o ! -e "$pkg" ]; then
7 echo "no package supplied" 1>&2
8 exit 1
9fi
10
11leadsize=96
12o=`expr $leadsize + 8`
13set `od -j $o -N 8 -t u1 $pkg`
14il=`expr 256 \* \( 256 \* \( 256 \* $2 + $3 \) + $4 \) + $5`
15dl=`expr 256 \* \( 256 \* \( 256 \* $6 + $7 \) + $8 \) + $9`
16# echo "sig il: $il dl: $dl"
17
18sigsize=`expr 8 + 16 \* $il + $dl`
19o=`expr $o + $sigsize + \( 8 - \( $sigsize \% 8 \) \) \% 8 + 8`
20set `od -j $o -N 8 -t u1 $pkg`
21il=`expr 256 \* \( 256 \* \( 256 \* $2 + $3 \) + $4 \) + $5`
22dl=`expr 256 \* \( 256 \* \( 256 \* $6 + $7 \) + $8 \) + $9`
23# echo "hdr il: $il dl: $dl"
24
25hdrsize=`expr 8 + 16 \* $il + $dl`
26o=`expr $o + $hdrsize`
27EXTRACTOR="dd if=$pkg ibs=$o skip=1"
28
29COMPRESSION=`($EXTRACTOR |file -) 2>/dev/null`
30if echo $COMPRESSION |grep -q gzip; then
31 DECOMPRESSOR=gunzip
32elif echo $COMPRESSION |grep -q bzip2; then
33 DECOMPRESSOR=bunzip2
34elif echo $COMPRESSION |grep -q xz; then
35 DECOMPRESSOR=unxz
36elif echo $COMPRESSION |grep -q cpio; then
37 DECOMPRESSOR=cat
38else
39 # Most versions of file don't support LZMA, therefore we assume
40 # anything not detected is LZMA
41 DECOMPRESSOR=`which unlzma 2>/dev/null`
42 case "$DECOMPRESSOR" in
43 /* ) ;;
44 * ) DECOMPRESSOR=`which lzmash 2>/dev/null`
45 case "$DECOMPRESSOR" in
46 /* ) DECOMPRESSOR="lzmash -d -c" ;;
47 * ) DECOMPRESSOR=cat ;;
48 esac
49 ;;
50 esac
51fi
52
53$EXTRACTOR 2>/dev/null | $DECOMPRESSOR