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

aptrepository

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.

Best Answer

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.

Related Question