How do I get the real full package name (including the version) that would be installed if I ran apt-get install pseudo-package-name
?
This is related to this previous question: Get the kernel version from lts package?
Example:
apt-get install linux-image-generic-lts-trusty
would install (as of right now on my 32-bit Trusty server):
linux-image-3.13.0-35-generic
I've tried the following, but none give me the answer. I'm trying to script this so I can just grab the linux-headers.
$ sudo apt-get install -qqs linux-image-generic-lts-trusty
Inst linux-image-generic-lts-trusty (3.13.0.35.42 Ubuntu:14.04/trusty-updates [i386])
Conf linux-image-generic-lts-trusty (3.13.0.35.42 Ubuntu:14.04/trusty-updates [i386])
$ apt-cache depends linux-image-generic-lts-trusty
linux-image-generic-lts-trusty
Depends: linux-image-generic
$ apt-cache depends linux-image-generic
linux-image-generic
Depends: linux-image-3.13.0-35-generic
Depends: linux-image-extra-3.13.0-35-generic
Depends: linux-firmware
$ apt-cache policy linux-image-generic-lts-trusty
linux-image-generic-lts-trusty:
Installed: (none)
Candidate: 3.13.0.35.42
Version table:
3.13.0.35.42 0
500 http://us.archive.ubuntu.com/ubuntu/ trusty-updates/main i386 Packages
500 http://security.ubuntu.com/ubuntu/ trusty-security/main i386 Packages
3.13.0.24.28 0
500 http://us.archive.ubuntu.com/ubuntu/ trusty/main i386 Packages
After some exploration of /var/lib/{apt,dpkg}, I relealized that there's not a generic, scriptable answer to this problem. So, similar to the answers below from @mchid and @muru, I did it like this:
#!/bin/bash
metapackage=linux-image-generic-lts-trusty
linux_package_version=$(apt-cache policy $metapackage |\
sed -nE '/Candidate:/ s,[^[:digit:]]*([[:digit:]\.]+)\.([[:digit:]]+)\.[[:digit:]]+,\1-\2,p')
apt-get download linux-headers-${linux_package_version}-generic linux-headers-${linux_package_version})