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

Diff of /eclass/rpm.eclass

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

Revision 1.1 Revision 1.1.1.1
1# Copyright 1999-2003 Gentoo Technologies, Inc. 1# Copyright 1999-2004 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 2003/06/21 13:24:12 liquidx Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/rpm.eclass,v 1.1.1.1 2005/11/30 09:59:18 chriswhite Exp $
4 4
5# Author : Alastair Tse <liquidx@gentoo.org> (21 Jun 2003) 5# Author : Alastair Tse <liquidx@gentoo.org> (21 Jun 2003)
6# 6#
7# Convienence class for extracting RPMs 7# Convienence class for extracting RPMs
8# 8#
9# Basically, rpm_src_unpack does: 9# Basically, rpm_src_unpack does:
10# 10#
11# 1. convert all *.rpm in ${A} to tar.gz, non rpm files are passed through 11# 1. uses rpm_unpack to unpack a rpm file using rpmoffset and cpio
12# unpack()
13# 2. unpacks the tar.gz into ${WORKDIR}
14# 3. if it is a source rpm, it finds all .tar .tar.gz, .tgz, .tbz2, .tar.bz2, 12# 2. if it is a source rpm, it finds all .tar .tar.gz, .tgz, .tbz2, .tar.bz2,
15# .zip, .ZIP and unpacks them using unpack() (with a little hackery) 13# .zip, .ZIP and unpacks them using unpack() (with a little hackery)
16# 4. deletes all the unpacked tarballs and zip files from ${WORKDIR} 14# 3. deletes all the unpacked tarballs and zip files from ${WORKDIR}
17# 15#
18# Warning !! 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# 19#
20# Sometimes, pure rpm2targz will fail on certain RPMs (eg: scim-chinese) 20# It will autodetect for rpm2cpio (included in app-arch/rpm) and if it exists
21# because their code for detecting RPM header offset is not good enough. 21# it will use that instead of the less reliable rpmoffset. This means if a
22# In that case, you need to add app-arch/rpm to your DEPEND. rpm2targz 22# particular rpm cannot be read using rpmoffset, you just need to put :
23# will automatically find rpm2cpio and use it instead of its own rpmoffset.
24# 23#
25# Also, rpm2targz-8.0 behaves differently from rpm2targz-9.0. The newer 24# DEPEND="app-arch/rpm"
26# versions will autodetect rpm2cpio whereas 8.0 doesn't. Also, 9.0 will 25#
27# detect if it is a source rpm and place files in ${prefix%.src} whereas 26# in your ebuild and it will install and use rpm2cpio instead. If you wish
28# 8.0 will just place them in the current directory. This eclass DEPENDS 27# to force your ebuild to use rpmoffset in the presence of rpm2cpio, define:
29# on rpm2targz 9.0. 28#
29# USE_RPMOFFSET_ONLY="1"
30 30
31ECLASS="rpm"
32INHERITED="$INHERITED $ECLASS"
33 31
34newdepend ">=app-arch/rpm2targz-0.9" 32USE_RPMOFFSET_ONLY=${USE_RPMOFFSET_ONLY-""}
33
34DEPEND=">=app-arch/rpm2targz-9.0-r1"
35
36# extracts the contents of the RPM in ${WORKDIR}
37rpm_unpack() {
38 local rpmfile rpmoff decompcmd
39 rpmfile=$1
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
49 decompcmd="gzip -dc"
50 if [ -n "`dd if=${rpmfile} skip=${rpmoff} bs=1 count=3 2>/dev/null | file - | grep bzip2`" ]; then
51 decompcmd="bzip2 -dc"
52 fi
53 dd ibs=${rpmoff} skip=1 if=${rpmfile} 2> /dev/null \
54 | ${decompcmd} \
55 | cpio -idmu --no-preserve-owner --quiet || return 1
56 fi
57
58 return 0
59}
35 60
36rpm_src_unpack() { 61rpm_src_unpack() {
37 local x prefix ext myfail OLD_DISTDIR 62 local x prefix ext myfail OLD_DISTDIR
38 63
39 for x in ${A}; do 64 for x in ${A}; do
40 myfail="failure unpacking ${x}" 65 myfail="failure unpacking ${x}"
41 ext=${x##*.} 66 ext=${x##*.}
42 case "$ext" in 67 case "$ext" in
43 rpm) 68 rpm)
44 echo ">>> Unpacking ${x}" 69 echo ">>> Unpacking ${x}"
45 prefix=${x%.rpm} 70 prefix=${x%.rpm}
46 cd ${WORKDIR} 71 cd ${WORKDIR}
47 # convert rpm to tar.gz and then extract
48 rpm2targz ${DISTDIR}/${x} || die "${myfail}" 72 rpm_unpack ${DISTDIR}/${x} || die "${myfail}"
49 if [ "$(tar tzvf ${WORKDIR}/${prefix}.tar.gz | wc -l)" -lt 2 ]; then 73
50 die "rpm2targz failed, produced an empty tar.gz"
51 fi
52 tar xz --no-same-owner -f ${WORKDIR}/${prefix}.tar.gz || die "${myfail}"
53 rm -f ${WORKDIR}/${prefix}.tar.gz
54
55 # find all tar.gz files and extract for srpms 74 # find all tar.gz files and extract for srpms
56 if [ "${prefix##*.}" = "src" ]; then 75 if [ "${prefix##*.}" = "src" ]; then
57 OLD_DISTDIR=${DISTDIR} 76 OLD_DISTDIR=${DISTDIR}
58 DISTDIR=${WORKDIR} 77 DISTDIR=${WORKDIR}
59 findopts="-name *.tar" 78 findopts="* -maxdepth 0 -name *.tar"
60 for t in *.tar.gz *.tgz *.tbz2 *.tar.bz2 *.zip *.ZIP; do 79 for t in *.tar.gz *.tgz *.tbz2 *.tar.bz2 *.zip *.ZIP; do
61 findopts="${findopts} -o -name ${t}" 80 findopts="${findopts} -o -name ${t}"
62 done 81 done
63 for t in $(find ${prefix%.src} ${findopts} | xargs); do 82 for t in $(find ${findopts} | xargs); do
64 unpack ${t} 83 unpack ${t}
65 rm -f ${t} 84 rm -f ${t}
66 done 85 done
67 DISTDIR=${OLD_DISTDIR} 86 DISTDIR=${OLD_DISTDIR}
68 fi 87 fi
69 ;; 88 ;;
70 *) 89 *)
71 unpack ${x} 90 unpack ${x}
72 ;; 91 ;;
73 esac 92 esac
74 done 93 done
75
76} 94}
77 95
78EXPORT_FUNCTIONS src_unpack 96EXPORT_FUNCTIONS src_unpack

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.1.1.1

  ViewVC Help
Powered by ViewVC 1.1.20