Support Ubuntu 22.04 (agent and server on Python 3.10)

The server only needed Python 3.11 for tomllib. Fall back to a small
parser for the flat key = value subset the config uses, checked against
tomllib on the shipped example. Relax the installer's version check to
3.10 and list Ubuntu 22.04 as supported for agents and server.

Add status tests using uname -v / package versions captured from real
22.04.5 and 24.04.4 HWE hosts, confirming the Ubuntu build mapping.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
patrickandClaude Opus 5.5 committed 2026-10-17 10:23:00 -04:00
1 parent 48f2d155af
commit 16d647cf9c
7 files changed
+92 -9

No files matched your search

+2 -2
View File
@@ -11,8 +11,8 @@ set -euo pipefail
here=$(cd "$(dirname "$0")" && pwd)
[[ $(id -u) == 0 ]] || { echo "run as root" >&2; exit 1; }
if ! /usr/bin/python3 -c 'import sys; sys.exit(sys.version_info < (3, 11))' 2>/dev/null; then
echo "kernelwatch needs /usr/bin/python3 >= 3.11 (Debian 12+, Ubuntu 24.04)" >&2
if ! /usr/bin/python3 -c 'import sys; sys.exit(sys.version_info < (3, 10))' 2>/dev/null; then
echo "kernelwatch needs /usr/bin/python3 >= 3.10 (Debian 12+, Ubuntu 22.04+)" >&2
exit 1
fi
+1 -1
View File
@@ -1,5 +1,5 @@
#!/usr/bin/python3 -I
"""Entry point. Runs from a checkout or /opt/kernelwatch with the system python3 (3.11+)."""
"""Entry point. Runs from a checkout or /opt/kernelwatch with the system python3 (3.10+)."""
import os
import sys
+51 -2
View File
@@ -4,8 +4,14 @@ from __future__ import annotations
import dataclasses
import os
import tomllib
import re
from dataclasses import dataclass
from typing import Any
try:
import tomllib
except ModuleNotFoundError: # Python 3.10 (Ubuntu 22.04): see _parse_flat_toml
tomllib = None
DEFAULT_PATH = "/etc/kernelwatch/server.toml"
@@ -38,7 +44,8 @@ def load(path: str | None = None) -> Config:
raise SystemExit(f"config file not found: {path}")
with open(path, "rb") as f:
raw = tomllib.load(f)
data = f.read()
raw = tomllib.loads(data.decode()) if tomllib else _parse_flat_toml(data.decode(), path)
fields = {f.name: f for f in dataclasses.fields(Config)}
unknown = sorted(set(raw) - set(fields))
@@ -54,3 +61,45 @@ def load(path: str | None = None) -> Config:
raise SystemExit(f"{path}: {name} must be {expected.__name__}")
values[name] = value
return Config(**values)
_KEY_VALUE = re.compile(r"^([A-Za-z0-9_-]+)\s*=\s*(.*)$")
def _parse_flat_toml(text: str, path: str) -> dict[str, Any]:
"""The subset of TOML the config uses (top-level `key = value` with strings,
booleans, integers and floats), for Pythons without tomllib."""
out: dict[str, Any] = {}
for lineno, line in enumerate(text.splitlines(), 1):
line = line.strip()
if not line or line.startswith("#"):
continue
m = _KEY_VALUE.match(line)
if not m:
raise SystemExit(f"{path}:{lineno}: expected `key = value`")
key, value = m.groups()
if key in out:
raise SystemExit(f"{path}:{lineno}: duplicate key {key}")
out[key] = _parse_flat_value(value, f"{path}:{lineno}")
return out
def _parse_flat_value(value: str, where: str) -> Any:
if value[:1] in ('"', "'"):
end = value.find(value[0], 1)
rest = value[end + 1:].strip() if end > 0 else ""
if end < 0 or (rest and not rest.startswith("#")):
raise SystemExit(f"{where}: bad string")
s = value[1:end]
if value[0] == '"' and "\\" in s:
raise SystemExit(f"{where}: escapes aren't supported; use a 'literal string'")
return s
value = value.split("#", 1)[0].strip()
if value in ("true", "false"):
return value == "true"
for conv in (int, float):
try:
return conv(value.replace("_", ""))
except ValueError:
pass
raise SystemExit(f"{where}: unsupported value {value!r}")