Score:0

Programmatically query latest kernel version to rebuild driver?

in flag

Is there a way to programmatically query the latest kernel version for Ubuntu 20.04 - e.g. 5.4.0-88, 5.4.0-91, 5.4.0-92, etc. perhaps querying a URL of sorts?

I need to build an automated process that rebuilds a driver to a particular kernel version. Usually, DKMS would take care of this, but the driver is for a server with security restrictions and cannot have build tools installed on it. It is also not able to contact servers on the internet, patches are applied from a local server.

The build process would query for the latest 5.4.0-x kernel and if there is a new one for which headers haven't been installed yet, install the appropriate headers package, then rebuild the driver against those headers.

Thanks for any help

Score:0
jp flag

Here is a rather crude solution I came up with. It essentially gets the linux-image-generic package information for focal-updates by reading the Packages file for the apt repository. The package version is then extracted, and the version in the dependency name if that is the format you need.

curl -s http://us.archive.ubuntu.com/ubuntu/dists/focal-updates/main/binary-amd64/Packages.gz | zcat | sed -n -e '/^Package: linux-image-generic$/,/^$/p' | sed -n -e '/^Depends:/s/^.*linux-image-\([-.0-9]*\)-.*/\1/p' -e '/^Version:/s/^Version: //p'

Here is the command in action

$ curl -s http://us.archive.ubuntu.com/ubuntu/dists/focal-updates/main/binary-amd64/Packages.gz | zcat | sed -n -e '/^Package: linux-image-generic$/,/^$/p' | sed -n -e '/^Depends:/s/^.*linux-image-\([-.0-9]*\)-.*/\1/p' -e '/^Version:/s/^Version: //p'
5.4.0.92.96
5.4.0-92
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.