source: calamares/trunk/fuentes/src/modules/openrcdmcryptcfg/main.py @ 7538

Last change on this file since 7538 was 7538, checked in by kbut, 13 months ago

sync with github

File size: 2.6 KB
Line 
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3#
4# === This file is part of Calamares - <https://github.com/calamares> ===
5#
6#   Copyright 2017, Ghiunhan Mamut <venerix@redcorelinux.org>
7#
8#   Calamares is free software: you can redistribute it and/or modify
9#   it under the terms of the GNU General Public License as published by
10#   the Free Software Foundation, either version 3 of the License, or
11#   (at your option) any later version.
12#
13#   Calamares is distributed in the hope that it will be useful,
14#   but WITHOUT ANY WARRANTY; without even the implied warranty of
15#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16#   GNU General Public License for more details.
17#
18#   You should have received a copy of the GNU General Public License
19#   along with Calamares. If not, see <http://www.gnu.org/licenses/>.
20
21import libcalamares
22import os.path
23
24def write_dmcrypt_conf(partitions, root_mount_point, dmcrypt_conf_path):
25    crypto_target = ""
26    crypto_source = ""
27
28    for partition in partitions:
29        has_luks = "luksMapperName" in partition
30        skip_partitions = partition["mountPoint"] == "/" or partition["fs"] == "linuxswap"
31
32        if not has_luks and not skip_partitions:
33            libcalamares.utils.debug(
34                "Skip writing OpenRC LUKS configuration for partition {!s}".format(partition["mountPoint"]))
35
36        if has_luks and not skip_partitions:
37            crypto_target = partition["luksMapperName"]
38            crypto_source = "/dev/disk/by-uuid/{!s}".format(partition["uuid"])
39            libcalamares.utils.debug(
40                "Writing OpenRC LUKS configuration for partition {!s}".format(partition["mountPoint"]))
41
42            with open(os.path.join(root_mount_point, dmcrypt_conf_path), 'a+') as dmcrypt_file:
43                dmcrypt_file.write("\ntarget=" + crypto_target)
44                dmcrypt_file.write("\nsource=" + crypto_source)
45                dmcrypt_file.write("\nkey=/crypto_keyfile.bin")
46                dmcrypt_file.write("\n")
47
48        if has_luks and skip_partitions:
49            pass  # root and swap partitions should be handled by initramfs generators
50
51    return None
52
53def run():
54    """
55    This module configures OpenRC dmcrypt service for LUKS encrypted partitions.
56    :return:
57    """
58
59    root_mount_point = libcalamares.globalstorage.value("rootMountPoint")
60    dmcrypt_conf_path = libcalamares.job.configuration["configFilePath"]
61    partitions = libcalamares.globalstorage.value("partitions")
62
63    dmcrypt_conf_path = dmcrypt_conf_path.lstrip('/')
64
65    return write_dmcrypt_conf(partitions, root_mount_point, dmcrypt_conf_path)
Note: See TracBrowser for help on using the repository browser.