summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlejandro Sirgo Rica <asirgo@soleta.eu>2024-03-04 11:13:46 +0100
committerAlejandro Sirgo Rica <asirgo@soleta.eu>2024-03-04 11:33:10 +0100
commit8e8ed280f962d32354dee3713388f86c569c5104 (patch)
treed0056db64e9c1983133a807f4e58eb2107442ed0 /src
parent66941e9f7956452d5d63bd87c8dbeb7d307924f3 (diff)
uefi: define EFIBOOTMGR_BIN to ease changing the efibootmgr binary
The json functionality proposed upstream might be merged one day in efibootmgr so deploying a fork would not be needed anymore. This change aims to ease the migration once that day comes.
Diffstat (limited to 'src')
-rw-r--r--src/utils/uefi.py20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/utils/uefi.py b/src/utils/uefi.py
index e0c41d1..fc78d40 100644
--- a/src/utils/uefi.py
+++ b/src/utils/uefi.py
@@ -14,6 +14,8 @@ import subprocess
import fdisk
+EFIBOOTMGR_BIN='efibootmgr-json'
+
def _find_bootentry(entries, label):
for entry in entries:
if entry['description'] == label:
@@ -37,7 +39,7 @@ def _check_efibootmgr_json():
"""
supported = True
try:
- subprocess.run(['efibootmgr-json', '--json'], stdout=subprocess.DEVNULL,
+ subprocess.run([EFIBOOTMGR_BIN, '--json'], stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL, check=True)
except subprocess.CalledProcessError:
supported = False
@@ -50,9 +52,9 @@ def is_uefi_supported():
def run_efibootmgr_json():
if _check_efibootmgr_json() is False:
- raise RuntimeError('efibootmgr-json not available')
+ raise RuntimeError(f'{EFIBOOTMGR_BIN} not available')
- proc = subprocess.run(['efibootmgr-json', '--json'], capture_output=True, text=True)
+ proc = subprocess.run([EFIBOOTMGR_BIN, '--json'], capture_output=True, text=True)
dict_json = json.loads(proc.stdout)
return dict_json
@@ -60,24 +62,24 @@ def run_efibootmgr_json():
def efibootmgr_bootnext(description):
logging.info(f'Setting BootNext to value from boot entry with label {description}')
- bootnext_cmd = 'efibootmgr-json -n {bootnum}'
+ bootnext_cmd = '{efibootmgr} -n {bootnum}'
boot_entries = run_efibootmgr_json().get('vars', [])
entry = _find_bootentry(boot_entries, description)
num = _strip_boot_prefix(entry) # efibootmgr output uses BootXXXX for each entry, remove the "Boot" prefix.
- bootnext_cmd = bootnext_cmd.format(bootnum=num)
+ bootnext_cmd = bootnext_cmd.format(bootnum=num, efibootmgr=EFIBOOTMGR_BIN)
subprocess.run(shlex.split(bootnext_cmd), check=True,
stdout=subprocess.DEVNULL)
def efibootmgr_delete_bootentry(label):
dict_json = run_efibootmgr_json()
- efibootmgr_cmd = 'efibootmgr-json -q -b {bootnum} -B'
+ efibootmgr_cmd = '{efibootmgr} -q -b {bootnum} -B'
for entry in dict_json.get('vars', []):
if entry['description'] == label:
num = entry['name'][4:] # Remove "Boot" prefix to extract num
- efibootmgr_cmd = efibootmgr_cmd.format(bootnum=num)
+ efibootmgr_cmd = efibootmgr_cmd.format(bootnum=num, efibootmgr=EFIBOOTMGR_BIN)
subprocess.run(shlex.split(efibootmgr_cmd), check=True)
break
else:
@@ -88,8 +90,8 @@ def efibootmgr_create_bootentry(disk, part, loader, label, add_to_bootorder=True
entries = run_efibootmgr_json().get('vars', [])
create_opt = '-c' if add_to_bootorder else '-C'
index_opt = f'-I {len(entries)}' # Requires efibootmgr version 18
- efibootmgr_cmd = f'efibootmgr-json {create_opt} {index_opt} -d {disk} -p {part} -L {label} -l {loader}'
- logging.info(f'efibootmgr-json command creating boot entry: {efibootmgr_cmd}')
+ efibootmgr_cmd = f'{EFIBOOTMGR_BIN} {create_opt} {index_opt} -d {disk} -p {part} -L {label} -l {loader}'
+ logging.info(f'{EFIBOOTMGR_BIN} command creating boot entry: {efibootmgr_cmd}')
try:
proc = subprocess.run(shlex.split(efibootmgr_cmd), check=True, text=True)
except subprocess.CalledProcessError as e: