source: calamares/trunk/fuentes/src/modules/initramfscfg/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 2014, Rohan Garg <rohan@kde.org>
7#   Copyright 2015, Philip Müller <philm@manjaro.org>
8#   Copyright 2016, David McKinney <mckinney@subgraph.com>
9#   Copyright 2016, Kevin Kofler <kevin.kofler@chello.at>
10#   Copyright 2017, Alf Gaida <agaida@siduction.org>
11#   Copyright 2017, Adriaan de Groot <groot@kde.org>
12#
13#   Calamares is free software: you can redistribute it and/or modify
14#   it under the terms of the GNU General Public License as published by
15#   the Free Software Foundation, either version 3 of the License, or
16#   (at your option) any later version.
17#
18#   Calamares is distributed in the hope that it will be useful,
19#   but WITHOUT ANY WARRANTY; without even the implied warranty of
20#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21#   GNU General Public License for more details.
22#
23#   You should have received a copy of the GNU General Public License
24#   along with Calamares. If not, see <http://www.gnu.org/licenses/>.
25
26import libcalamares
27
28import inspect
29import os
30import shutil
31
32
33def copy_initramfs_hooks(partitions, root_mount_point):
34    """
35    Copies initramfs hooks so they are picked up by update-initramfs
36
37    :param partitions:
38    :param root_mount_point:
39    """
40    encrypt_hook = False
41    unencrypted_separate_boot = False
42
43    for partition in partitions:
44        if partition["mountPoint"] == "/" and "luksMapperName" in partition:
45            encrypt_hook = True
46
47        if (partition["mountPoint"] == "/boot"
48                and "luksMapperName" not in partition):
49            unencrypted_separate_boot = True
50
51    if encrypt_hook:
52        target = "{!s}/usr/share/initramfs-tools/hooks/encrypt_hook".format(
53                    root_mount_point)
54
55        # Find where this module is installed
56        _filename = inspect.getframeinfo(inspect.currentframe()).filename
57        _path = os.path.dirname(os.path.abspath(_filename))
58
59        if unencrypted_separate_boot:
60            shutil.copy2(
61                os.path.join(_path, "encrypt_hook_nokey"),
62                target
63                )
64        else:
65            shutil.copy2(
66                os.path.join(_path, "encrypt_hook"),
67                target
68                )
69        os.chmod(target, 0o755)
70
71
72def run():
73    """
74    Calls routine with given parameters to configure initramfs
75
76    :return:
77    """
78    partitions = libcalamares.globalstorage.value("partitions")
79    root_mount_point = libcalamares.globalstorage.value("rootMountPoint")
80    copy_initramfs_hooks(partitions, root_mount_point)
81
82    return None
Note: See TracBrowser for help on using the repository browser.