aboutsummaryrefslogtreecommitdiff
path: root/tools/cru-py/cru/system.py
blob: 4c9de01cfefab8bb4e4f272661574cd9f44d4007 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import os.path
import re


def check_debian_derivative_version(name: str) -> None | str:
    if not os.path.isfile("/etc/os-release"):
        return None
    with open("/etc/os-release", "r") as f:
        content = f.read()
        if not f"ID={name}" in content:
            return None
        m = re.search(r'VERSION_ID="(.+)"', content)
        if m is None: return None
        return m.group(1)


def check_ubuntu_version() -> None | str:
    return check_debian_derivative_version("ubuntu")


def check_debian_version() -> None | str:
    return check_debian_derivative_version("debian")