-1

I want to get all binary packages that belong to specific source package from specific Debian source/repository.

apt show bla-dev command returns output like this:

Package: bla-dev
Version: 1.3-2
Priority: extra
Section: libdevel
Source: bla
Maintainer: someone@someone
Installed-Size: 144 kB
Download-Size: 121 kB
APT-Sources: http://my-repo/ all/main amd64 Packages
Description: Headers

I try to get all Package: and Version: fields of packages that contains the fields:

Source: bla
APT-sources: http://my-repo/

The command apt show '*-*' shows data of all packages so I think it would be helpful but I don't really know how to continue (This command is a little bit heavy - long text as output)

1 Answers1

0

You can grep through the plaintext package list metadata for your repo in /var/lib/apt/lists/, they are world-readable:

$ grep --no-filename /var/lib/apt/lists/*golang* -e 'Package: golang'

ppa.launchpad.net_golang-amd64_Packages:Package: golang
ppa.launchpad.net_golang-amd64_Packages:Package: golang-1.15
ppa.launchpad.net_golang-amd64_Packages:Package: golang-1-15-doc
ppa.launchpad.net_golang-amd64_Packages:Package: golang-1.16
ppa.launchpad.net_golang-amd64_Packages:Package: golang-1.16-doc
...

Edit: to match and print more fields, awk might work better:

awk '
    /Package: golang/  { p=$2 }
    /Version: /        { v=$2 }
    /Source: golang-d/ { s=$2 }
    /^$/               { if (p && s) printf("%s\t%s\n", p, v); p=v=s="" }
' /var/lib/apt/lists/*golang*

Which outputs:

golang  2:1.17~1longsleep1
golang-any      2:1.17~1longsleep1
golang-doc      2:1.16-1longsleep1+bionic
golang-doc      2:1.17~1longsleep1
golang-go       2:1.17~1longsleep1
golang-src      2:1.17~1longsleep1
patraulea
  • 652
  • 2
  • 5
  • 26
  • Thanks! but it returns only the field I search for, I want to see the other fields of matching packages – Barel Elbaz Mar 06 '22 at 10:08
  • How can I distinct the output (Want only last occurrence of each '$p')? @patraulea – Barel Elbaz Mar 06 '22 at 10:41
  • `uniq -f1` skips the first field, and since you need uniq on _only_ the first field, use rev to reverse the lines and back: `awk ... | rev | uniq -f1 | rev`. – patraulea Mar 06 '22 at 12:09
  • And uniq prints the first unique line, you can reverse the order of lines using `tac`: `awk ... | rev | tac | uniq -f1 | tac | rev`. – patraulea Mar 06 '22 at 12:14