diff options
Diffstat (limited to 'source/a/rpm2tgz')
-rw-r--r-- | source/a/rpm2tgz/rpm2targz | 129 | ||||
-rw-r--r-- | source/a/rpm2tgz/rpm2targz.README | 18 | ||||
-rwxr-xr-x | source/a/rpm2tgz/rpm2tgz.SlackBuild | 58 | ||||
-rw-r--r-- | source/a/rpm2tgz/rpmoffset.c | 24 | ||||
-rw-r--r-- | source/a/rpm2tgz/slack-desc | 19 |
5 files changed, 248 insertions, 0 deletions
diff --git a/source/a/rpm2tgz/rpm2targz b/source/a/rpm2tgz/rpm2targz new file mode 100644 index 00000000..484e5ad0 --- /dev/null +++ b/source/a/rpm2tgz/rpm2targz @@ -0,0 +1,129 @@ +#!/bin/sh +# Copyright 1997, 1998 Patrick Volkerding, Moorhead, MN USA +# Copyright 2002, 2004 Slackware Linux, Inc., Concord, CA USA +# Copyright 2006, 2009 Patrick Volkerding, Sebeka, MN USA +# All rights reserved. +# +# Redistribution and use of this script, with or without modification, is +# permitted provided that the following conditions are met: +# +# 1. Redistributions of this script must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED +# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# + +if [ "$1" = "" ]; then + echo "$0: Converts RPM format to standard GNU tar + GNU zip format." + echo " (view converted packages with \"less\", install and remove" + echo " with \"installpkg\", \"removepkg\", \"pkgtool\", or manually" + echo " with \"tar\")" + echo + echo "Usage: $0 <file.rpm>" + if [ "$(basename $0)" = "rpm2tgz" ]; then + echo " (Outputs \"file.tgz\")" + else + echo " (Outputs \"file.tar.gz\")" + fi + exit 1; +fi + +CWD=$(pwd) + +# Create a new temporary directory with a secure filename: +make_temp_dir() { + if [ -x "$(which mcookie)" ]; then + tempd=/tmp/tmp.$(mcookie) + mkdir -p -m 0755 $tempd + elif [ -x "$(which openssl)" ]; then + tempd=/tmp/tmp.$(dd if=/dev/urandom bs=1k count=1 2> /dev/null | openssl dgst -md5) + mkdir -p -m 0755 $tempd + elif [ -x "$(which md5)" ]; then + tempd=/tmp/tmp.$(dd if=/dev/urandom bs=1k count=1 2> /dev/null | md5) + mkdir -p -m 0755 $tempd + elif [ -x "$(which mktemp)" ]; then + tempd=$(mktemp -d) + chmod 755 $tempd + ## Uncomment for insecure use, but don't blame me: + #else + # tempd=/tmp/tmp.$$ + # mkdir -p -m 0755 $tempd + fi + if [ -d $tempd ]; then # success, return the name of the directory: + echo $tempd + else + echo "ERROR: Could not find mcookie, openssl, or md5." + echo " Exiting since a secure temporary directory could not be made." + exit 1 + fi +} + +for i in $* ; do + + # Determine if this is a source or binary RPM. + # If we have getrpmtype, use that. Otherwise, try "file". + if which getrpmtype 1> /dev/null 2> /dev/null; then + if getrpmtype -n $i | grep source 1> /dev/null 2> /dev/null ; then + isSource=1 + else + isSource=0 + fi + else # use file. This works fine on Slackware, and is the default. + if file $i | grep RPM | grep " src " 1> /dev/null 2> /dev/null ; then + isSource=1 + else + isSource=0 + fi + fi + + # Create a temporary directory: + TMPDIR=$(make_temp_dir) + + # Extract the RPM: + ofn=$TMPDIR/$(basename $i .rpm).cpio + if which rpm2cpio 1> /dev/null 2> /dev/null ; then + rpm2cpio $i > $ofn 2> /dev/null + if [ ! $? = 0 ]; then + echo "ERROR: rpm2cpio failed. (maybe $i is not an RPM?)" + rm -rf $TMPDIR + continue + fi + else # less reliable than rpm2cpio... + ( dd ibs=$(rpmoffset < $i) skip=1 if=$i 2> /dev/null | gzip -dc > $ofn 2>/dev/null ) || \ + ( dd ibs=$(rpmoffset < $i) skip=1 if=$i 2> /dev/null | bzip2 -dc > $ofn 2>/dev/null ) + fi + DEST=$TMPDIR + if [ "$isSource" = "1" ]; then + DEST=$DEST/$(basename $(basename $i .rpm) .src) + fi + mkdir -p $DEST + ( cd $DEST + cpio -i -m -d < $ofn 1> /dev/null 2> /dev/null + rm -f $ofn + find . -type d -perm 700 -exec chmod 755 {} \; + ) + + # If this program was called as "rpm2targz", then repack as a plain + # tar+gz archive. If it was called as "rpm2tgz", use Slackware's + # makepkg to produce the .tgz: + if [ "$(basename $0)" = "rpm2tgz" ]; then + ( cd $TMPDIR ; makepkg -l y -c n $CWD/$(basename $i .rpm).tgz ) + else + ( cd $TMPDIR ; tar cf - . ) > $(basename $i .rpm).tar + gzip -9 $(basename $i .rpm).tar + fi + + # Remove temporary directory: + rm -rf $TMPDIR + +done + diff --git a/source/a/rpm2tgz/rpm2targz.README b/source/a/rpm2tgz/rpm2targz.README new file mode 100644 index 00000000..2ce141c0 --- /dev/null +++ b/source/a/rpm2tgz/rpm2targz.README @@ -0,0 +1,18 @@ + +This package contains 'rpm2targz', a simple utility to convert Red Hat-style +RPM packages into standard tar.gz archives. Converted binary packages can then +be installed/removed using the 'installpkg/removepkg' commands, or 'pkgtool'. + +It's advisable to at least examine the converted package with 'less' to make +sure it won't do anything too crazy to your system. If it does, Patrick +Volkerding and David Cantrell are not responsible, so use this at your own +risk. :-) + +By default, rpm2targz will attempt to use "file" to detect source RPMS, and will +put the contents into a subdirectory in the resulting package. This may not be +portable to other operating systems -- if you're trying to run rpm2targz on an +OS that doesn't have a file that knows RPM types, and you care about this source +RPM feature, you can compile and install David Cantrell's standalone getrpmtype +utility. The getrpmtype.tar.gz source archive can be found in Slackware's +source tree in source/a/rpm2tgz/. + diff --git a/source/a/rpm2tgz/rpm2tgz.SlackBuild b/source/a/rpm2tgz/rpm2tgz.SlackBuild new file mode 100755 index 00000000..abfe3298 --- /dev/null +++ b/source/a/rpm2tgz/rpm2tgz.SlackBuild @@ -0,0 +1,58 @@ +#!/bin/sh + +# Copyright 2008, 2009 Patrick J. Volkerding, Sebeka, Minnesota, USA +# All rights reserved. +# +# Redistribution and use of this script, with or without modification, is +# permitted provided that the following conditions are met: +# +# 1. Redistributions of this script must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED +# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +VERSION=1.1 +ARCH=${ARCH:-x86_64} +BUILD=${BUILD:-1} + +CWD=$(pwd) +TMP=${TMP:-/tmp} +PKG=$TMP/package-bin + +rm -rf $PKG +mkdir -p $TMP $PKG + +echo "+===========+" +echo "| rpm2targz |" +echo "+===========+" +cd $TMP +mkdir -p $PKG/usr/bin +cc -o $PKG/usr/bin/rpmoffset $CWD/rpmoffset.c +cat $CWD/rpm2targz > $PKG/usr/bin/rpm2targz +chmod 755 $PKG/usr/bin/{rpmoffset,rpm2targz} +( cd $PKG/usr/bin ; ln -sf rpm2targz rpm2tgz ) +mkdir -p $PKG/usr/doc/rpm2targz +cp -a $CWD/rpm2targz.README $PKG/usr/doc/rpm2targz/rpm2targz.README +chown root:root $PKG/usr/doc/rpm2targz/rpm2targz.README +chmod 644 $PKG/usr/doc/rpm2targz/rpm2targz.README +( cd $PKG + find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null + find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null +) + +mkdir -p $PKG/install +cat $CWD/slack-desc > $PKG/install/slack-desc + +# Build the package: +cd $PKG +makepkg -l y -c n $TMP/rpm2tgz-$VERSION-$ARCH-$BUILD.txz + diff --git a/source/a/rpm2tgz/rpmoffset.c b/source/a/rpm2tgz/rpmoffset.c new file mode 100644 index 00000000..57af397c --- /dev/null +++ b/source/a/rpm2tgz/rpmoffset.c @@ -0,0 +1,24 @@ + +/* Find how deeply inside an .RPM the real data is */ +/* kept, and report the offset in bytes */ + +/* Wouldn't it be a lot more sane if we could just untar these things? */ + +#include <stdlib.h> + +/* These offsets keep getting bigger, so we're going to just bite a 2MB */ +/* chunk of RAM right away so that we have enough. Yeah, horrible */ +/* quick and dirty implementation, but hey -- it gets the job done. */ + +#define RPMBUFSIZ 2097152 + +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') || + (*p == 'B' && p[1] == 'Z' && p[2] == 'h' && '1' <= p[3] && p[3] <= '9' )) + printf("%d\n",p - buff), + exit(0); + exit(1); +} diff --git a/source/a/rpm2tgz/slack-desc b/source/a/rpm2tgz/slack-desc new file mode 100644 index 00000000..8f8861b5 --- /dev/null +++ b/source/a/rpm2tgz/slack-desc @@ -0,0 +1,19 @@ +# HOW TO EDIT THIS FILE: +# The "handy ruler" below makes it easier to edit a package description. Line +# up the first '|' above the ':' following the base package name, and the '|' +# on the right side marks the last column you can put a character in. You must +# make exactly 11 lines for the formatting to be correct. It's also +# customary to leave one space after the ':'. + + |-----handy-ruler------------------------------------------------------| +rpm2tgz: rpm2tgz (a tool for converting an RPM archive into a tar+gz one) +rpm2tgz: +rpm2tgz: Converts RPM format to Slackware's GNU tar + GNU zip format. (view +rpm2tgz: converted packages with "less", install and remove with "installpkg", +rpm2tgz: "removepkg", "pkgtool", or manually with "tar"). +rpm2tgz: +rpm2tgz: Converted packages come with no warranty. ;-) +rpm2tgz: +rpm2tgz: +rpm2tgz: +rpm2tgz: |