Sunday, April 28, 2024
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 2138  / 3 Years ago, tue, june 22, 2021, 10:49:53

How do I find the most recent version of a package in the repositories in a shell script? If I use apt-cache-policy, I get the installed version as "Candidate", not the most recent one from the repositories.



apt-cache policy nvidia-current shows:



nvidia-current:
Installed: 280.13-0ppa~natty1
Candidate: 280.13-0ppa~natty1
Version table:
*** 280.13-0ppa~natty1 0
100 /var/lib/dpkg/status
270.41.06-0ubuntu1 0
500 http://archive.ubuntu.com/ubuntu/ natty/restricted amd64 Packages


It looks like the installed version is marked with ***, so that one must be ignored. Perhaps there is an awk script that could be used?


More From » package-management

 Answers
2

I suggest the following awk script, to which feed apt-cache policy output:



#!/usr/bin/awk -f

/^ [^ ]/ {
version = $1
}
/^ *** [^ ]/ {
version = $2
}
/^ [^ ]/ {
server = $2
if (server !~ /^//) {
print version
exit
}
}

[#43926] Wednesday, June 23, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
raldership

Total Points: 222
Total Questions: 115
Total Answers: 124

Location: North Korea
Member since Fri, Nov 4, 2022
2 Years ago
;