From 9f0d25bce302459efa5ab5b9eaf22bb1f1feb575 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Tue, 9 Mar 2021 11:48:40 +0100 Subject: Added functions to auto-detect filesystems inside encrypted partitions (given a password) --- archinstall/lib/luks.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'archinstall/lib/luks.py') diff --git a/archinstall/lib/luks.py b/archinstall/lib/luks.py index c9946239..fa040788 100644 --- a/archinstall/lib/luks.py +++ b/archinstall/lib/luks.py @@ -6,13 +6,14 @@ from .output import log, LOG_LEVELS from .storage import storage class luks2(): - def __init__(self, partition, mountpoint, password, key_file=None, *args, **kwargs): + def __init__(self, partition, mountpoint, password, key_file=None, auto_unmount=False, *args, **kwargs): self.password = password self.partition = partition self.mountpoint = mountpoint self.args = args self.kwargs = kwargs self.key_file = key_file + self.auto_unmount = auto_unmount self.filesystem = 'crypto_LUKS' def __enter__(self): @@ -32,6 +33,9 @@ class luks2(): def __exit__(self, *args, **kwargs): # TODO: https://stackoverflow.com/questions/28157929/how-to-safely-handle-an-exception-inside-a-context-manager + if self.auto_unmount: + self.close() + if len(args) >= 2 and args[1]: raise args[1] return True @@ -73,11 +77,12 @@ class luks2(): :param mountpoint: The name without absolute path, for instance "luksdev" will point to /dev/mapper/luksdev :type mountpoint: str """ + from .disk import get_filesystem_type if '/' in mountpoint: os.path.basename(mountpoint) # TODO: Raise exception instead? sys_command(f'/usr/bin/cryptsetup open {partition.path} {mountpoint} --key-file {os.path.abspath(key_file)} --type luks2') if os.path.islink(f'/dev/mapper/{mountpoint}'): - return Partition(f'/dev/mapper/{mountpoint}', encrypted=True) + return Partition(f'/dev/mapper/{mountpoint}', encrypted=True, filesystem=get_filesystem_type(f'/dev/mapper/{mountpoint}')) def close(self, mountpoint): sys_command(f'cryptsetup close /dev/mapper/{mountpoint}') -- cgit v1.2.3-54-g00ecf