#!/bin/sh # # file: rpm2tar (after rpm2tgz) # machine: wincrap # modified: pasha may 20 2006 # modification: replaced functions library # # 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. # function do_with_echo () { echo "$ME: doing $1" $1 if [ $? != 0 ]; then echo $ME: $1 returned error\; aborting exit 1 fi } ME=`basename $0` if [ "$1" = "" ]; then echo "$ME: converts RPM format to tar." echo "Usage: $ME " echo " (Outputs \"file.tar\")" exit 1; fi BASE=`basename $1 .rpm` BASE_TAR=$BASE.tar BASE_CPIO=$BASE.cpio if [ -f $BASE_TAR ]; then echo "$ME: $BASE_TAR exists" exit 1 fi TMPDIR=/tmp/$ME$$ rm -rf $TMPDIR # clear the way, just in case of mischief do_with_echo "mkdir $TMPDIR" echo "$ME: doing dd and producing .cpio" dd ibs=`rpmoffset < $1` skip=1 if=$1 | gzip -dc > $TMPDIR/$BASE_CPIO ( cd $TMPDIR 1>&2 echo "$ME: doing cpio" 1>&2 cpio --extract --preserve-modification-time --make-directories < $BASE_CPIO 1>&2 rm -f $BASE_CPIO 1>&2 echo "$ME: doing find and chmoding everything" 1>&2 find . -type d -perm 700 -exec chmod 755 {} \; 1>&2 echo "$ME: doing tar" 1>&2 tar cf - . ) > $BASE_TAR echo "$ME: removing .rpm" if [ "$?" == "0" ]; then rm $1 || echo "$ME: unable remove $1" fi rm -rf $TMPDIR || echo "$ME: unable remove $TMPDIR, leaving garbage" # end of rpm2tar