| 1 | # Copyright 1999-2004 Gentoo Foundation |
1 | # Copyright 1999-2011 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.1.1.1 2005/11/30 09:59:18 chriswhite Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/rpm.eclass,v 1.22 2011/12/27 17:55:12 fauli 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 | |
|
|
10 | inherit eutils |
| 31 | |
11 | |
| 32 | USE_RPMOFFSET_ONLY=${USE_RPMOFFSET_ONLY-""} |
12 | DEPEND=">=app-arch/rpm2targz-9.0.0.3g" |
| 33 | |
13 | |
| 34 | 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 | [[ $# -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 | } |
| 35 | |
35 | |
| 36 | # 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). |
| 37 | rpm_unpack() { |
43 | srcrpm_unpack() { |
| 38 | local rpmfile rpmoff decompcmd |
44 | [[ $# -eq 0 ]] && set -- ${A} |
| 39 | rpmfile=$1 |
45 | rpm_unpack "$@" |
| 40 | if [ -z "${rpmfile}" ]; then |
|
|
| 41 | return 1 |
|
|
| 42 | fi |
|
|
| 43 | if [ -x /usr/bin/rpm2cpio -a -z "${USE_RPMOFFSET_ONLY}" ]; then |
|
|
| 44 | rpm2cpio ${rpmfile} | cpio -idmu --no-preserve-owner --quiet || return 1 |
|
|
| 45 | else |
|
|
| 46 | rpmoff=`rpmoffset < ${rpmfile}` |
|
|
| 47 | [ -z "${rpmoff}" ] && return 1 |
|
|
| 48 | |
46 | |
| 49 | decompcmd="gzip -dc" |
47 | # no .src.rpm files, then nothing to do |
| 50 | if [ -n "`dd if=${rpmfile} skip=${rpmoff} bs=1 count=3 2>/dev/null | file - | grep bzip2`" ]; then |
48 | [[ "$* " != *".src.rpm " ]] && return 0 |
| 51 | decompcmd="bzip2 -dc" |
49 | |
| 52 | fi |
50 | eshopts_push -s nullglob |
| 53 | dd ibs=${rpmoff} skip=1 if=${rpmfile} 2> /dev/null \ |
51 | |
| 54 | | ${decompcmd} \ |
52 | # unpack everything |
| 55 | | cpio -idmu --no-preserve-owner --quiet || return 1 |
53 | local a |
| 56 | fi |
54 | for a in *.tar.{gz,bz2} *.t{gz,bz2} *.zip *.ZIP ; do |
|
|
55 | unpack "./${a}" |
|
|
56 | rm -f "${a}" |
|
|
57 | done |
|
|
58 | |
|
|
59 | eshopts_pop |
| 57 | |
60 | |
| 58 | return 0 |
61 | return 0 |
| 59 | } |
62 | } |
| 60 | |
63 | |
|
|
64 | # @FUNCTION: rpm_src_unpack |
|
|
65 | # @DESCRIPTION: |
|
|
66 | # Automatically unpack all archives in ${A} including rpms. If one of the |
|
|
67 | # archives in a source rpm, then the sub archives will be unpacked as well. |
| 61 | rpm_src_unpack() { |
68 | rpm_src_unpack() { |
| 62 | local x prefix ext myfail OLD_DISTDIR |
69 | local a |
| 63 | |
|
|
| 64 | for x in ${A}; do |
70 | for a in ${A} ; do |
| 65 | myfail="failure unpacking ${x}" |
71 | case ${a} in |
| 66 | ext=${x##*.} |
72 | *.rpm) srcrpm_unpack "${a}" ;; |
| 67 | case "$ext" in |
73 | *) unpack "${a}" ;; |
| 68 | rpm) |
|
|
| 69 | echo ">>> Unpacking ${x}" |
|
|
| 70 | prefix=${x%.rpm} |
|
|
| 71 | cd ${WORKDIR} |
|
|
| 72 | rpm_unpack ${DISTDIR}/${x} || die "${myfail}" |
|
|
| 73 | |
|
|
| 74 | # find all tar.gz files and extract for srpms |
|
|
| 75 | if [ "${prefix##*.}" = "src" ]; then |
|
|
| 76 | OLD_DISTDIR=${DISTDIR} |
|
|
| 77 | DISTDIR=${WORKDIR} |
|
|
| 78 | findopts="* -maxdepth 0 -name *.tar" |
|
|
| 79 | for t in *.tar.gz *.tgz *.tbz2 *.tar.bz2 *.zip *.ZIP; do |
|
|
| 80 | findopts="${findopts} -o -name ${t}" |
|
|
| 81 | done |
|
|
| 82 | for t in $(find ${findopts} | xargs); do |
|
|
| 83 | unpack ${t} |
|
|
| 84 | rm -f ${t} |
|
|
| 85 | done |
|
|
| 86 | DISTDIR=${OLD_DISTDIR} |
|
|
| 87 | fi |
|
|
| 88 | ;; |
|
|
| 89 | *) |
|
|
| 90 | unpack ${x} |
|
|
| 91 | ;; |
|
|
| 92 | esac |
74 | esac |
| 93 | done |
75 | done |
| 94 | } |
76 | } |
| 95 | |
77 | |
|
|
78 | # @FUNCTION: rpm_spec_epatch |
|
|
79 | # @USAGE: [spec] |
|
|
80 | # @DESCRIPTION: |
|
|
81 | # Read the specified spec (defaults to ${PN}.spec) and attempt to apply |
|
|
82 | # all the patches listed in it. If the spec does funky things like moving |
|
|
83 | # files around, well this won't handle that. |
|
|
84 | rpm_spec_epatch() { |
|
|
85 | local p spec=$1 |
|
|
86 | local dir |
|
|
87 | |
|
|
88 | if [[ -z ${spec} ]] ; then |
|
|
89 | # search likely places for the spec file |
|
|
90 | for spec in "${PWD}" "${S}" "${WORKDIR}" ; do |
|
|
91 | spec+="/${PN}.spec" |
|
|
92 | [[ -e ${spec} ]] && break |
|
|
93 | done |
|
|
94 | fi |
|
|
95 | [[ ${spec} == */* ]] \ |
|
|
96 | && dir=${spec%/*} \ |
|
|
97 | || dir= |
|
|
98 | |
|
|
99 | ebegin "Applying patches from ${spec}" |
|
|
100 | |
|
|
101 | grep '^%patch' "${spec}" | \ |
|
|
102 | while read line ; do |
|
|
103 | # expand the %patch line |
|
|
104 | set -- ${line} |
|
|
105 | p=$1 |
|
|
106 | shift |
|
|
107 | |
|
|
108 | # process the %patch arguments |
|
|
109 | local arg |
|
|
110 | EPATCH_OPTS= |
|
|
111 | for arg in "$@" ; do |
|
|
112 | case ${arg} in |
|
|
113 | -b) EPATCH_OPTS+=" --suffix" ;; |
|
|
114 | *) EPATCH_OPTS+=" ${arg}" ;; |
|
|
115 | esac |
|
|
116 | done |
|
|
117 | |
|
|
118 | # extract the patch name from the Patch# line |
|
|
119 | set -- $(grep "^P${p#%p}: " "${spec}") |
|
|
120 | shift |
|
|
121 | epatch "${dir:+${dir}/}$*" |
|
|
122 | done |
|
|
123 | |
|
|
124 | eend |
|
|
125 | } |
|
|
126 | |
| 96 | EXPORT_FUNCTIONS src_unpack |
127 | EXPORT_FUNCTIONS src_unpack |