2023-09-19 12:12:10 +00:00
|
|
|
#!/usr/bin/env nix-shell
|
linux: ignore kernel branches older than min supported branch
Right now, hashes for 4.14 are kept (and thus also maintained by the
hardened updater) even though we don't support that anymore, the oldest
supported branch is 4.19.
To avoid having to remember too many places where to drop a kernel when
dropping an old one (next will be 4.19), the oldest kernel branch will
be determined by the lowest version number in the keys of
`kernels-org.json`. That way, it's sufficient to drop an old branch
from this file and it will be ignored on the upcoming update runs.
Yes, the code to read from that file is duplicated, but I'd expect the
min version to change way more often than 3 lines of code reading a
version from a JSON file[1].
The logic is fairly simple though: if the branch (i.e. MAJOR.MINOR) of a
kernel that's listed on kernel.org[2] is older than the oldest version
in `kernels-org.json`, it's omitted on update and a message is printed
like this:
[...]
linux_5_4: 5.4.265 is latest, skipping...
linux_4_19: 4.19.303 is latest, skipping...
4.14 is too old and not supported anymore, skipping...
Kernels that have the branch `testing` are excluded from that check and
always allowed.
[1] Also, I'm unhappy already that I can't just do a relative import in
here to deduplicate the function and for 3 lines of code it seems
like unnecessarily much effort to create a python package structure
here.
[2] Kernels that got unlisted there are too old to be added/kept here
anyways.
2023-12-30 10:40:59 +00:00
|
|
|
#!nix-shell -i python3 -p "python3.withPackages (ps: [ ps.beautifulsoup4 ps.lxml ps.packaging ])"
|
2023-09-19 12:12:10 +00:00
|
|
|
import json
|
2023-09-22 13:10:21 +00:00
|
|
|
import os
|
2023-09-19 12:12:10 +00:00
|
|
|
import pathlib
|
|
|
|
import subprocess
|
|
|
|
import sys
|
2023-09-22 13:10:21 +00:00
|
|
|
import urllib.request
|
|
|
|
from dataclasses import dataclass
|
|
|
|
from enum import Enum
|
2023-09-19 12:12:10 +00:00
|
|
|
|
2023-09-22 13:10:21 +00:00
|
|
|
from bs4 import BeautifulSoup, NavigableString, Tag
|
linux: ignore kernel branches older than min supported branch
Right now, hashes for 4.14 are kept (and thus also maintained by the
hardened updater) even though we don't support that anymore, the oldest
supported branch is 4.19.
To avoid having to remember too many places where to drop a kernel when
dropping an old one (next will be 4.19), the oldest kernel branch will
be determined by the lowest version number in the keys of
`kernels-org.json`. That way, it's sufficient to drop an old branch
from this file and it will be ignored on the upcoming update runs.
Yes, the code to read from that file is duplicated, but I'd expect the
min version to change way more often than 3 lines of code reading a
version from a JSON file[1].
The logic is fairly simple though: if the branch (i.e. MAJOR.MINOR) of a
kernel that's listed on kernel.org[2] is older than the oldest version
in `kernels-org.json`, it's omitted on update and a message is printed
like this:
[...]
linux_5_4: 5.4.265 is latest, skipping...
linux_4_19: 4.19.303 is latest, skipping...
4.14 is too old and not supported anymore, skipping...
Kernels that have the branch `testing` are excluded from that check and
always allowed.
[1] Also, I'm unhappy already that I can't just do a relative import in
here to deduplicate the function and for 3 lines of code it seems
like unnecessarily much effort to create a python package structure
here.
[2] Kernels that got unlisted there are too old to be added/kept here
anyways.
2023-12-30 10:40:59 +00:00
|
|
|
from packaging.version import parse as parse_version, Version
|
|
|
|
from typing import List
|
2023-09-19 12:12:10 +00:00
|
|
|
|
|
|
|
HERE = pathlib.Path(__file__).parent
|
|
|
|
ROOT = HERE.parent.parent.parent.parent
|
|
|
|
VERSIONS_FILE = HERE / "kernels-org.json"
|
|
|
|
|
2023-09-22 13:10:21 +00:00
|
|
|
|
2023-09-19 12:12:10 +00:00
|
|
|
class KernelNature(Enum):
|
|
|
|
MAINLINE = 1
|
|
|
|
STABLE = 2
|
|
|
|
LONGTERM = 3
|
|
|
|
|
2023-09-22 13:10:21 +00:00
|
|
|
|
2023-09-19 12:12:10 +00:00
|
|
|
@dataclass
|
|
|
|
class KernelRelease:
|
|
|
|
nature: KernelNature
|
|
|
|
version: str
|
2023-09-22 11:28:05 +00:00
|
|
|
branch: str
|
2023-09-19 12:12:10 +00:00
|
|
|
date: str
|
|
|
|
link: str
|
|
|
|
eol: bool = False
|
|
|
|
|
2023-09-22 13:10:21 +00:00
|
|
|
|
2023-09-19 12:12:10 +00:00
|
|
|
def parse_release(release: Tag) -> KernelRelease | None:
|
2023-09-22 13:10:21 +00:00
|
|
|
columns: list[Tag] = list(release.find_all("td"))
|
2023-09-19 12:12:10 +00:00
|
|
|
try:
|
2023-09-22 13:10:21 +00:00
|
|
|
nature = KernelNature[columns[0].get_text().rstrip(":").upper()]
|
2023-09-19 12:12:10 +00:00
|
|
|
except KeyError:
|
|
|
|
return None
|
|
|
|
|
2023-09-22 13:10:21 +00:00
|
|
|
version = columns[1].get_text().rstrip(" [EOL]")
|
2023-09-19 12:12:10 +00:00
|
|
|
date = columns[2].get_text()
|
2023-09-22 13:10:21 +00:00
|
|
|
link = columns[3].find("a")
|
2023-09-19 12:12:10 +00:00
|
|
|
if link is not None and isinstance(link, Tag):
|
2023-09-22 13:10:21 +00:00
|
|
|
link = link.attrs.get("href")
|
|
|
|
assert link is not None, f"link for kernel {version} is non-existent"
|
|
|
|
eol = bool(release.find(class_="eolkernel"))
|
2023-09-19 12:12:10 +00:00
|
|
|
|
2023-09-22 11:28:05 +00:00
|
|
|
return KernelRelease(
|
|
|
|
nature=nature,
|
|
|
|
branch=get_branch(version),
|
|
|
|
version=version,
|
|
|
|
date=date,
|
|
|
|
link=link,
|
|
|
|
eol=eol,
|
|
|
|
)
|
2023-09-19 12:12:10 +00:00
|
|
|
|
2023-09-22 13:10:21 +00:00
|
|
|
|
2023-09-19 12:12:10 +00:00
|
|
|
def get_branch(version: str):
|
|
|
|
# This is a testing kernel.
|
2023-09-22 13:10:21 +00:00
|
|
|
if "rc" in version:
|
|
|
|
return "testing"
|
2023-09-19 12:12:10 +00:00
|
|
|
else:
|
|
|
|
major, minor, *_ = version.split(".")
|
|
|
|
return f"{major}.{minor}"
|
|
|
|
|
2023-09-22 13:10:21 +00:00
|
|
|
|
2023-09-22 11:28:05 +00:00
|
|
|
def get_hash(kernel: KernelRelease):
|
|
|
|
if kernel.branch == "testing":
|
|
|
|
args = ["--unpack"]
|
|
|
|
else:
|
|
|
|
args = []
|
2023-09-19 12:12:10 +00:00
|
|
|
|
2023-09-22 11:28:05 +00:00
|
|
|
hash = (
|
|
|
|
subprocess.check_output(["nix-prefetch-url", kernel.link] + args)
|
|
|
|
.decode()
|
|
|
|
.strip()
|
|
|
|
)
|
|
|
|
return f"sha256:{hash}"
|
2023-09-19 12:12:10 +00:00
|
|
|
|
|
|
|
|
linux: ignore kernel branches older than min supported branch
Right now, hashes for 4.14 are kept (and thus also maintained by the
hardened updater) even though we don't support that anymore, the oldest
supported branch is 4.19.
To avoid having to remember too many places where to drop a kernel when
dropping an old one (next will be 4.19), the oldest kernel branch will
be determined by the lowest version number in the keys of
`kernels-org.json`. That way, it's sufficient to drop an old branch
from this file and it will be ignored on the upcoming update runs.
Yes, the code to read from that file is duplicated, but I'd expect the
min version to change way more often than 3 lines of code reading a
version from a JSON file[1].
The logic is fairly simple though: if the branch (i.e. MAJOR.MINOR) of a
kernel that's listed on kernel.org[2] is older than the oldest version
in `kernels-org.json`, it's omitted on update and a message is printed
like this:
[...]
linux_5_4: 5.4.265 is latest, skipping...
linux_4_19: 4.19.303 is latest, skipping...
4.14 is too old and not supported anymore, skipping...
Kernels that have the branch `testing` are excluded from that check and
always allowed.
[1] Also, I'm unhappy already that I can't just do a relative import in
here to deduplicate the function and for 3 lines of code it seems
like unnecessarily much effort to create a python package structure
here.
[2] Kernels that got unlisted there are too old to be added/kept here
anyways.
2023-12-30 10:40:59 +00:00
|
|
|
def get_oldest_branch() -> Version:
|
|
|
|
with open(VERSIONS_FILE) as f:
|
|
|
|
return parse_version(sorted(json.load(f).keys())[0])
|
|
|
|
|
|
|
|
|
|
|
|
def predates_oldest_branch(oldest: Version, to_compare: str) -> bool:
|
|
|
|
if to_compare == "testing":
|
|
|
|
return False
|
|
|
|
|
|
|
|
return parse_version(to_compare) < oldest
|
|
|
|
|
|
|
|
|
2023-09-19 12:12:10 +00:00
|
|
|
def commit(message):
|
|
|
|
return subprocess.check_call(["git", "commit", "-m", message, VERSIONS_FILE])
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
kernel_org = urllib.request.urlopen("https://kernel.org/")
|
|
|
|
soup = BeautifulSoup(kernel_org.read().decode(), "lxml")
|
2023-09-22 13:10:21 +00:00
|
|
|
release_table = soup.find(id="releases")
|
2023-09-19 12:12:10 +00:00
|
|
|
if not release_table or isinstance(release_table, NavigableString):
|
2023-10-02 11:43:18 +00:00
|
|
|
print(release_table, file=sys.stderr)
|
|
|
|
print("Failed to find the release table on https://kernel.org", file=sys.stderr)
|
2023-09-19 12:12:10 +00:00
|
|
|
sys.exit(1)
|
|
|
|
|
2023-09-22 13:10:21 +00:00
|
|
|
releases = release_table.find_all("tr")
|
2023-09-19 12:12:10 +00:00
|
|
|
parsed_releases = filter(None, [parse_release(release) for release in releases])
|
|
|
|
all_kernels = json.load(VERSIONS_FILE.open())
|
|
|
|
|
linux: ignore kernel branches older than min supported branch
Right now, hashes for 4.14 are kept (and thus also maintained by the
hardened updater) even though we don't support that anymore, the oldest
supported branch is 4.19.
To avoid having to remember too many places where to drop a kernel when
dropping an old one (next will be 4.19), the oldest kernel branch will
be determined by the lowest version number in the keys of
`kernels-org.json`. That way, it's sufficient to drop an old branch
from this file and it will be ignored on the upcoming update runs.
Yes, the code to read from that file is duplicated, but I'd expect the
min version to change way more often than 3 lines of code reading a
version from a JSON file[1].
The logic is fairly simple though: if the branch (i.e. MAJOR.MINOR) of a
kernel that's listed on kernel.org[2] is older than the oldest version
in `kernels-org.json`, it's omitted on update and a message is printed
like this:
[...]
linux_5_4: 5.4.265 is latest, skipping...
linux_4_19: 4.19.303 is latest, skipping...
4.14 is too old and not supported anymore, skipping...
Kernels that have the branch `testing` are excluded from that check and
always allowed.
[1] Also, I'm unhappy already that I can't just do a relative import in
here to deduplicate the function and for 3 lines of code it seems
like unnecessarily much effort to create a python package structure
here.
[2] Kernels that got unlisted there are too old to be added/kept here
anyways.
2023-12-30 10:40:59 +00:00
|
|
|
oldest_branch = get_oldest_branch()
|
|
|
|
|
2023-09-19 12:12:10 +00:00
|
|
|
for kernel in parsed_releases:
|
|
|
|
branch = get_branch(kernel.version)
|
2023-09-22 13:10:21 +00:00
|
|
|
nixpkgs_branch = branch.replace(".", "_")
|
2023-09-19 12:12:10 +00:00
|
|
|
|
|
|
|
old_version = all_kernels.get(branch, {}).get("version")
|
|
|
|
if old_version == kernel.version:
|
|
|
|
print(f"linux_{nixpkgs_branch}: {kernel.version} is latest, skipping...")
|
|
|
|
continue
|
|
|
|
|
linux: ignore kernel branches older than min supported branch
Right now, hashes for 4.14 are kept (and thus also maintained by the
hardened updater) even though we don't support that anymore, the oldest
supported branch is 4.19.
To avoid having to remember too many places where to drop a kernel when
dropping an old one (next will be 4.19), the oldest kernel branch will
be determined by the lowest version number in the keys of
`kernels-org.json`. That way, it's sufficient to drop an old branch
from this file and it will be ignored on the upcoming update runs.
Yes, the code to read from that file is duplicated, but I'd expect the
min version to change way more often than 3 lines of code reading a
version from a JSON file[1].
The logic is fairly simple though: if the branch (i.e. MAJOR.MINOR) of a
kernel that's listed on kernel.org[2] is older than the oldest version
in `kernels-org.json`, it's omitted on update and a message is printed
like this:
[...]
linux_5_4: 5.4.265 is latest, skipping...
linux_4_19: 4.19.303 is latest, skipping...
4.14 is too old and not supported anymore, skipping...
Kernels that have the branch `testing` are excluded from that check and
always allowed.
[1] Also, I'm unhappy already that I can't just do a relative import in
here to deduplicate the function and for 3 lines of code it seems
like unnecessarily much effort to create a python package structure
here.
[2] Kernels that got unlisted there are too old to be added/kept here
anyways.
2023-12-30 10:40:59 +00:00
|
|
|
if predates_oldest_branch(oldest_branch, kernel.branch):
|
|
|
|
print(
|
|
|
|
f"{kernel.branch} is too old and not supported anymore, skipping...",
|
|
|
|
file=sys.stderr
|
|
|
|
)
|
|
|
|
continue
|
|
|
|
|
2023-09-19 12:12:10 +00:00
|
|
|
if old_version is None:
|
2024-04-10 15:09:49 +00:00
|
|
|
if kernel.eol:
|
|
|
|
print(
|
|
|
|
f"{kernel.branch} is EOL, not adding...",
|
|
|
|
file=sys.stderr
|
|
|
|
)
|
|
|
|
continue
|
|
|
|
|
2023-09-19 12:12:10 +00:00
|
|
|
message = f"linux_{nixpkgs_branch}: init at {kernel.version}"
|
|
|
|
else:
|
|
|
|
message = f"linux_{nixpkgs_branch}: {old_version} -> {kernel.version}"
|
|
|
|
|
2023-10-02 11:43:18 +00:00
|
|
|
print(message, file=sys.stderr)
|
2023-09-19 12:12:10 +00:00
|
|
|
|
2023-09-22 11:28:05 +00:00
|
|
|
all_kernels[branch] = {
|
|
|
|
"version": kernel.version,
|
|
|
|
"hash": get_hash(kernel),
|
|
|
|
}
|
2023-09-19 12:12:10 +00:00
|
|
|
|
|
|
|
with VERSIONS_FILE.open("w") as fd:
|
|
|
|
json.dump(all_kernels, fd, indent=4)
|
|
|
|
fd.write("\n") # makes editorconfig happy
|
|
|
|
|
2023-09-22 11:28:05 +00:00
|
|
|
if os.environ.get("COMMIT") == "1":
|
|
|
|
commit(message)
|
2023-09-19 12:12:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|