Gentoo Archives: gentoo-commits

From: "Mike Frysinger (vapier)" <vapier@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-x86 commit in eclass: rpm.eclass
Date: Sat, 03 Oct 2009 08:56:20
Message-Id: E1Mu0Pa-0004Sy-1o@stork.gentoo.org
1 vapier 09/10/03 08:56:18
2
3 Modified: rpm.eclass
4 Log:
5 simplify rpm code greatly by forcing rpm2targz and recent portage, and document things
6
7 Revision Changes Path
8 1.17 eclass/rpm.eclass
9
10 file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/eclass/rpm.eclass?rev=1.17&view=markup
11 plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/eclass/rpm.eclass?rev=1.17&content-type=text/plain
12 diff : http://sources.gentoo.org/viewcvs.py/gentoo-x86/eclass/rpm.eclass?r1=1.16&r2=1.17
13
14 Index: rpm.eclass
15 ===================================================================
16 RCS file: /var/cvsroot/gentoo-x86/eclass/rpm.eclass,v
17 retrieving revision 1.16
18 retrieving revision 1.17
19 diff -u -r1.16 -r1.17
20 --- rpm.eclass 12 Mar 2009 04:29:09 -0000 1.16
21 +++ rpm.eclass 3 Oct 2009 08:56:17 -0000 1.17
22 @@ -1,95 +1,67 @@
23 -# Copyright 1999-2006 Gentoo Foundation
24 +# Copyright 1999-2009 Gentoo Foundation
25 # Distributed under the terms of the GNU General Public License v2
26 -# $Header: /var/cvsroot/gentoo-x86/eclass/rpm.eclass,v 1.16 2009/03/12 04:29:09 vapier Exp $
27 +# $Header: /var/cvsroot/gentoo-x86/eclass/rpm.eclass,v 1.17 2009/10/03 08:56:17 vapier Exp $
28
29 -# Author : Alastair Tse <liquidx@g.o> (21 Jun 2003)
30 -#
31 -# Convienence class for extracting RPMs
32 -#
33 -# Basically, rpm_src_unpack does:
34 -#
35 -# 1. uses rpm_unpack to unpack a rpm file using rpmoffset and cpio
36 -# 2. if it is a source rpm, it finds all .tar .tar.gz, .tgz, .tbz2, .tar.bz2,
37 -# .zip, .ZIP and unpacks them using unpack() (with a little hackery)
38 -# 3. deletes all the unpacked tarballs and zip files from ${WORKDIR}
39 -#
40 -# This ebuild now re-defines a utility function called rpm_unpack which
41 -# basically does what rpm2targz does, except faster. It does not gzip the
42 -# output tar again but directly extracts to ${WORKDIR}
43 -#
44 -# It will autodetect for rpm2cpio (included in app-arch/rpm) and if it exists
45 -# it will use that instead of the less reliable rpmoffset. This means if a
46 -# particular rpm cannot be read using rpmoffset, you just need to put :
47 -#
48 -# DEPEND="app-arch/rpm"
49 -#
50 -# in your ebuild and it will install and use rpm2cpio instead. If you wish
51 -# to force your ebuild to use rpmoffset in the presence of rpm2cpio, define:
52 -#
53 -# USE_RPMOFFSET_ONLY="1"
54 +# @ECLASS: rpm.eclass
55 +# @MAINTAINER:
56 +# base-system@g.o
57 +# @BLURB: convenience class for extracting RPMs
58
59 inherit eutils
60
61 -USE_RPMOFFSET_ONLY=${USE_RPMOFFSET_ONLY-""}
62 +DEPEND=">=app-arch/rpm2targz-9.0.0.3g"
63
64 -DEPEND=">=app-arch/rpm2targz-9.0-r1"
65 -
66 -# extracts the contents of the RPM in ${WORKDIR}
67 +# @FUNCTION: rpm_unpack
68 +# @USAGE: <rpms>
69 +# @DESCRIPTION:
70 +# Unpack the contents of the specified rpms like the unpack() function.
71 rpm_unpack() {
72 - local rpmfile rpmoff decompcmd
73 - rpmfile=$1
74 - if [ -z "${rpmfile}" ]; then
75 - return 1
76 - fi
77 - if [ -x /usr/bin/rpm2cpio -a -z "${USE_RPMOFFSET_ONLY}" ]; then
78 - rpm2cpio ${rpmfile} | cpio -idmu --no-preserve-owner --quiet || return 1
79 - else
80 - rpmoff=`rpmoffset < ${rpmfile}`
81 - [ -z "${rpmoff}" ] && return 1
82 -
83 - decompcmd="gzip -dc"
84 - if [ -n "`dd if=${rpmfile} skip=${rpmoff} bs=1 count=3 2>/dev/null | file - | grep bzip2`" ]; then
85 - decompcmd="bzip2 -dc"
86 - fi
87 - dd ibs=${rpmoff} skip=1 if=${rpmfile} 2> /dev/null \
88 - | ${decompcmd} \
89 - | cpio -idmu --no-preserve-owner --quiet || return 1
90 - fi
91 + local a
92 + for a in "$@" ; do
93 + echo ">>> Unpacking ${a} to ${PWD}"
94 + [[ ${a} != ./* ]] && a="${DISTDIR}/${a}"
95 + rpm2tar -O "${a}" | tar xf - || die "failure unpacking ${a}"
96 + done
97 +}
98 +
99 +# @FUNCTION: srcrpm_unpack
100 +# @USAGE: <rpms>
101 +# @DESCRIPTION:
102 +# Unpack the contents of the specified rpms like the unpack() function as well
103 +# as any archives that it might contain. Note that the secondary archive
104 +# unpack isn't perfect in that it simply unpacks all archives in the working
105 +# directory (with the assumption that there weren't any to start with).
106 +srcrpm_unpack() {
107 + rpm_unpack "$@"
108 +
109 + # no .src.rpm files, then nothing to do
110 + [[ "$* " != *".src.rpm " ]] && return 0
111 +
112 + local old_shopts=$(shopt -p nullglob)
113 + shopt -s nullglob
114 +
115 + # unpack everything
116 + local a
117 + for a in *.tar.{gz,bz2} *.t{gz,bz2} *.zip *.ZIP ; do
118 + unpack "./${a}"
119 + rm -f "${a}"
120 + done
121 +
122 + eval "${old_shopts}"
123
124 return 0
125 }
126
127 +# @FUNCTION: rpm_src_unpack
128 +# @DESCRIPTION:
129 +# Automatically unpack all archives in ${A} including rpms. If one of the
130 +# archives in a source rpm, then the sub archives will be unpacked as well.
131 rpm_src_unpack() {
132 - local x prefix ext myfail OLD_DISTDIR
133 -
134 - for x in ${A}; do
135 - myfail="failure unpacking ${x}"
136 - ext=${x##*.}
137 - case "$ext" in
138 - rpm)
139 - echo ">>> Unpacking ${x} to ${WORKDIR}"
140 - prefix=${x%.rpm}
141 - cd ${WORKDIR}
142 - rpm_unpack ${DISTDIR}/${x} || die "${myfail}"
143 -
144 - # find all tar.gz files and extract for srpms
145 - if [ "${prefix##*.}" = "src" ]; then
146 - OLD_DISTDIR=${DISTDIR}
147 - DISTDIR=${WORKDIR}
148 - findopts="* -maxdepth 0 -name *.tar"
149 - for t in *.tar.gz *.tgz *.tbz2 *.tar.bz2 *.zip *.ZIP; do
150 - findopts="${findopts} -o -name ${t}"
151 - done
152 - for t in $(find ${findopts} | xargs); do
153 - unpack ${t}
154 - rm -f ${t}
155 - done
156 - DISTDIR=${OLD_DISTDIR}
157 - fi
158 - ;;
159 - *)
160 - unpack ${x}
161 - ;;
162 + local a
163 + for a in ${A} ; do
164 + case ${a} in
165 + *.rpm) srcrpm_unpack "${a}" ;;
166 + *) unpack "${a}" ;;
167 esac
168 done
169 }