5

I have a set of (source) URIs, distributions and sections enabled in my Debian Wheezy apt configuration. Now I want a list of all installed packages, and for each of those, the source URI, "distribution" and "section" that the currently installed version of each respective package has been installed from.

I'm basically looking for something like the output of dpkg -l but instead of the description it would show the source URI, distribution and section. Something like:

||/ Name       Version           Arch  InstalledFrom
+++-==========-=================-=====-===================
ii  package1   1:4.14-1.1+deb7u1 amd64 ftp://ftp.se.debian.org/debian wheezy main
ii  package2   1.7-1             all   ftp://ftp.se.debian.org/debian wheezy/updates main
ii  package3   1.0.25+3~deb7u1   all   ftp://ftp.se.debian.org/debian wheezy non-free
ii  package4   0.9.8~3           amd64 local
ii  package5   7.2.107           i386  local

How can I obtain such a list of packages?

Nicely formatted would be a bonus, but mostly anything that I can grep for interesting line substrings (or even just browse through) will likely do.

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
user
  • 28,901
  • Take a look at dctrl-tools. I don't think what you want is available within dpkg at least, which isn't the most flexible tool. Mercurial, for example, has a DSL which lets you configure the output of log and other commands, but that isn't common with command line tools. If you want something exactly like this, my quess is you'll have to write it yourself if something like dctrl-tools won't do it for you. – Faheem Mitha Feb 08 '15 at 16:12
  • 1
  • Did you want to know the section, or the component? main and non-free are components, not sections. See https://wiki.debian.org/SourcesList – mpb Aug 23 '18 at 16:39
  • @mpb To be honest, after three and a half years, I don't remember. :-) – user Aug 23 '18 at 16:40
  • @Michael Kjörling So the wiki ( https://wiki.debian.org/SourcesList ) calls them "components", but the Debian package search page ( https://www.debian.org/distrib/packages#search_packages ) calls them "sections". Confusing! The problem is, "section" does have another meaning in the context of Debian packages. So the search page is probably incorrect and misleading. (Update: the sources.list man page also calls them components.) – mpb Aug 23 '18 at 16:52

4 Answers4

4

As well as apt-cache policy, described in Braiam's answer, you can use apt-show-versions and apt-forktracer.

apt-show-versions by default will list all installed packages with the suite they come from, their version and whether they can be upgraded; for example

afl:amd64/experimental *manually* upgradeable from 1.28b-1 to 1.36b-1
agedu:amd64/testing 9723-1 uptodate
devio:armhf 1.2-1 installed: No available version in archive

With the -a option it lists the installed version and all available versions in all the repositories you have configured:

afl:amd64 1.28b-1 install ok installed
No stable version
No testing version
No unstable version
afl:amd64 1.36b-1 experimental ftp.fr.debian.org
afl:amd64/experimental *manually* upgradeable from 1.28b-1 to 1.36b-1
agedu:amd64 9723-1 install ok installed
No stable version
agedu:amd64 9723-1 testing  ftp.fr.debian.org
agedu:amd64 9723-1 unstable ftp.fr.debian.org
No experimental version
agedu:amd64/testing 9723-1 uptodate

apt-forktracer lists the packages which don't come from the standard repositories or whose installed version doesn't match those available in the standard repositories:

afl (1.28b-1) [Debian: 1.36b-1]
bb (1.3rc1-8.2) [Debian: 1.3rc1-8.1+b1 1.3rc1-8.1+b1]
biew (5.7.3.1-0.1) [SK2: 5.7.3.1-0.1]
Stephen Kitt
  • 434,908
4

I found myself putting together pieces from the different answers, particularly Braiam's and muru's. In the end, I ended up with this oneliner, which gets me close enough to a start that I should be able to figure out the rest:

dpkg-query --showformat '${Package}\n' -W | \
while read package; do \
  apt-cache policy $package | grep -q wheezy/non-free && echo $package ; \
done

The above lists the names of all packages which apt-cache policy reports as coming from wheezy/non-free (not exactly, but close enough for the moment). By adjusting what the script does with the apt-cache policy output, while it won't be in a nice tabular format (at least out of the box), it should be possible to get fairly close to what I am after.

Thanks to everyone who helped out!

user
  • 28,901
3

You are looking for apt-cache policy output:

➜  ~  apt-cache policy skype
skype:i386:
  Installed: 4.3.0.37-1
  Candidate: 4.3.0.37-1
  Version table:
 *** 4.3.0.37-1 0
        100 /var/lib/dpkg/status
➜  ~  apt-cache policy irssi
irssi:
  Installed: 0.8.17-1
  Candidate: 0.8.17-1
  Version table:
 *** 0.8.17-1 0
        900 http://http.debian.net/debian/ testing/main amd64 Packages
        500 http://http.debian.net/debian/ unstable/main amd64 Packages
        100 /var/lib/dpkg/status
➜  ~  apt-cache policy megasync
megasync:
  Installed: 1.0.39
  Candidate: 1.0.39
  Version table:
 *** 1.0.39 0
        500 http://mega.nz/linux/MEGAsync/Debian_7.0/ ./ Packages
        100 /var/lib/dpkg/status

In this case, the installed version of skype isn't available from any repository (that includes local installation), irssi is installed from Debian repositories, and megasync is from a third party repository.

Braiam
  • 35,991
3

-l is one of the options of dpkg-query, which has another option, -W (or --show). -W allows use to select an output format. You can try:

dpkg-query --showformat '${Status}\t${Package}\t${Version}\t${Architecture}\t${Origin}\t${Section}\n' -W | 
  column -ts $'\t'

For example:

$ dpkg-query --showformat '${db:Status-Abbrev}\t${Package}\t${Version}\t${Architecture}\t${Origin}\t${Section}\n' -W | column -ts $'\t' | head
ii  account-plugin-aim           3.8.6-0ubuntu9.1                amd64  gnome
ii  account-plugin-facebook      0.11+14.04.20140409.1-0ubuntu1  all    gnome
ii  account-plugin-flickr        0.11+14.04.20140409.1-0ubuntu1  all    gnome
ii  account-plugin-google        0.11+14.04.20140409.1-0ubuntu1  all    gnome
ii  account-plugin-jabber        3.8.6-0ubuntu9.1                amd64  gnome
ii  account-plugin-salut         3.8.6-0ubuntu9.1                amd64  gnome
ii  account-plugin-twitter       0.11+14.04.20140409.1-0ubuntu1  all    gnome
ii  account-plugin-windows-live  0.11+14.04.20140409.1-0ubuntu1  all    gnome
ii  account-plugin-yahoo         3.8.6-0ubuntu9.1                amd64  gnome
ii  accountsservice              0.6.35-0ubuntu7.1               amd64  admin

The URI is not known to dpkg, since that's a frontend (apt) concern. It shouldn't be that difficult to use awk or something to obtain it too, though.

Braiam
  • 35,991
muru
  • 72,889
  • 1
    This doesn't work for me, and it appears that it doesn't work for you either: your sample output doesn't actually include any origin info. (e.g. amd64 gnome -- shouldn't there be an origin tag in between those two columns?) – smammy Mar 26 '22 at 19:12