0

Does apt-get -s upgrade or some other apt command have an option to list the repositories the packages will be downloaded from?

apt-cache policy will tell you for an individual package but I need something that displays the repos for each package, line by line.

4

You could try something like this:

apt-get -s upgrade | awk '/^Inst/ {print $2}' | 
    xargs apt-cache policy | 
    awk '/:$|^$/ && ! /Version table:/ {print "\n" $0 } ; /:\/\// { print $2 }'

Output (run just now on my debian sid system) looks like this:

sqlite3:
http://my.local.mirror.redacted/debian

libsqlite3-0:
http://my.local.mirror.redacted/debian

libsqlite3-0:i386:
http://my.local.mirror.redacted/debian

python-newt:
http://my.local.mirror.redacted/debian

libnewt0.52:
http://my.local.mirror.redacted/debian

libruby:
http://my.local.mirror.redacted/debian
http://my.local.mirror.redacted/debian

mercurial:
http://my.local.mirror.redacted/debian

mercurial-common:
http://my.local.mirror.redacted/debian
http://my.local.mirror.redacted/debian

sysstat:
http://my.local.mirror.redacted/debian

libmilter1.0.1:
http://my.local.mirror.redacted/debian

Some of the packages have two URLs. That's because my system is amd64 with i386 as an added architecture, and these packages have both amd64 and i386 versions available for upgrade.

If you prefer to have the full output line, so that it looks like this:

mercurial-common:
        990 http://my.local.mirror.redacted/debian unstable/main amd64 Packages
        990 http://my.local.mirror.redacted/debian unstable/main i386 Packages

then just delete { print $2 } from the second awk script.

2
  • I would have preferred an option which both package and repo on the same line. That I will work out myself. – vfclists Mar 4 '16 at 1:44
  • that would have been fairly easy to do except for the fact that some packages have two URLs listed (and i haven't seen it, or have any documentation or evidence to support this conjecture but maybe even more than two in some circumstances)....but it's why I wrote the 2nd awk script to add a \n newline before each package - that makes it easier to post-process in 'paragraph mode', e.g. with perl -00 or similar. – cas Mar 4 '16 at 5:31
1

You can use --print-uris which gives something like this,

~# apt-get upgrade -s --print-uris
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be upgraded:
  libcgi-fast-perl libperl5.14 perl perl-base perl-modules
5 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Inst perl [5.14.2-21+deb7u2] (5.14.2-21+deb7u3 Debian-Security:7.0/oldstable [i386]) []
Inst libperl5.14 [5.14.2-21+deb7u2] (5.14.2-21+deb7u3 Debian-Security:7.0/oldstable [i386]) []
Inst perl-base [5.14.2-21+deb7u2] (5.14.2-21+deb7u3 Debian-Security:7.0/oldstable [i386]) []
Conf perl-base (5.14.2-21+deb7u3 Debian-Security:7.0/oldstable [i386]) []
Inst perl-modules [5.14.2-21+deb7u2] (5.14.2-21+deb7u3 Debian-Security:7.0/oldstable [all])
Inst libcgi-fast-perl [5.14.2-21+deb7u2] (5.14.2-21+deb7u3 Debian-Security:7.0/oldstable [all])
Conf perl (5.14.2-21+deb7u3 Debian-Security:7.0/oldstable [i386])
Conf perl-modules (5.14.2-21+deb7u3 Debian-Security:7.0/oldstable [all])
Conf libperl5.14 (5.14.2-21+deb7u3 Debian-Security:7.0/oldstable [i386])
Conf libcgi-fast-perl (5.14.2-21+deb7u3 Debian-Security:7.0/oldstable [all])
1
  • This might be as good as one is going to get with the existing tool. But does it completely specify the repository? – Faheem Mitha Mar 3 '16 at 9:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.