| 1 | # Copyright 1999-2006 Gentoo Foundation |
1 | # Copyright 1999-2009 Gentoo Foundation |
| 2 | # Distributed under the terms of the GNU General Public License v2 |
2 | # Distributed under the terms of the GNU General Public License v2 |
| 3 | # $Header: /var/cvsroot/gentoo-x86/eclass/rpm.eclass,v 1.16 2009/03/12 04:29:09 vapier Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/rpm.eclass,v 1.17 2009/10/03 08:56:17 vapier Exp $ |
| 4 | |
4 | |
| 5 | # Author : Alastair Tse <liquidx@gentoo.org> (21 Jun 2003) |
5 | # @ECLASS: rpm.eclass |
| 6 | # |
6 | # @MAINTAINER: |
|
|
7 | # base-system@gentoo.org |
| 7 | # Convienence class for extracting RPMs |
8 | # @BLURB: convenience 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 | |
9 | |
| 31 | inherit eutils |
10 | inherit eutils |
| 32 | |
11 | |
| 33 | USE_RPMOFFSET_ONLY=${USE_RPMOFFSET_ONLY-""} |
12 | DEPEND=">=app-arch/rpm2targz-9.0.0.3g" |
| 34 | |
13 | |
| 35 | DEPEND=">=app-arch/rpm2targz-9.0-r1" |
14 | # @FUNCTION: rpm_unpack |
|
|
15 | # @USAGE: <rpms> |
|
|
16 | # @DESCRIPTION: |
|
|
17 | # Unpack the contents of the specified rpms like the unpack() function. |
|
|
18 | rpm_unpack() { |
|
|
19 | local a |
|
|
20 | for a in "$@" ; do |
|
|
21 | echo ">>> Unpacking ${a} to ${PWD}" |
|
|
22 | [[ ${a} != ./* ]] && a="${DISTDIR}/${a}" |
|
|
23 | rpm2tar -O "${a}" | tar xf - || die "failure unpacking ${a}" |
|
|
24 | done |
|
|
25 | } |
| 36 | |
26 | |
| 37 | # extracts the contents of the RPM in ${WORKDIR} |
27 | # @FUNCTION: srcrpm_unpack |
|
|
28 | # @USAGE: <rpms> |
|
|
29 | # @DESCRIPTION: |
|
|
30 | # Unpack the contents of the specified rpms like the unpack() function as well |
|
|
31 | # as any archives that it might contain. Note that the secondary archive |
|
|
32 | # unpack isn't perfect in that it simply unpacks all archives in the working |
|
|
33 | # directory (with the assumption that there weren't any to start with). |
| 38 | rpm_unpack() { |
34 | srcrpm_unpack() { |
| 39 | local rpmfile rpmoff decompcmd |
35 | rpm_unpack "$@" |
| 40 | rpmfile=$1 |
|
|
| 41 | if [ -z "${rpmfile}" ]; then |
|
|
| 42 | return 1 |
|
|
| 43 | fi |
|
|
| 44 | if [ -x /usr/bin/rpm2cpio -a -z "${USE_RPMOFFSET_ONLY}" ]; then |
|
|
| 45 | rpm2cpio ${rpmfile} | cpio -idmu --no-preserve-owner --quiet || return 1 |
|
|
| 46 | else |
|
|
| 47 | rpmoff=`rpmoffset < ${rpmfile}` |
|
|
| 48 | [ -z "${rpmoff}" ] && return 1 |
|
|
| 49 | |
36 | |
| 50 | decompcmd="gzip -dc" |
37 | # no .src.rpm files, then nothing to do |
| 51 | if [ -n "`dd if=${rpmfile} skip=${rpmoff} bs=1 count=3 2>/dev/null | file - | grep bzip2`" ]; then |
38 | [[ "$* " != *".src.rpm " ]] && return 0 |
| 52 | decompcmd="bzip2 -dc" |
39 | |
| 53 | fi |
40 | local old_shopts=$(shopt -p nullglob) |
| 54 | dd ibs=${rpmoff} skip=1 if=${rpmfile} 2> /dev/null \ |
41 | shopt -s nullglob |
| 55 | | ${decompcmd} \ |
42 | |
| 56 | | cpio -idmu --no-preserve-owner --quiet || return 1 |
43 | # unpack everything |
| 57 | fi |
44 | local a |
|
|
45 | for a in *.tar.{gz,bz2} *.t{gz,bz2} *.zip *.ZIP ; do |
|
|
46 | unpack "./${a}" |
|
|
47 | rm -f "${a}" |
|
|
48 | done |
|
|
49 | |
|
|
50 | eval "${old_shopts}" |
| 58 | |
51 | |
| 59 | return 0 |
52 | return 0 |
| 60 | } |
53 | } |
| 61 | |
54 | |
|
|
55 | # @FUNCTION: rpm_src_unpack |
|
|
56 | # @DESCRIPTION: |
|
|
57 | # Automatically unpack all archives in ${A} including rpms. If one of the |
|
|
58 | # archives in a source rpm, then the sub archives will be unpacked as well. |
| 62 | rpm_src_unpack() { |
59 | rpm_src_unpack() { |
| 63 | local x prefix ext myfail OLD_DISTDIR |
60 | local a |
| 64 | |
|
|
| 65 | for x in ${A}; do |
61 | for a in ${A} ; do |
| 66 | myfail="failure unpacking ${x}" |
62 | case ${a} in |
| 67 | ext=${x##*.} |
63 | *.rpm) srcrpm_unpack "${a}" ;; |
| 68 | case "$ext" in |
64 | *) unpack "${a}" ;; |
| 69 | rpm) |
|
|
| 70 | echo ">>> Unpacking ${x} to ${WORKDIR}" |
|
|
| 71 | prefix=${x%.rpm} |
|
|
| 72 | cd ${WORKDIR} |
|
|
| 73 | rpm_unpack ${DISTDIR}/${x} || die "${myfail}" |
|
|
| 74 | |
|
|
| 75 | # find all tar.gz files and extract for srpms |
|
|
| 76 | if [ "${prefix##*.}" = "src" ]; then |
|
|
| 77 | OLD_DISTDIR=${DISTDIR} |
|
|
| 78 | DISTDIR=${WORKDIR} |
|
|
| 79 | findopts="* -maxdepth 0 -name *.tar" |
|
|
| 80 | for t in *.tar.gz *.tgz *.tbz2 *.tar.bz2 *.zip *.ZIP; do |
|
|
| 81 | findopts="${findopts} -o -name ${t}" |
|
|
| 82 | done |
|
|
| 83 | for t in $(find ${findopts} | xargs); do |
|
|
| 84 | unpack ${t} |
|
|
| 85 | rm -f ${t} |
|
|
| 86 | done |
|
|
| 87 | DISTDIR=${OLD_DISTDIR} |
|
|
| 88 | fi |
|
|
| 89 | ;; |
|
|
| 90 | *) |
|
|
| 91 | unpack ${x} |
|
|
| 92 | ;; |
|
|
| 93 | esac |
65 | esac |
| 94 | done |
66 | done |
| 95 | } |
67 | } |
| 96 | |
68 | |
| 97 | # @FUNCTION: rpm_spec_epatch |
69 | # @FUNCTION: rpm_spec_epatch |