| 1 |
# Copyright 1999-2003 Gentoo Technologies, Inc.
|
| 2 |
# Distributed under the terms of the GNU General Public License v2
|
| 3 |
# $Header: /home/cvsroot/gentoo-x86/eclass/rpm.eclass,v 1.6 2003/06/22 16:31:23 liquidx Exp $
|
| 4 |
|
| 5 |
# Author : Alastair Tse <liquidx@gentoo.org> (21 Jun 2003)
|
| 6 |
#
|
| 7 |
# Convienence class for extracting RPMs
|
| 8 |
#
|
| 9 |
# Basically, rpm_src_unpack does:
|
| 10 |
#
|
| 11 |
# 1. uses rpm_unpack to unpack a rpm file using rpmoffset and cpio
|
| 12 |
# 2. if it is a source rpm, it finds all .tar .tar.gz, .tgz, .tbz2, .tar.bz2,
|
| 13 |
# .zip, .ZIP and unpacks them using unpack() (with a little hackery)
|
| 14 |
# 3. deletes all the unpacked tarballs and zip files from ${WORKDIR}
|
| 15 |
#
|
| 16 |
# This ebuild now re-defines a utility function called rpm_unpack which
|
| 17 |
# basically does what rpm2targz does, except faster. It does not gzip the
|
| 18 |
# output tar again but directly extracts to ${WORKDIR}
|
| 19 |
#
|
| 20 |
# It will autodetect for rpm2cpio (included in app-arch/rpm) and if it exists
|
| 21 |
# it will use that instead of the less reliable rpmoffset. This means if a
|
| 22 |
# particular rpm cannot be read using rpmoffset, you just need to put :
|
| 23 |
#
|
| 24 |
# DEPEND="app-arch/rpm"
|
| 25 |
#
|
| 26 |
# in your ebuild and it will install and use rpm2cpio instead. If you wish
|
| 27 |
# to force your ebuild to use rpmoffset in the presence of rpm2cpio, define:
|
| 28 |
#
|
| 29 |
# USE_RPMOFFSET_ONLY="1"
|
| 30 |
|
| 31 |
ECLASS="rpm"
|
| 32 |
INHERITED="$INHERITED $ECLASS"
|
| 33 |
|
| 34 |
USE_RPMOFFSET_ONLY=${USE_RPMOFFSET_ONLY-""}
|
| 35 |
|
| 36 |
newdepend "app-arch/rpm2targz"
|
| 37 |
|
| 38 |
# extracts the contents of the RPM in ${WORKDIR}
|
| 39 |
rpm_unpack() {
|
| 40 |
local rpmfile rpmoff decompcmd
|
| 41 |
rpmfile=$1
|
| 42 |
if [ -z "${rpmfile}" ]; then
|
| 43 |
return 1
|
| 44 |
fi
|
| 45 |
|
| 46 |
cd ${WORKDIR}
|
| 47 |
if [ -x /usr/bin/rpm2cpio -a -z "${USE_RPMOFFSET_ONLY}" ]; then
|
| 48 |
rpm2cpio ${rpmfile} | cpio -idmu --no-preserve-owner --quiet || return 1
|
| 49 |
else
|
| 50 |
rpmoff=`rpmoffset < ${rpmfile}`
|
| 51 |
[ -z "${rpmoff}" ] && return 1
|
| 52 |
|
| 53 |
decompcmd="gzip -dc"
|
| 54 |
if [ -n "`dd if=${rpmfile} skip=${rpmoff} bs=1 count=3 2>/dev/null | file - | grep bzip2`" ]; then
|
| 55 |
decompcmd="bzip2 -dc"
|
| 56 |
fi
|
| 57 |
dd ibs=${rpmoff} skip=1 if=${rpmfile} 2> /dev/null \
|
| 58 |
| ${decompcmd} \
|
| 59 |
| cpio -idmu --no-preserve-owner --quiet || return 1
|
| 60 |
fi
|
| 61 |
|
| 62 |
return 0
|
| 63 |
}
|
| 64 |
|
| 65 |
rpm_src_unpack() {
|
| 66 |
local x prefix ext myfail OLD_DISTDIR
|
| 67 |
|
| 68 |
for x in ${A}; do
|
| 69 |
myfail="failure unpacking ${x}"
|
| 70 |
ext=${x##*.}
|
| 71 |
case "$ext" in
|
| 72 |
rpm)
|
| 73 |
echo ">>> Unpacking ${x}"
|
| 74 |
prefix=${x%.rpm}
|
| 75 |
cd ${WORKDIR}
|
| 76 |
rpm_unpack ${DISTDIR}/${x} || die "${myfail}"
|
| 77 |
|
| 78 |
# find all tar.gz files and extract for srpms
|
| 79 |
if [ "${prefix##*.}" = "src" ]; then
|
| 80 |
OLD_DISTDIR=${DISTDIR}
|
| 81 |
DISTDIR=${WORKDIR}
|
| 82 |
findopts="* -maxdepth 0 -name *.tar"
|
| 83 |
for t in *.tar.gz *.tgz *.tbz2 *.tar.bz2 *.zip *.ZIP; do
|
| 84 |
findopts="${findopts} -o -name ${t}"
|
| 85 |
done
|
| 86 |
for t in $(find ${findopts} | xargs); do
|
| 87 |
unpack ${t}
|
| 88 |
rm -f ${t}
|
| 89 |
done
|
| 90 |
DISTDIR=${OLD_DISTDIR}
|
| 91 |
fi
|
| 92 |
;;
|
| 93 |
*)
|
| 94 |
unpack ${x}
|
| 95 |
;;
|
| 96 |
esac
|
| 97 |
done
|
| 98 |
|
| 99 |
}
|
| 100 |
|
| 101 |
EXPORT_FUNCTIONS src_unpack
|