2014-08-19 15:54:02 +02:00
|
|
|
#!/usr/bin/env python3
|
2015-02-18 15:06:10 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
2014-08-19 15:54:02 +02:00
|
|
|
# === This file is part of Calamares - <http://github.com/calamares> ===
|
|
|
|
#
|
2014-11-10 15:45:30 +01:00
|
|
|
# Copyright 2014, Rohan Garg <rohan@kde.org>
|
2015-02-17 14:38:30 +01:00
|
|
|
# Copyright 2015, Philip Müller <philm@manjaro.org>
|
2014-08-19 15:54:02 +02:00
|
|
|
#
|
|
|
|
# Calamares is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# Calamares is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
import libcalamares
|
|
|
|
import os
|
2014-10-16 19:34:43 +02:00
|
|
|
from collections import OrderedDict
|
2014-08-19 15:54:02 +02:00
|
|
|
from libcalamares.utils import check_chroot_call
|
|
|
|
|
2015-02-18 16:03:57 +01:00
|
|
|
|
2014-10-16 19:34:43 +02:00
|
|
|
def cpuinfo():
|
2015-02-18 16:03:57 +01:00
|
|
|
"""
|
|
|
|
Return the information in /proc/cpuinfo as a dictionary in the following format:
|
2014-10-16 19:34:43 +02:00
|
|
|
cpu_info['proc0']={...}
|
|
|
|
cpu_info['proc1']={...}
|
2015-02-18 16:03:57 +01:00
|
|
|
"""
|
|
|
|
cpuinfo = OrderedDict()
|
|
|
|
procinfo = OrderedDict()
|
2014-10-16 19:34:43 +02:00
|
|
|
|
|
|
|
nprocs = 0
|
|
|
|
with open('/proc/cpuinfo') as f:
|
|
|
|
for line in f:
|
|
|
|
if not line.strip():
|
|
|
|
# end of one processor
|
2015-02-17 14:38:30 +01:00
|
|
|
cpuinfo["proc{!s}".format(nprocs)] = procinfo
|
2015-02-18 15:13:39 +01:00
|
|
|
nprocs += 1
|
2014-10-16 19:34:43 +02:00
|
|
|
# Reset
|
2015-02-18 16:03:57 +01:00
|
|
|
procinfo = OrderedDict()
|
2014-10-16 19:34:43 +02:00
|
|
|
else:
|
|
|
|
if len(line.split(':')) == 2:
|
|
|
|
procinfo[line.split(':')[0].strip()] = line.split(':')[1].strip()
|
|
|
|
else:
|
|
|
|
procinfo[line.split(':')[0].strip()] = ''
|
|
|
|
|
|
|
|
return cpuinfo
|
2014-08-19 15:54:02 +02:00
|
|
|
|
2015-02-18 16:03:57 +01:00
|
|
|
|
2014-08-19 15:54:02 +02:00
|
|
|
def set_mkinitcpio_hooks_and_modules(hooks, modules, root_mount_point):
|
2015-02-20 20:54:25 +01:00
|
|
|
"""
|
|
|
|
Set up mkinitcpio.conf.
|
2014-08-19 15:54:02 +02:00
|
|
|
|
2015-02-20 20:54:25 +01:00
|
|
|
:param hooks:
|
|
|
|
:param modules:
|
|
|
|
:param root_mount_point:
|
|
|
|
"""
|
2014-08-19 15:54:02 +02:00
|
|
|
with open("/etc/mkinitcpio.conf", "r") as mkinitcpio_file:
|
|
|
|
mklins = [x.strip() for x in mkinitcpio_file.readlines()]
|
|
|
|
|
|
|
|
for i in range(len(mklins)):
|
|
|
|
if mklins[i].startswith("HOOKS"):
|
2015-02-17 14:38:30 +01:00
|
|
|
joined_hooks = ' '.join(hooks)
|
|
|
|
mklins[i] = "HOOKS=\"{!s}\"".format(joined_hooks)
|
2014-08-19 15:54:02 +02:00
|
|
|
elif mklins[i].startswith("MODULES"):
|
2015-02-17 14:38:30 +01:00
|
|
|
joined_modules = ' '.join(modules)
|
|
|
|
mklins[i] = "MODULES=\"{!s}\"".format(joined_modules)
|
2014-08-19 15:54:02 +02:00
|
|
|
|
|
|
|
path = os.path.join(root_mount_point, "etc/mkinitcpio.conf")
|
|
|
|
with open(path, "w") as mkinitcpio_file:
|
|
|
|
mkinitcpio_file.write("\n".join(mklins) + "\n")
|
|
|
|
|
2015-02-18 16:03:57 +01:00
|
|
|
|
2014-08-19 15:54:02 +02:00
|
|
|
def modify_mkinitcpio_conf(partitions, root_mount_point):
|
2015-02-20 20:54:25 +01:00
|
|
|
"""
|
|
|
|
Modifies mkinitcpio.conf
|
2014-08-19 15:54:02 +02:00
|
|
|
|
2015-02-20 20:54:25 +01:00
|
|
|
:param partitions:
|
|
|
|
:param root_mount_point:
|
|
|
|
"""
|
2014-10-17 11:52:29 +02:00
|
|
|
cpu = cpuinfo()
|
2014-08-19 15:54:02 +02:00
|
|
|
swap_uuid = ""
|
|
|
|
btrfs = ""
|
|
|
|
hooks = ["base", "udev", "autodetect", "modconf", "block", "keyboard", "keymap"]
|
|
|
|
modules = []
|
|
|
|
|
|
|
|
# It is important that the plymouth hook comes before any encrypt hook
|
|
|
|
plymouth_bin = os.path.join(root_mount_point, "usr/bin/plymouth")
|
|
|
|
if os.path.exists(plymouth_bin):
|
|
|
|
hooks.append("plymouth")
|
|
|
|
|
|
|
|
for partition in partitions:
|
|
|
|
if partition["fs"] == "linuxswap":
|
|
|
|
swap_uuid = partition["uuid"]
|
|
|
|
if partition["fs"] == "btrfs":
|
|
|
|
btrfs = "yes"
|
|
|
|
|
|
|
|
if swap_uuid is not "":
|
|
|
|
hooks.extend(["resume", "filesystems"])
|
|
|
|
else:
|
|
|
|
hooks.extend(["filesystems"])
|
|
|
|
|
2014-10-16 19:34:43 +02:00
|
|
|
if btrfs is "yes" and cpu['proc0']['vendor_id'].lower() != "genuineintel":
|
2014-08-19 15:54:02 +02:00
|
|
|
modules.append("crc32c")
|
2014-10-16 19:34:43 +02:00
|
|
|
elif btrfs is "yes" and cpu['proc0']['vendor_id'].lower() == "genuineintel":
|
2014-08-19 15:54:02 +02:00
|
|
|
modules.append("crc32c-intel")
|
|
|
|
else:
|
|
|
|
hooks.append("fsck")
|
|
|
|
|
|
|
|
set_mkinitcpio_hooks_and_modules(hooks, modules, root_mount_point)
|
|
|
|
|
|
|
|
|
|
|
|
def run():
|
2015-02-20 20:54:25 +01:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
:return:
|
|
|
|
"""
|
2014-08-19 15:54:02 +02:00
|
|
|
partitions = libcalamares.globalstorage.value("partitions")
|
|
|
|
root_mount_point = libcalamares.globalstorage.value("rootMountPoint")
|
|
|
|
modify_mkinitcpio_conf(partitions, root_mount_point)
|
|
|
|
return None
|