stable/eclass/rpm5.eclass

114 lines
3.0 KiB
Bash
Raw Normal View History

2010-11-10 15:42:34 +01:00
# Copyright 1999-2009 Gentoo Foundation
2009-01-16 13:25:23 +01:00
# Distributed under the terms of the GNU General Public License v2
2010-11-10 15:42:34 +01:00
# $Header: /var/cvsroot/gentoo-x86/eclass/rpm.eclass,v 1.20 2010/07/18 21:57:20 vapier Exp $
2009-01-16 13:25:23 +01:00
2010-11-10 15:42:34 +01:00
# @ECLASS: rpm.eclass
# @MAINTAINER:
# base-system@gentoo.org
# @BLURB: convenience class for extracting RPMs
2009-01-16 13:25:23 +01:00
2010-11-10 15:42:34 +01:00
inherit eutils
2009-01-16 13:25:23 +01:00
DEPEND=">=app-arch/rpm5offset-9.0"
2010-11-10 15:42:34 +01:00
# @FUNCTION: rpm_unpack
# @USAGE: <rpms>
# @DESCRIPTION:
# Unpack the contents of the specified rpms like the unpack() function.
2009-04-02 21:15:37 +02:00
rpm5_unpack() {
2010-11-10 15:42:34 +01:00
[[ $# -eq 0 ]] && set -- ${A}
local a rpmoff decompcmd
for a in "$@" ; do
echo ">>> Unpacking ${a} to ${PWD}"
if [[ ${a} == ./* ]] ; then
: nothing to do -- path is local
elif [[ ${a} == ${DISTDIR}/* ]] ; then
ewarn 'QA: do not use ${DISTDIR} with rpm_unpack -- it is added for you'
elif [[ ${a} == /* ]] ; then
ewarn 'QA: do not use full paths with rpm_unpack -- use ./ paths instead'
else
a="${DISTDIR}/${a}"
fi
# rpm2tar -O "${a}" | tar xf - || die "failure unpacking ${a}"
rpmoff=`rpm5offset < ${a}`
2009-01-16 13:25:23 +01:00
[ -z "${rpmoff}" ] && return 1
decompcmd="lzma -dc"
2010-11-10 15:42:34 +01:00
if [ -n "`dd if=${a} skip=${rpmoff} bs=1 count=3 2>/dev/null | file - | grep bzip2`" ]; then
2009-01-16 13:25:23 +01:00
decompcmd="bzip2 -dc"
fi
2010-11-10 15:42:34 +01:00
if [ -n "`dd if=${a} skip=${rpmoff} bs=1 count=3 2>/dev/null | file - | grep gzip`" ]; then
2009-01-16 13:25:23 +01:00
decompcmd="gzip -dc"
fi
2010-11-10 15:42:34 +01:00
dd ibs=${rpmoff} skip=1 if=${a} 2> /dev/null \
2009-01-16 13:25:23 +01:00
| ${decompcmd} \
| cpio -idmu --no-preserve-owner --quiet || return 1
2010-11-10 15:42:34 +01:00
done
}
# @FUNCTION: srcrpm_unpack
# @USAGE: <rpms>
# @DESCRIPTION:
# Unpack the contents of the specified rpms like the unpack() function as well
# as any archives that it might contain. Note that the secondary archive
# unpack isn't perfect in that it simply unpacks all archives in the working
# directory (with the assumption that there weren't any to start with).
srcrpm5_unpack() {
[[ $# -eq 0 ]] && set -- ${A}
rpm5_unpack "$@"
# no .src.rpm files, then nothing to do
[[ "$* " != *".src.rpm " ]] && return 0
eshopts_push -s nullglob
# unpack everything
local a
for a in *.tar.{gz,bz2} *.t{gz,bz2} *.zip *.ZIP ; do
unpack "./${a}"
rm -f "${a}"
done
eshopts_pop
2009-01-16 13:25:23 +01:00
return 0
}
2010-11-10 15:42:34 +01:00
# @FUNCTION: rpm_src_unpack
# @DESCRIPTION:
# Automatically unpack all archives in ${A} including rpms. If one of the
# archives in a source rpm, then the sub archives will be unpacked as well.
2009-04-02 21:15:37 +02:00
rpm5_src_unpack() {
2010-11-10 15:42:34 +01:00
local a
for a in ${A} ; do
case ${a} in
*.rpm) srcrpm5_unpack "${a}" ;;
*) unpack "${a}" ;;
2009-01-16 13:25:23 +01:00
esac
done
}
2010-11-10 15:42:34 +01:00
# @FUNCTION: rpm_spec_epatch
# @USAGE: [spec]
# @DESCRIPTION:
# Read the specified spec (defaults to ${PN}.spec) and attempt to apply
# all the patches listed in it. If the spec does funky things like moving
# files around, well this won't handle that.
rpm5_spec_epatch() {
local p spec=${1:-${PN}.spec}
local dir=${spec%/*}
grep '^%patch' "${spec}" | \
while read line ; do
set -- ${line}
p=$1
shift
EPATCH_OPTS="$*"
set -- $(grep "^P${p#%p}: " "${spec}")
shift
epatch "${dir:+${dir}/}$*"
done
}
2009-01-16 13:25:23 +01:00
EXPORT_FUNCTIONS src_unpack