Ticket #33444: rpm2cpio

File rpm2cpio, 1.4 KB (added by n3npq@…, 13 years ago)

rpm2cpio written in shell

Line 
1#!/bin/sh
2
3pkg=$1
4if [ "$pkg" = "" -o ! -e "$pkg" ]; then
5    echo "no package supplied" 1>&2
6   exit 1
7fi
8
9leadsize=96
10o=`expr $leadsize + 8`
11set `od -j $o -N 8 -t u1 $pkg`
12il=`expr 256 \* \( 256 \* \( 256 \* $2 + $3 \) + $4 \) + $5`
13dl=`expr 256 \* \( 256 \* \( 256 \* $6 + $7 \) + $8 \) + $9`
14# echo "sig il: $il dl: $dl"
15
16sigsize=`expr 8 + 16 \* $il + $dl`
17o=`expr $o + $sigsize + \( 8 - \( $sigsize \% 8 \) \) \% 8 + 8`
18set `od -j $o -N 8 -t u1 $pkg`
19il=`expr 256 \* \( 256 \* \( 256 \* $2 + $3 \) + $4 \) + $5`
20dl=`expr 256 \* \( 256 \* \( 256 \* $6 + $7 \) + $8 \) + $9`
21# echo "hdr il: $il dl: $dl"
22
23hdrsize=`expr 8 + 16 \* $il + $dl`
24o=`expr $o + $hdrsize`
25EXTRACTOR="dd if=$pkg ibs=$o skip=1"
26
27COMPRESSION=`($EXTRACTOR |file -) 2>/dev/null`
28if echo $COMPRESSION |grep -q gzip; then
29        DECOMPRESSOR=gunzip
30elif echo $COMPRESSION |grep -q bzip2; then
31        DECOMPRESSOR=bunzip2
32elif echo $COMPRESSION |grep -q xz; then
33        DECOMPRESSOR=unxz
34elif echo $COMPRESSION |grep -q cpio; then
35        DECOMPRESSOR=cat
36else
37        # Most versions of file don't support LZMA, therefore we assume
38        # anything not detected is LZMA
39        DECOMPRESSOR=`which unlzma 2>/dev/null`
40        case "$DECOMPRESSOR" in
41            /* ) ;;
42            *  ) DECOMPRESSOR=`which lzmash 2>/dev/null`
43                 case "$DECOMPRESSOR" in
44                     /* ) DECOMPRESSOR="lzmash -d -c" ;;
45                     *  ) DECOMPRESSOR=cat ;;
46                 esac
47                 ;;
48        esac
49fi
50
51$EXTRACTOR 2>/dev/null | $DECOMPRESSOR