Fix disk encryption emnu (#3506)
This commit is contained in:
parent
6c7260fa33
commit
8c12d15a41
|
|
@ -78,7 +78,7 @@ class DiskLayoutConfigurationMenu(AbstractSubMenu[DiskLayoutConfiguration]):
|
|||
),
|
||||
MenuItem(
|
||||
text=tr('Disk encryption'),
|
||||
action=self._disk_encryption,
|
||||
action=self._select_disk_encryption,
|
||||
preview_action=self._prev_disk_encryption,
|
||||
dependencies=['disk_config'],
|
||||
key='disk_encryption',
|
||||
|
|
@ -121,17 +121,20 @@ class DiskLayoutConfigurationMenu(AbstractSubMenu[DiskLayoutConfiguration]):
|
|||
|
||||
return False
|
||||
|
||||
def _disk_encryption(self, preset: DiskEncryption | None) -> DiskEncryption | None:
|
||||
def _select_disk_encryption(self, preset: DiskEncryption | None) -> DiskEncryption | None:
|
||||
disk_config: DiskLayoutConfiguration | None = self._item_group.find_by_key('disk_config').value
|
||||
lvm_config: LvmConfiguration | None = self._item_group.find_by_key('lvm_config').value
|
||||
|
||||
if not disk_config:
|
||||
# this should not happen as the encryption menu has the disk_config as dependency
|
||||
raise ValueError('No disk layout specified')
|
||||
return preset
|
||||
|
||||
if not DiskEncryption.validate_enc(disk_config):
|
||||
modifications = disk_config.device_modifications
|
||||
|
||||
if not DiskEncryption.validate_enc(modifications, lvm_config):
|
||||
return None
|
||||
|
||||
disk_encryption = DiskEncryptionMenu(disk_config, preset=preset).run()
|
||||
disk_encryption = DiskEncryptionMenu(modifications, lvm_config=lvm_config, preset=preset).run()
|
||||
|
||||
return disk_encryption
|
||||
|
||||
def _select_disk_layout_config(self, preset: DiskLayoutConfiguration | None) -> DiskLayoutConfiguration | None:
|
||||
|
|
@ -146,10 +149,15 @@ class DiskLayoutConfigurationMenu(AbstractSubMenu[DiskLayoutConfiguration]):
|
|||
def _select_lvm_config(self, preset: LvmConfiguration | None) -> LvmConfiguration | None:
|
||||
disk_config: DiskLayoutConfiguration | None = self._item_group.find_by_key('disk_config').value
|
||||
|
||||
if disk_config:
|
||||
return select_lvm_config(disk_config, preset=preset)
|
||||
if not disk_config:
|
||||
return preset
|
||||
|
||||
return preset
|
||||
lvm_config = select_lvm_config(disk_config, preset=preset)
|
||||
|
||||
if lvm_config != preset:
|
||||
self._menu_item_group.find_by_key('disk_encryption').value = None
|
||||
|
||||
return lvm_config
|
||||
|
||||
def _select_btrfs_snapshots(self, preset: SnapshotConfig | None) -> SnapshotConfig | None:
|
||||
preset_type = preset.snapshot_type if preset else None
|
||||
|
|
@ -250,7 +258,7 @@ class DiskLayoutConfigurationMenu(AbstractSubMenu[DiskLayoutConfiguration]):
|
|||
disk_config: DiskLayoutConfiguration | None = self._item_group.find_by_key('disk_config').value
|
||||
enc_config: DiskEncryption | None = item.value
|
||||
|
||||
if disk_config and not DiskEncryption.validate_enc(disk_config):
|
||||
if disk_config and not DiskEncryption.validate_enc(disk_config.device_modifications, disk_config.lvm_config):
|
||||
return tr('LVM disk encryption with more than 2 partitions is currently not supported')
|
||||
|
||||
if enc_config:
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ from archinstall.lib.menu.menu_helper import MenuHelper
|
|||
from archinstall.lib.models.device_model import (
|
||||
DeviceModification,
|
||||
DiskEncryption,
|
||||
DiskLayoutConfiguration,
|
||||
EncryptionType,
|
||||
LvmConfiguration,
|
||||
LvmVolume,
|
||||
|
|
@ -28,7 +27,8 @@ from .fido import Fido2
|
|||
class DiskEncryptionMenu(AbstractSubMenu[DiskEncryption]):
|
||||
def __init__(
|
||||
self,
|
||||
disk_config: DiskLayoutConfiguration,
|
||||
device_modifications: list[DeviceModification],
|
||||
lvm_config: LvmConfiguration | None = None,
|
||||
preset: DiskEncryption | None = None,
|
||||
):
|
||||
if preset:
|
||||
|
|
@ -36,7 +36,8 @@ class DiskEncryptionMenu(AbstractSubMenu[DiskEncryption]):
|
|||
else:
|
||||
self._enc_config = DiskEncryption()
|
||||
|
||||
self._disk_config = disk_config
|
||||
self._device_modifications = device_modifications
|
||||
self._lvm_config = lvm_config
|
||||
|
||||
menu_optioons = self._define_menu_options()
|
||||
self._item_group = MenuItemGroup(menu_optioons, sort_items=False, checkmarks=True)
|
||||
|
|
@ -51,7 +52,7 @@ class DiskEncryptionMenu(AbstractSubMenu[DiskEncryption]):
|
|||
return [
|
||||
MenuItem(
|
||||
text=tr('Encryption type'),
|
||||
action=lambda x: select_encryption_type(self._disk_config, x),
|
||||
action=lambda x: select_encryption_type(self._device_modifications, self._lvm_config, x),
|
||||
value=self._enc_config.encryption_type,
|
||||
preview_action=self._preview,
|
||||
key='encryption_type',
|
||||
|
|
@ -66,7 +67,7 @@ class DiskEncryptionMenu(AbstractSubMenu[DiskEncryption]):
|
|||
),
|
||||
MenuItem(
|
||||
text=tr('Partitions'),
|
||||
action=lambda x: select_partitions_to_encrypt(self._disk_config.device_modifications, x),
|
||||
action=lambda x: select_partitions_to_encrypt(self._device_modifications, x),
|
||||
value=self._enc_config.partitions,
|
||||
dependencies=[self._check_dep_partitions],
|
||||
preview_action=self._preview,
|
||||
|
|
@ -91,8 +92,8 @@ class DiskEncryptionMenu(AbstractSubMenu[DiskEncryption]):
|
|||
]
|
||||
|
||||
def _select_lvm_vols(self, preset: list[LvmVolume]) -> list[LvmVolume]:
|
||||
if self._disk_config.lvm_config:
|
||||
return select_lvm_vols_to_encrypt(self._disk_config.lvm_config, preset=preset)
|
||||
if self._lvm_config:
|
||||
return select_lvm_vols_to_encrypt(self._lvm_config, preset=preset)
|
||||
return []
|
||||
|
||||
def _check_dep_enc_type(self) -> bool:
|
||||
|
|
@ -214,15 +215,23 @@ class DiskEncryptionMenu(AbstractSubMenu[DiskEncryption]):
|
|||
return f'{tr("HSM device")}: {output}'
|
||||
|
||||
|
||||
def select_encryption_type(disk_config: DiskLayoutConfiguration, preset: EncryptionType) -> EncryptionType | None:
|
||||
def select_encryption_type(
|
||||
device_modifications: list[DeviceModification],
|
||||
lvm_config: LvmConfiguration | None = None,
|
||||
preset: EncryptionType | None = None,
|
||||
) -> EncryptionType | None:
|
||||
options: list[EncryptionType] = []
|
||||
preset_value = EncryptionType.type_to_text(preset)
|
||||
|
||||
if disk_config.lvm_config:
|
||||
if lvm_config:
|
||||
options = [EncryptionType.LvmOnLuks, EncryptionType.LuksOnLvm]
|
||||
else:
|
||||
options = [EncryptionType.Luks]
|
||||
|
||||
if not preset:
|
||||
preset = options[0]
|
||||
|
||||
preset_value = EncryptionType.type_to_text(preset)
|
||||
|
||||
items = [MenuItem(EncryptionType.type_to_text(o), value=o) for o in options]
|
||||
group = MenuItemGroup(items)
|
||||
group.set_focus_by_value(preset_value)
|
||||
|
|
|
|||
|
|
@ -312,15 +312,15 @@ class GlobalMenu(AbstractMenu[None]):
|
|||
output += tr('Mountpoint') + ': ' + str(disk_layout_conf.mountpoint)
|
||||
|
||||
if disk_layout_conf.lvm_config:
|
||||
output += '{}: {}'.format(tr('LVM configuration type'), disk_layout_conf.lvm_config.config_type.display_msg())
|
||||
output += '{}: {}'.format(tr('LVM configuration type'), disk_layout_conf.lvm_config.config_type.display_msg()) + '\n'
|
||||
|
||||
if disk_layout_conf.disk_encryption:
|
||||
output += tr('Disk encryption') + ': ' + EncryptionType.type_to_text(disk_layout_conf.disk_encryption.encryption_type)
|
||||
output += tr('Disk encryption') + ': ' + EncryptionType.type_to_text(disk_layout_conf.disk_encryption.encryption_type) + '\n'
|
||||
|
||||
if disk_layout_conf.btrfs_options:
|
||||
btrfs_options = disk_layout_conf.btrfs_options
|
||||
if btrfs_options.snapshot_config:
|
||||
output += tr('Btrfs snapshot type: {}').format(btrfs_options.snapshot_config.snapshot_type.value)
|
||||
output += tr('Btrfs snapshot type: {}').format(btrfs_options.snapshot_config.snapshot_type.value) + '\n'
|
||||
|
||||
return output
|
||||
|
||||
|
|
|
|||
|
|
@ -1505,15 +1505,19 @@ class DiskEncryption:
|
|||
return obj
|
||||
|
||||
@classmethod
|
||||
def validate_enc(cls, disk_config: DiskLayoutConfiguration) -> bool:
|
||||
def validate_enc(
|
||||
cls,
|
||||
modifications: list[DeviceModification],
|
||||
lvm_config: LvmConfiguration | None = None,
|
||||
) -> bool:
|
||||
partitions = []
|
||||
|
||||
for mod in disk_config.device_modifications:
|
||||
for mod in modifications:
|
||||
for part in mod.partitions:
|
||||
partitions.append(part)
|
||||
|
||||
if len(partitions) > 2: # assume one boot and at least 2 additional
|
||||
if disk_config.lvm_config:
|
||||
if lvm_config:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
|
@ -1525,7 +1529,7 @@ class DiskEncryption:
|
|||
disk_encryption: _DiskEncryptionSerialization,
|
||||
password: Password | None = None,
|
||||
) -> 'DiskEncryption | None':
|
||||
if not cls.validate_enc(disk_config):
|
||||
if not cls.validate_enc(disk_config.device_modifications, disk_config.lvm_config):
|
||||
return None
|
||||
|
||||
if not password:
|
||||
|
|
|
|||
Loading…
Reference in New Issue