aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorphceac <phceac@yahoo.com>2008-05-31 16:31:03 -0400
committerMike Frysinger <vapier@gentoo.org>2008-05-31 17:07:32 -0400
commit5258cd939bd6c3e26ca295f700aee477a75288e7 (patch)
tree3e8b17307cac1acaa83e7b1d3d96dfa99507ea5b
parentadd files to help with dist (diff)
downloadrpm2targz-5258cd939bd6c3e26ca295f700aee477a75288e7.tar.gz
rpm2targz-5258cd939bd6c3e26ca295f700aee477a75288e7.tar.bz2
rpm2targz-5258cd939bd6c3e26ca295f700aee477a75288e7.zip
add support for rpms with bzip2 compression
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
-rwxr-xr-xrpm2targz32
-rw-r--r--rpmoffset.c11
2 files changed, 39 insertions, 4 deletions
diff --git a/rpm2targz b/rpm2targz
index 0ab74e4..1f47014 100755
--- a/rpm2targz
+++ b/rpm2targz
@@ -21,6 +21,8 @@
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
+# debug switch to allow to bypass use of rpm2cpio provided by the rpm package
+USERPM2CPIO=true
if [ "$TMPDIR" = "" ]; then
TMPDIR=/tmp
fi
@@ -46,7 +48,7 @@ if [ "$1" = "" ]; then
fi
for i in $* ; do
if [ ! "$1" = "$*" ]; then
- echo -n "Processing file: $i"
+ echo "Processing file: $i"
fi
rm -rf $TMPDIR/rpm2targz$COOKIE # clear the way, just in case of mischief
mkdir $TMPDIR/rpm2targz$COOKIE
@@ -68,7 +70,7 @@ for i in $* ; do
fi
ofn=$TMPDIR/rpm2targz$COOKIE/`basename $i .rpm`.cpio
- if which rpm2cpio 1> /dev/null 2> /dev/null ; then
+ if $USERPM2CPIO && which rpm2cpio 1> /dev/null 2> /dev/null ; then
rpm2cpio $i > $ofn 2> /dev/null
if [ ! $? = 0 ]; then
echo "... rpm2cpio failed. (maybe $i is not an RPM?)"
@@ -76,7 +78,31 @@ for i in $* ; do
continue
fi
else # less reliable than rpm2cpio...
- dd ibs=`rpmoffset < $i` skip=1 if=$i 2> /dev/null | gzip -dc > $ofn
+ # get offset of start of payload
+ PAYLOADOFFSET=`rpmoffset < $i`
+ #identify compression
+ PAYLOADHEAD=`dd ibs=${PAYLOADOFFSET} skip=1 if=$i 2> /dev/null | dd bs=10 count=1 2> /dev/null`
+ if echo ${PAYLOADHEAD} | grep -e $'^\037\213' > /dev/null ; then
+ echo "found gzip magic bytes"
+ decomp="gzip"
+ elif echo ${PAYLOADHEAD} | grep -e "^BZh" > /dev/null ; then
+ echo "found bzip magic bytes"
+ decomp="bzip2"
+ else
+ echo " $i - no magic compression identifier found - skipping file"
+ ( cd $TMPDIR ; rm -rf rpm2targz$COOKIE )
+ continue
+ fi
+ echo -n " trying to decompress with ${decomp}..."
+ dd ibs=`rpmoffset < $i` skip=1 if=$i 2> /dev/null | ${decomp} -dc > $ofn 2> /dev/null
+ if [ $? = 0 ]; then
+ echo " OK"
+ else
+ echo " FAILED"
+ echo " $i failed to decompress - skipping file"
+ ( cd $TMPDIR ; rm -rf rpm2targz$COOKIE )
+ continue
+ fi
fi
DEST=$TMPDIR/rpm2targz$COOKIE
if [ "$isSource" = "1" ]; then
diff --git a/rpmoffset.c b/rpmoffset.c
index ac5984c..524e310 100644
--- a/rpmoffset.c
+++ b/rpmoffset.c
@@ -16,8 +16,17 @@ main()
{
char *buff = malloc(RPMBUFSIZ),*eb,*p;
for (p = buff, eb = buff + read(0,buff,RPMBUFSIZ); p < eb; p++)
+ {
if (*p == '\037' && p[1] == '\213' && p[2] == '\010')
- printf("%d\n",p - buff),
+ {
+ printf("%d\n",p - buff);
exit(0);
+ }
+ else if (*p == 'B' && p[1] == 'Z' && p[2] == 'h')
+ {
+ printf("%d\n",p - buff);
+ exit(0);
+ }
+ }
exit(1);
}