diff options
| -rwxr-xr-x | scripts/rpm2cpio.sh | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/scripts/rpm2cpio.sh b/scripts/rpm2cpio.sh index 2034373fe4..8199b43784 100755 --- a/scripts/rpm2cpio.sh +++ b/scripts/rpm2cpio.sh | |||
| @@ -7,7 +7,7 @@ fatal() { | |||
| 7 | } | 7 | } |
| 8 | 8 | ||
| 9 | pkg="$1" | 9 | pkg="$1" |
| 10 | [ -n "$pkg" -a -e "$pkg" ] || | 10 | [ -n "$pkg" ] && [ -e "$pkg" ] || |
| 11 | fatal "No package supplied" | 11 | fatal "No package supplied" |
| 12 | 12 | ||
| 13 | _dd() { | 13 | _dd() { |
| @@ -16,14 +16,23 @@ _dd() { | |||
| 16 | } | 16 | } |
| 17 | 17 | ||
| 18 | calcsize() { | 18 | calcsize() { |
| 19 | |||
| 20 | case "$(_dd $1 bs=4 count=1 | tr -d '\0')" in | ||
| 21 | "$(printf '\216\255\350')"*) ;; # '\x8e\xad\xe8' | ||
| 22 | *) fatal "File doesn't look like rpm: $pkg" ;; | ||
| 23 | esac | ||
| 24 | |||
| 19 | offset=$(($1 + 8)) | 25 | offset=$(($1 + 8)) |
| 20 | 26 | ||
| 21 | local i b b0 b1 b2 b3 b4 b5 b6 b7 | 27 | local i b b0 b1 b2 b3 b4 b5 b6 b7 |
| 22 | 28 | ||
| 23 | i=0 | 29 | i=0 |
| 24 | while [ $i -lt 8 ]; do | 30 | while [ $i -lt 8 ]; do |
| 25 | b=$(_dd $(($offset + $i)) bs=1 count=1; echo X) | 31 | # add . to not loose \n |
| 26 | b=${b%X} | 32 | # strip \0 as it gets dropped with warning otherwise |
| 33 | b="$(_dd $(($offset + $i)) bs=1 count=1 | tr -d '\0' ; echo .)" | ||
| 34 | b=${b%.} # strip . again | ||
| 35 | |||
| 27 | [ -z "$b" ] && | 36 | [ -z "$b" ] && |
| 28 | b="0" || | 37 | b="0" || |
| 29 | b="$(exec printf '%u\n' "'$b")" | 38 | b="$(exec printf '%u\n' "'$b")" |
| @@ -35,7 +44,7 @@ calcsize() { | |||
| 35 | offset=$(($offset + $rsize)) | 44 | offset=$(($offset + $rsize)) |
| 36 | } | 45 | } |
| 37 | 46 | ||
| 38 | case "$(_dd 0 bs=8 count=1)" in | 47 | case "$(_dd 0 bs=4 count=1 | tr -d '\0')" in |
| 39 | "$(printf '\355\253\356\333')"*) ;; # '\xed\xab\xee\xdb' | 48 | "$(printf '\355\253\356\333')"*) ;; # '\xed\xab\xee\xdb' |
| 40 | *) fatal "File doesn't look like rpm: $pkg" ;; | 49 | *) fatal "File doesn't look like rpm: $pkg" ;; |
| 41 | esac | 50 | esac |
| @@ -46,10 +55,11 @@ sigsize=$rsize | |||
| 46 | calcsize $(($offset + (8 - ($sigsize % 8)) % 8)) | 55 | calcsize $(($offset + (8 - ($sigsize % 8)) % 8)) |
| 47 | hdrsize=$rsize | 56 | hdrsize=$rsize |
| 48 | 57 | ||
| 49 | case "$(_dd $offset bs=3 count=1)" in | 58 | case "$(_dd $offset bs=2 count=1 | tr -d '\0')" in |
| 50 | "$(printf '\102\132')"*) _dd $offset | bzip2 -d ;; # '\x42\x5a' | 59 | "$(printf '\102\132')") _dd $offset | bunzip2 ;; # '\x42\x5a' |
| 51 | "$(printf '\037\213')"*) _dd $offset | gunzip ;; # '\x1f\x8b' | 60 | "$(printf '\037\213')") _dd $offset | gunzip ;; # '\x1f\x8b' |
| 52 | "$(printf '\375\067')"*) _dd $offset | xzcat ;; # '\xfd\x37' | 61 | "$(printf '\375\067')") _dd $offset | xzcat ;; # '\xfd\x37' |
| 53 | "$(printf '\135\000')"*) _dd $offset | unlzma ;; # '\x5d\x00' | 62 | "$(printf '\135')") _dd $offset | unlzma ;; # '\x5d\x00' |
| 54 | *) fatal "Unrecognized rpm file: $pkg" ;; | 63 | "$(printf '\050\265')") _dd $offset | unzstd ;; # '\x28\xb5' |
| 64 | *) fatal "Unrecognized payload compression format in rpm file: $pkg" ;; | ||
| 55 | esac | 65 | esac |
