/[gentoo-x86]/eclass/rpm.eclass
Gentoo

Diff of /eclass/rpm.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.6 Revision 1.19
1# Copyright 1999-2003 Gentoo Technologies, Inc. 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.6 2003/06/22 16:31:23 liquidx Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/rpm.eclass,v 1.19 2009/10/05 06:14:36 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
31ECLASS="rpm" 10inherit eutils
32INHERITED="$INHERITED $ECLASS"
33 11
34USE_RPMOFFSET_ONLY=${USE_RPMOFFSET_ONLY-""} 12DEPEND=">=app-arch/rpm2targz-9.0.0.3g"
35 13
36newdepend "app-arch/rpm2targz" 14# @FUNCTION: rpm_unpack
15# @USAGE: <rpms>
16# @DESCRIPTION:
17# Unpack the contents of the specified rpms like the unpack() function.
18rpm_unpack() {
19 [[ $# -eq 0 ]] && set -- ${A}
20 local a
21 for a in "$@" ; do
22 echo ">>> Unpacking ${a} to ${PWD}"
23 if [[ ${a} == ./* ]] ; then
24 : nothing to do -- path is local
25 elif [[ ${a} == ${DISTDIR}/* ]] ; then
26 ewarn 'QA: do not use ${DISTDIR} with rpm_unpack -- it is added for you'
27 elif [[ ${a} == /* ]] ; then
28 ewarn 'QA: do not use full paths with rpm_unpack -- use ./ paths instead'
29 else
30 a="${DISTDIR}/${a}"
31 fi
32 rpm2tar -O "${a}" | tar xf - || die "failure unpacking ${a}"
33 done
34}
37 35
38# extracts the contents of the RPM in ${WORKDIR} 36# @FUNCTION: srcrpm_unpack
37# @USAGE: <rpms>
38# @DESCRIPTION:
39# Unpack the contents of the specified rpms like the unpack() function as well
40# as any archives that it might contain. Note that the secondary archive
41# unpack isn't perfect in that it simply unpacks all archives in the working
42# directory (with the assumption that there weren't any to start with).
39rpm_unpack() { 43srcrpm_unpack() {
40 local rpmfile 44 [[ $# -eq 0 ]] && set -- ${A}
41 rpmfile=$1 45 rpm_unpack "$@"
42 if [ -z "${rpmfile}" ]; then
43 return 1
44 fi
45 46
46 cd ${WORKDIR} 47 # no .src.rpm files, then nothing to do
47 if [ -x /usr/bin/rpm2cpio -a -z "${USE_RPMOFFSET_ONLY}" ]; then 48 [[ "$* " != *".src.rpm " ]] && return 0
48 rpm2cpio ${rpmfile} | cpio -idmu --no-preserve-owner --quiet || return 1 49
49 else 50 local old_shopts=$(shopt -p nullglob)
50 dd ibs=`rpmoffset < ${rpmfile}` skip=1 if=${rpmfile} 2> /dev/null \ 51 shopt -s nullglob
51 | gzip -dc \ 52
52 | cpio -idmu --no-preserve-owner --quiet || return 1 53 # unpack everything
53 fi 54 local a
54 55 for a in *.tar.{gz,bz2} *.t{gz,bz2} *.zip *.ZIP ; do
56 unpack "./${a}"
57 rm -f "${a}"
58 done
59
60 eval "${old_shopts}"
61
55 return 0 62 return 0
56} 63}
57 64
65# @FUNCTION: rpm_src_unpack
66# @DESCRIPTION:
67# Automatically unpack all archives in ${A} including rpms. If one of the
68# archives in a source rpm, then the sub archives will be unpacked as well.
58rpm_src_unpack() { 69rpm_src_unpack() {
59 local x prefix ext myfail OLD_DISTDIR 70 local a
60
61 for x in ${A}; do 71 for a in ${A} ; do
62 myfail="failure unpacking ${x}" 72 case ${a} in
63 ext=${x##*.} 73 *.rpm) srcrpm_unpack "${a}" ;;
64 case "$ext" in 74 *) unpack "${a}" ;;
65 rpm)
66 echo ">>> Unpacking ${x}"
67 prefix=${x%.rpm}
68 cd ${WORKDIR}
69 rpm_unpack ${DISTDIR}/${x} || die "${myfail}"
70
71 # find all tar.gz files and extract for srpms
72 if [ "${prefix##*.}" = "src" ]; then
73 OLD_DISTDIR=${DISTDIR}
74 DISTDIR=${WORKDIR}
75 findopts="* -maxdepth 0 -name *.tar"
76 for t in *.tar.gz *.tgz *.tbz2 *.tar.bz2 *.zip *.ZIP; do
77 findopts="${findopts} -o -name ${t}"
78 done
79 for t in $(find ${findopts} | xargs); do
80 unpack ${t}
81 rm -f ${t}
82 done
83 DISTDIR=${OLD_DISTDIR}
84 fi
85 ;;
86 *)
87 unpack ${x}
88 ;;
89 esac 75 esac
90 done 76 done
91 77}
78
79# @FUNCTION: rpm_spec_epatch
80# @USAGE: [spec]
81# @DESCRIPTION:
82# Read the specified spec (defaults to ${PN}.spec) and attempt to apply
83# all the patches listed in it. If the spec does funky things like moving
84# files around, well this won't handle that.
85rpm_spec_epatch() {
86 local p spec=${1:-${PN}.spec}
87 local dir=${spec%/*}
88 grep '^%patch' "${spec}" | \
89 while read line ; do
90 set -- ${line}
91 p=$1
92 shift
93 EPATCH_OPTS="$*"
94 set -- $(grep "^P${p#%p}: " "${spec}")
95 shift
96 epatch "${dir:+${dir}/}$*"
97 done
92} 98}
93 99
94EXPORT_FUNCTIONS src_unpack 100EXPORT_FUNCTIONS src_unpack

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.19

  ViewVC Help
Powered by ViewVC 1.1.20