|
|
# Copyright 1997, 1998 Patrick Volkerding, Moorhead, MN USA | # Copyright 1997, 1998 Patrick Volkerding, Moorhead, MN USA |
# Copyright 2002 Slackware Linux, Inc., Concord, CA USA | # Copyright 2002 Slackware Linux, Inc., Concord, CA USA |
# All rights reserved. | # All rights reserved. |
|
# $Header: $ |
# | # |
# Redistribution and use of this script, with or without modification, is | # Redistribution and use of this script, with or without modification, is |
# permitted provided that the following conditions are met: | # permitted provided that the following conditions are met: |
|
|
| |
# debug switch to allow to bypass use of rpm2cpio provided by the rpm package | # debug switch to allow to bypass use of rpm2cpio provided by the rpm package |
USERPM2CPIO=true | USERPM2CPIO=true |
if [ "$TMPDIR" = "" ]; then |
[ "$TMPDIR" == "" ] && TMPDIR=/tmp |
TMPDIR=/tmp |
if [ ! -d "$TMPDIR" ]; then |
|
echo "TMPDIR=$TMPDIR is not a dir" > /dev/stderr |
|
exit 1 |
fi | fi |
# If mcookie is available, use it for better /tmp security. |
WORKDIR=`mktemp -d $TMPDIR/$$XXXXXX` |
if [ -x `which mcookie` ]; then |
if [ $? != 0 ]; then |
COOKIE=`mcookie` |
echo "Failed to make tmp workdir for file i/o conversion" > /dev/stderr |
else |
exit 1 |
COOKIE=$$ |
|
fi | fi |
|
|
if [ "$1" = "" ]; then | if [ "$1" = "" ]; then |
echo "$0: Converts RPM format to standard GNU tar + GNU zip format." | echo "$0: Converts RPM format to standard GNU tar + GNU zip format." |
echo " (view converted packages with \"less\", install and remove" |
if [ -e /etc/slackware-version ]; then |
echo " with \"installpkg\", \"removepkg\", \"pkgtool\", or manually" |
echo " (view converted packages with \"less\", install and remove" |
echo " with \"tar\")" |
echo " with \"installpkg\", \"removepkg\", \"pkgtool\", or manually" |
|
echo " with \"tar\")" |
|
fi |
echo | echo |
echo "Usage: $0 <file.rpm>" | echo "Usage: $0 <file.rpm>" |
if [ "`basename $0`" = "rpm2tgz" ]; then | if [ "`basename $0`" = "rpm2tgz" ]; then |
|
|
if [ ! "$1" = "$*" ]; then | if [ ! "$1" = "$*" ]; then |
echo "Processing file: $i" | echo "Processing file: $i" |
fi | fi |
rm -rf $TMPDIR/rpm2targz$COOKIE # clear the way, just in case of mischief |
rm -rf ${WORKDIR}/* || exit 1 ; # clear the way, just in case of mischief |
mkdir $TMPDIR/rpm2targz$COOKIE |
|
| |
# Determine if this is a source or binary RPM. | # Determine if this is a source or binary RPM. |
# If we have getrpmtype, use that. Otherwise, try "file". | # If we have getrpmtype, use that. Otherwise, try "file". |
if which getrpmtype 1> /dev/null 2> /dev/null; then |
if type -p getrpmtype 1> /dev/null 2> /dev/null; then |
if getrpmtype -n $i | grep source 1> /dev/null 2> /dev/null ; then | if getrpmtype -n $i | grep source 1> /dev/null 2> /dev/null ; then |
isSource=1 | isSource=1 |
else | else |
|
|
fi | fi |
fi | fi |
| |
ofn=$TMPDIR/rpm2targz$COOKIE/`basename $i .rpm`.cpio |
ofn=${WORKDIR}/`basename $i .rpm`.cpio |
if $USERPM2CPIO && 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 | rpm2cpio $i > $ofn 2> /dev/null |
if [ ! $? = 0 ]; then | if [ ! $? = 0 ]; then |
echo "... rpm2cpio failed. (maybe $i is not an RPM?)" | echo "... rpm2cpio failed. (maybe $i is not an RPM?)" |
( cd $TMPDIR ; rm -rf rpm2targz$COOKIE ) |
( rm -rf "${WORKDIR}/*" ) |
continue | continue |
fi | fi |
else # less reliable than rpm2cpio... | else # less reliable than rpm2cpio... |
|
|
decomp="bzip2" | decomp="bzip2" |
else | else |
echo " $i - no magic compression identifier found - skipping file" | echo " $i - no magic compression identifier found - skipping file" |
( cd $TMPDIR ; rm -rf rpm2targz$COOKIE ) |
( rm -rf "${WORKDIR}/*" ) |
continue | continue |
fi | fi |
echo -n " trying to decompress with ${decomp}..." | echo -n " trying to decompress with ${decomp}..." |
|
|
else | else |
echo " FAILED" | echo " FAILED" |
echo " $i failed to decompress - skipping file" | echo " $i failed to decompress - skipping file" |
( cd $TMPDIR ; rm -rf rpm2targz$COOKIE ) |
( rm -rf "${WORKDIR}/*" ) |
continue | continue |
fi | fi |
fi | fi |
DEST=$TMPDIR/rpm2targz$COOKIE |
DEST=${WORKDIR} |
#if [ "$isSource" = "1" ]; then | #if [ "$isSource" = "1" ]; then |
# DEST=$DEST/$(basename $(basename $i .rpm) .src) | # DEST=$DEST/$(basename $(basename $i .rpm) .src) |
#fi | #fi |
|
|
cpio --extract --preserve-modification-time --make-directories < $ofn 1> /dev/null 2> /dev/null | cpio --extract --preserve-modification-time --make-directories < $ofn 1> /dev/null 2> /dev/null |
rm -f $ofn | rm -f $ofn |
find . -type d -perm 700 -exec chmod 755 {} \; ) | find . -type d -perm 700 -exec chmod 755 {} \; ) |
( cd $TMPDIR/rpm2targz$COOKIE ; tar cf - . ) > `basename $i .rpm`.tar |
( cd ${WORKDIR} ; tar cf - . ) > `basename $i .rpm`.tar |
gzip -9 `basename $i .rpm`.tar | gzip -9 `basename $i .rpm`.tar |
if [ "`basename $0`" = "rpm2tgz" ]; then | if [ "`basename $0`" = "rpm2tgz" ]; then |
mv `basename $i .rpm`.tar.gz `basename $i .rpm`.tgz | mv `basename $i .rpm`.tar.gz `basename $i .rpm`.tgz |
fi | fi |
( cd $TMPDIR ; rm -rf rpm2targz$COOKIE ) |
( rm -rf "${WORKDIR}/*" ) |
echo | echo |
done | done |
|
rm -rf ${WORKDIR} |