Gentoo Archives: gentoo-portage-dev

From: Fabian Groffen <grobian@g.o>
To: gentoo-portage-dev@l.g.o
Subject: Re: [gentoo-portage-dev] How to extract the version/revision of an installed package?
Date: Wed, 26 Nov 2008 08:30:01
Message-Id: 20081126082956.GA98089@gentoo.org
In Reply to: Re: [gentoo-portage-dev] How to extract the version/revision of an installed package? by Ned Ludd
1 On 25-11-2008 16:15:09 -0800, Ned Ludd wrote:
2 > On Tue, 2008-11-25 at 18:05 +0200, Amit Dor-Shifer wrote:
3 > > Given the following:
4 > > # qlist -Iv sys-apps/portage
5 > > sys-apps/portage-2.1.4.5
6 > >
7 > > How do I safely extract the "2.1.4.5"?
8 > >
9 > > (I don't necessarily need to use qlist. Just want to get the version of
10 > > an installed package within a bash script)
11 >
12 > qatom $(qlist -ICv sys-apps/portage) | awk '{print $3}'
13
14 I happen to do it in bash for my update script, it hasn't broke yet:
15
16 get_ebuildversion() {
17 if [[ -z $1 ]] ; then
18 return
19 fi
20
21 # strip extension
22 t=${1%.ebuild}
23 # abort if this is not an ebuild
24 if [[ $t == $1 ]] ; then
25 return
26 fi
27 # strip package name
28 t=${t#*-}
29 # sometimes there are dashes in the package name
30 while [[ ${t:0:1} < "0" || ${t:0:1} > "9" ]] ; do
31 [[ $t != ${t#*-} ]] \
32 && t=${t#*-} \
33 || break
34 done
35
36 echo ${t}
37 }
38
39 you might want to remove the .ebuild check and strip the category ($1#*/})
40
41
42 --
43 Fabian Groffen
44 Gentoo on a different level