contrib/rpm2targz-han/rpm2targz

85 lines
2.4 KiB
Bash

#!/bin/sh
#
# Modified by Han Boetes <han@mijncomputer.nl>, February 2005.
# Modified by Per Liden <per@fukt.bth.se>, November 2000.
#
# 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.
#
name=${0##*/}
if [ $# -eq 0 ]; then
echo "usage: $name <file.rpm> [file2.rpm]..."
exit 1
fi
TMP=${TMP:=/tmp}
returncode=0
# Create a temporary directory
if ! TMP_DIR=$(mktemp -d -p $TMP/); then
exit 1
fi
for i in $*; do
rm -rf $TMP_DIR/*
if [ ! -r "$i" ]; then
echo "$name: Error: file \"$i\" doesn't exist" >&2
returncode=1
continue
fi
set -- $(file $i)
if [ "$2" != RPM ]; then
echo "$name: Error: file \"$i\" is not an RPM" >&2
returncode=1
continue
fi
base_name=${i%.rpm}
ofn=$base_name.cpio
raw=$ofn.raw
echo "Converting: $i to $base_name.tar.gz"
dd ibs=$(/usr/lib/rpm2targz/rpmoffset < $i) skip=1 if=$i of=$TMP_DIR/$raw 2> /dev/null
if file $TMP_DIR/$raw| grep bzip2\ compressed\ data; then
bzip2 -dc < $TMP_DIR/$raw > $TMP_DIR/$ofn
else
gzip -dc < $TMP_DIR/$raw > $TMP_DIR/$ofn
fi
(
cd $TMP_DIR
rm -f $raw
cpio \
--quiet \
--extract \
--preserve-modification-time \
--make-directories < $ofn
rm -f $ofn
find . -type d -perm 700 -exec chmod 755 {} \;
tar cf - .
) | gzip > $base_name.tar.gz
done
rm -rf $TMP_DIR
if [ $returncode = 1 ]; then
exit 1
fi