diff options
author | Mike Frysinger <vapier@gentoo.org> | 2009-10-03 08:56:17 +0000 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2009-10-03 08:56:17 +0000 |
commit | 7197a0fbe0613e2b27647ba76c39a1101d4e1a37 (patch) | |
tree | f7c2eaa028f62c0619270f2e544cca36b7625c97 /eclass/rpm.eclass | |
parent | Stable for ppc. (diff) | |
download | gentoo-2-7197a0fbe0613e2b27647ba76c39a1101d4e1a37.tar.gz gentoo-2-7197a0fbe0613e2b27647ba76c39a1101d4e1a37.tar.bz2 gentoo-2-7197a0fbe0613e2b27647ba76c39a1101d4e1a37.zip |
simplify rpm code greatly by forcing rpm2targz and recent portage, and document things
Diffstat (limited to 'eclass/rpm.eclass')
-rw-r--r-- | eclass/rpm.eclass | 130 |
1 files changed, 51 insertions, 79 deletions
diff --git a/eclass/rpm.eclass b/eclass/rpm.eclass index cd8d11f41e35..79c6fc027293 100644 --- a/eclass/rpm.eclass +++ b/eclass/rpm.eclass @@ -1,95 +1,67 @@ -# Copyright 1999-2006 Gentoo Foundation +# Copyright 1999-2009 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 -# $Header: /var/cvsroot/gentoo-x86/eclass/rpm.eclass,v 1.16 2009/03/12 04:29:09 vapier Exp $ +# $Header: /var/cvsroot/gentoo-x86/eclass/rpm.eclass,v 1.17 2009/10/03 08:56:17 vapier Exp $ -# Author : Alastair Tse <liquidx@gentoo.org> (21 Jun 2003) -# -# Convienence class for extracting RPMs -# -# Basically, rpm_src_unpack does: -# -# 1. uses rpm_unpack to unpack a rpm file using rpmoffset and cpio -# 2. if it is a source rpm, it finds all .tar .tar.gz, .tgz, .tbz2, .tar.bz2, -# .zip, .ZIP and unpacks them using unpack() (with a little hackery) -# 3. deletes all the unpacked tarballs and zip files from ${WORKDIR} -# -# This ebuild now re-defines a utility function called rpm_unpack which -# basically does what rpm2targz does, except faster. It does not gzip the -# output tar again but directly extracts to ${WORKDIR} -# -# It will autodetect for rpm2cpio (included in app-arch/rpm) and if it exists -# it will use that instead of the less reliable rpmoffset. This means if a -# particular rpm cannot be read using rpmoffset, you just need to put : -# -# DEPEND="app-arch/rpm" -# -# in your ebuild and it will install and use rpm2cpio instead. If you wish -# to force your ebuild to use rpmoffset in the presence of rpm2cpio, define: -# -# USE_RPMOFFSET_ONLY="1" +# @ECLASS: rpm.eclass +# @MAINTAINER: +# base-system@gentoo.org +# @BLURB: convenience class for extracting RPMs inherit eutils -USE_RPMOFFSET_ONLY=${USE_RPMOFFSET_ONLY-""} +DEPEND=">=app-arch/rpm2targz-9.0.0.3g" -DEPEND=">=app-arch/rpm2targz-9.0-r1" - -# extracts the contents of the RPM in ${WORKDIR} +# @FUNCTION: rpm_unpack +# @USAGE: <rpms> +# @DESCRIPTION: +# Unpack the contents of the specified rpms like the unpack() function. rpm_unpack() { - local rpmfile rpmoff decompcmd - rpmfile=$1 - if [ -z "${rpmfile}" ]; then - return 1 - fi - if [ -x /usr/bin/rpm2cpio -a -z "${USE_RPMOFFSET_ONLY}" ]; then - rpm2cpio ${rpmfile} | cpio -idmu --no-preserve-owner --quiet || return 1 - else - rpmoff=`rpmoffset < ${rpmfile}` - [ -z "${rpmoff}" ] && return 1 + local a + for a in "$@" ; do + echo ">>> Unpacking ${a} to ${PWD}" + [[ ${a} != ./* ]] && a="${DISTDIR}/${a}" + rpm2tar -O "${a}" | tar xf - || die "failure unpacking ${a}" + done +} + +# @FUNCTION: srcrpm_unpack +# @USAGE: <rpms> +# @DESCRIPTION: +# Unpack the contents of the specified rpms like the unpack() function as well +# as any archives that it might contain. Note that the secondary archive +# unpack isn't perfect in that it simply unpacks all archives in the working +# directory (with the assumption that there weren't any to start with). +srcrpm_unpack() { + rpm_unpack "$@" + + # no .src.rpm files, then nothing to do + [[ "$* " != *".src.rpm " ]] && return 0 - decompcmd="gzip -dc" - if [ -n "`dd if=${rpmfile} skip=${rpmoff} bs=1 count=3 2>/dev/null | file - | grep bzip2`" ]; then - decompcmd="bzip2 -dc" - fi - dd ibs=${rpmoff} skip=1 if=${rpmfile} 2> /dev/null \ - | ${decompcmd} \ - | cpio -idmu --no-preserve-owner --quiet || return 1 - fi + local old_shopts=$(shopt -p nullglob) + shopt -s nullglob + + # unpack everything + local a + for a in *.tar.{gz,bz2} *.t{gz,bz2} *.zip *.ZIP ; do + unpack "./${a}" + rm -f "${a}" + done + + eval "${old_shopts}" return 0 } +# @FUNCTION: rpm_src_unpack +# @DESCRIPTION: +# Automatically unpack all archives in ${A} including rpms. If one of the +# archives in a source rpm, then the sub archives will be unpacked as well. rpm_src_unpack() { - local x prefix ext myfail OLD_DISTDIR - - for x in ${A}; do - myfail="failure unpacking ${x}" - ext=${x##*.} - case "$ext" in - rpm) - echo ">>> Unpacking ${x} to ${WORKDIR}" - prefix=${x%.rpm} - cd ${WORKDIR} - rpm_unpack ${DISTDIR}/${x} || die "${myfail}" - - # find all tar.gz files and extract for srpms - if [ "${prefix##*.}" = "src" ]; then - OLD_DISTDIR=${DISTDIR} - DISTDIR=${WORKDIR} - findopts="* -maxdepth 0 -name *.tar" - for t in *.tar.gz *.tgz *.tbz2 *.tar.bz2 *.zip *.ZIP; do - findopts="${findopts} -o -name ${t}" - done - for t in $(find ${findopts} | xargs); do - unpack ${t} - rm -f ${t} - done - DISTDIR=${OLD_DISTDIR} - fi - ;; - *) - unpack ${x} - ;; + local a + for a in ${A} ; do + case ${a} in + *.rpm) srcrpm_unpack "${a}" ;; + *) unpack "${a}" ;; esac done } |