mirror of https://git.48k.eu/ogclient
utils: implement linux distro id detection
The OS probe logic must be able to check a distro programmatically, add get_linux_distro_id to return an id whitout versioning. Ensure the availability of 'ubuntu' when we need to ensure certain features are only used with a supported system.master
parent
4d4171e459
commit
f5501aac91
|
@ -12,7 +12,7 @@ import os
|
|||
import shlex
|
||||
import subprocess
|
||||
|
||||
from src.utils.probe import OSFamily, get_os_family
|
||||
from src.utils.probe import OSFamily, get_os_family, get_linux_distro_id, os_probe
|
||||
from src.utils.disk import get_partition_device, get_efi_partition
|
||||
from src.utils.uefi import *
|
||||
from src.utils.fs import *
|
||||
|
@ -23,6 +23,10 @@ def _boot_bios_legacy(disk, part, mountpoint):
|
|||
|
||||
def _boot_bios_linux(disk, part, mountpoint):
|
||||
logging.info(f'Booting Linux system')
|
||||
|
||||
if not get_linux_distro_id(mountpoint) == 'ubuntu':
|
||||
raise NotImplementedError(f'{os_probe(mountpoint)} detected, only Ubuntu is supported for legacy BIOS boot')
|
||||
|
||||
_boot_bios_legacy(disk, part, mountpoint)
|
||||
|
||||
def _boot_bios_windows(disk, part, mountpoint):
|
||||
|
|
|
@ -112,6 +112,28 @@ def linux_is64bit(mountpoint):
|
|||
return True if bits == '64bit' else False
|
||||
return os.path.exists(lib64_path)
|
||||
|
||||
def get_linux_distro_id(mountpoint):
|
||||
"""
|
||||
Parses a os-release file and fetches the 'ID' key.
|
||||
Check repository documentation at ./ogclient/os-release-ids.txt
|
||||
for a list of the potential strings it might return.
|
||||
If file or key are not found, then returns generic 'linux' string.
|
||||
"""
|
||||
osrelease = f'{mountpoint}/etc/os-release'
|
||||
|
||||
try:
|
||||
with open(osrelease, 'r') as f:
|
||||
for line in f:
|
||||
if line.find('=') == -1:
|
||||
continue
|
||||
key, value = line.split('=')
|
||||
if key == 'ID':
|
||||
value = value.replace('\n', '')
|
||||
value = value.strip('"')
|
||||
return value
|
||||
except FileNotFoundError as e:
|
||||
logging.error(f'os-release file not found at "{osrelease}"')
|
||||
return 'linux'
|
||||
|
||||
def cache_probe():
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue