Related: How do I check package version using apt-get / aptitude?
How do I do this for a given variable debian release, from the command line? Using either apt, dpkg, or aptitude is fine. Ideally, relying on the packages.debian.org website is not ok as the requested release may be out of date. (The ftp archive does contain the older releases).
E.g.:
release="bullseye"
package="wget"
version=$(some_magic_apt_command $release)
echo $version
1.21-1+deb11u1
release="stretch"
package="wget"
version=$(some_magic_apt_command $release)
echo $version
1.18-5+deb9u3
I also need to know which 'repository' it's from. Main, contrib, or nonfree?
release="stretch"
package="wget"
type=$(some_magic_apt_command $release)
echo $type
main
Requirements:
- It has to work for any release: not just the current installed version.
Purpose:
Extracting old packages to find original configuration files that have changed, not remembering what was changed, to figure out how to update these config files for a newer version (the question: what did the programmers change about the config files, it's undocumented).