How to fetch the current fedora version number from the web?

I want to create a Distrobox assembly file that usee the latest Fedora version and installs a COPR, a bunch of packages, and exports an app.

Fedoras QGis packages are really good so I want to use that for the image.

How can I get the latest fedora version on any OS so that I get a variable like

VERSION=41

If you do cat /etc/os-release you will find a line with almost exactly what you wish. Mine showsVERSION_ID=40
This is on the system, but I have no clue how to do the same to identify the latest released version on the web other than looking at the download page and pulling the data from there. The download page (for whatever spin) should always show the latest released version.
Fedora 40 is downloaded from
https://download.fedoraproject.org/pub/fedora/linux/releases/40/

Workstation and spins are under that location.

1 Like

Thanks!

So, this HTML file could be scraped

After a prompt (to extract the highest 2-digit number and export as environment variable)

ChatGPT gave me this, I have not tried or corrected it. The idea with the β€œ/” was of the AI, I overlooked that.

#!/bin/bash

# Fetch the HTML content from the redirected mirror
url="https://download.fedoraproject.org/pub/fedora/linux/releases/"
html=$(curl -Ls "$url")

# Extract the highest two-digit number
highest_version=$(echo "$html" | grep -oE '[0-9]{2}/' | sed 's#/##' | sort -n | tail -1)

# Set the environment variable
export VERSION=$highest_version
echo "VERSION=$VERSION"

Explanation:

  • curl -Ls fetches the HTML content of the page.
  • grep -oE '[0-9]{2}/' extracts all two-digit numbers followed by a slash.
  • sed 's#/##' removes the trailing slash.
  • sort -n sorts the numbers numerically.
  • tail -1 gets the highest number.
  • The result is stored in VERSION.
1 Like
curl -s -L https://fedoraproject.org/releases.json \
| jq -r '[.[].version|select(test("^[0-9]+$"))]|max'
5 Likes

Thanks! It works!

Does this require bash? On fish I got strange errors.

1 Like

Really elegant. Lets see how I use it!