From 7b09b69c4af90136ef300d49db67100099402d13 Mon Sep 17 00:00:00 2001 From: Tilman Sauerbeck Date: Sun, 19 Mar 2006 16:35:20 +0000 Subject: [PATCH] rpm2targz, less: moved rpm2targz from core to opt --- rpm2targz/.footprint | 6 ++++ rpm2targz/.md5sum | 2 ++ rpm2targz/Pkgfile | 14 +++++++++ rpm2targz/README | 6 ++++ rpm2targz/rpm2targz | 66 +++++++++++++++++++++++++++++++++++++++++++ rpm2targz/rpmoffset.c | 24 ++++++++++++++++ 6 files changed, 118 insertions(+) create mode 100644 rpm2targz/.footprint create mode 100644 rpm2targz/.md5sum create mode 100644 rpm2targz/Pkgfile create mode 100644 rpm2targz/README create mode 100755 rpm2targz/rpm2targz create mode 100644 rpm2targz/rpmoffset.c diff --git a/rpm2targz/.footprint b/rpm2targz/.footprint new file mode 100644 index 000000000..645e7b10a --- /dev/null +++ b/rpm2targz/.footprint @@ -0,0 +1,6 @@ +drwxr-xr-x root/root usr/ +drwxr-xr-x root/root usr/bin/ +-rwxr-xr-x root/root usr/bin/rpm2targz +drwxr-xr-x root/root usr/lib/ +drwxr-xr-x root/root usr/lib/rpm2targz/ +-rwxr-xr-x root/root usr/lib/rpm2targz/rpmoffset diff --git a/rpm2targz/.md5sum b/rpm2targz/.md5sum new file mode 100644 index 000000000..3b656c07c --- /dev/null +++ b/rpm2targz/.md5sum @@ -0,0 +1,2 @@ +8341044e13ddead93295d57f5853ab00 rpm2targz +4501e004279155038f16000c7b45acb4 rpmoffset.c diff --git a/rpm2targz/Pkgfile b/rpm2targz/Pkgfile new file mode 100644 index 000000000..ffbbfa608 --- /dev/null +++ b/rpm2targz/Pkgfile @@ -0,0 +1,14 @@ +# Description: A tool to convert RPM files to TAR.GZ files +# URL: http://www.crux.nu +# Maintainer: Per Lidén + +name=rpm2targz +version=1.0.4 +release=1 +source=(rpm2targz rpmoffset.c) + +build() { + gcc $CFLAGS rpmoffset.c -o rpmoffset + install -D -m 0755 rpm2targz $PKG/usr/bin/rpm2targz + install -D -m 0755 rpmoffset $PKG/usr/lib/rpm2targz/rpmoffset +} diff --git a/rpm2targz/README b/rpm2targz/README new file mode 100644 index 000000000..8380b22a9 --- /dev/null +++ b/rpm2targz/README @@ -0,0 +1,6 @@ +POST-INSTALL + + To enable less(1) to view RPM files, add the following line to + the case statement in /usr/lib/less/filter: + + *.rpm) dd ibs=`/usr/lib/rpm2targz/rpmoffset < "$1"` skip=1 if="$1" | gzip -dc | cpio -tv ;; diff --git a/rpm2targz/rpm2targz b/rpm2targz/rpm2targz new file mode 100755 index 000000000..eee5c2b3f --- /dev/null +++ b/rpm2targz/rpm2targz @@ -0,0 +1,66 @@ +#!/bin/sh +# +# Modified by Per Liden , 2000, 2004. +# Han Boetes , 2004. +# +# Copyright 1997, 1998 Patrick Volkerding, Moorhead, 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. +# + +if [ "$#" = "0" ]; then + echo "usage: ${0##*/} ..." + exit 1 +fi + +# If $TMPDIR is not set, then use $TMP. +# If $TMP is not set either, then mktemp(1) will use /tmp. +${TMPDIR:=$TMP} + +for file_rpm in $*; do + if [ ! -f $file_rpm ]; then + echo "$file_rpm: file not found" + continue + fi + + dir_tar_gz=`mktemp -d` || exit 1 + file_cpio=`mktemp` || exit 1 + file_cpio_z=`mktemp` || exit 1 + file_tar_gz=${file_rpm%.rpm}.tar.gz + + echo "$file_rpm => $file_tar_gz" + + dd ibs=`/usr/lib/rpm2targz/rpmoffset < $file_rpm` skip=1 if=$file_rpm of=$file_cpio_z 2> /dev/null + + if file $file_cpio_z | grep "bzip2 compressed data"; then + bzip2 -dc < $file_cpio_z > $file_cpio + else + gzip -dc < $file_cpio_z > $file_cpio + fi + + ( cd $dir_tar_gz + cpio --quiet -i -m -d < $file_cpio + find . -type d -perm 700 -exec chmod 755 {} \; + tar cf - . + ) | gzip > $file_tar_gz + + rm -rf $file_cpio $file_cpio_z $dir_tar_gz +done + +# End of file. diff --git a/rpm2targz/rpmoffset.c b/rpm2targz/rpmoffset.c new file mode 100644 index 000000000..a0d220023 --- /dev/null +++ b/rpm2targz/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 + +/* 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 +const char magic[][3]={"\x1F\x8B\x08"/*gzip*/,"BZh"/*bzip2*/}; + +main() +{ + char *buff = malloc(RPMBUFSIZ),*eb,*p; + for (p = buff, eb = buff + read(0,buff,RPMBUFSIZ); p < eb; p++) + if ((*p == magic[0][0] && p[1] == magic[0][1] && p[2] == magic[0][2]) || + (*p == magic[1][0] && p[1] == magic[1][1] && p[2] == magic[1][2])) + printf("%d\n",p - buff), + exit(0); + exit(1); +}