2014-10-12 19:45:02 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# encoding: utf-8
|
|
|
|
# === This file is part of Calamares - <http://github.com/calamares> ===
|
|
|
|
#
|
|
|
|
# Copyright 2014, Aurélien Gâteau <agateau@kde.org>
|
|
|
|
# Copyright 2014, Anke Boersma <demm@kaosx.us>
|
|
|
|
# Copyright 2014, Daniel Hillenbrand <codeworkx@bbqlinux.org>
|
|
|
|
# Copyright 2014, Benjamin Vaudour <benjamin.vaudour@yahoo.fr>
|
2015-02-17 13:53:51 +01:00
|
|
|
# Copyright 2015, Philip Mueller <philm@manjaro.org>
|
2014-10-12 19:45: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
|
|
|
|
import shutil
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
from libcalamares.utils import check_chroot_call
|
|
|
|
|
2014-10-16 21:08:18 +02:00
|
|
|
|
2014-10-12 19:45:02 +02:00
|
|
|
def get_uuid():
|
|
|
|
root_mount_point = libcalamares.globalstorage.value("rootMountPoint")
|
|
|
|
print(root_mount_point)
|
|
|
|
partitions = libcalamares.globalstorage.value("partitions")
|
|
|
|
print(partitions)
|
|
|
|
for partition in partitions:
|
|
|
|
if partition["mountPoint"] == "/":
|
|
|
|
print(partition["uuid"])
|
|
|
|
return partition["uuid"]
|
|
|
|
return ""
|
2014-10-16 21:08:18 +02:00
|
|
|
|
2014-11-13 05:10:20 +01:00
|
|
|
|
2014-11-19 17:01:02 +01:00
|
|
|
def get_bootloader_entry_name():
|
|
|
|
if "bootloaderEntryName" in libcalamares.job.configuration:
|
|
|
|
return libcalamares.job.configuration["bootloaderEntryName"]
|
|
|
|
else:
|
|
|
|
branding = libcalamares.globalstorage.value("branding")
|
|
|
|
return branding["bootloaderEntryName"]
|
|
|
|
|
2014-10-12 19:45:02 +02:00
|
|
|
def create_conf(uuid, conf_path):
|
2014-11-19 17:01:02 +01:00
|
|
|
distribution = get_bootloader_entry_name()
|
2014-11-11 06:13:15 +01:00
|
|
|
kernel = libcalamares.job.configuration["kernel"]
|
|
|
|
img = libcalamares.job.configuration["img"]
|
|
|
|
partitions = libcalamares.globalstorage.value("partitions")
|
2014-12-31 19:33:07 +01:00
|
|
|
swap = ""
|
2014-11-11 06:13:15 +01:00
|
|
|
for partition in partitions:
|
|
|
|
if partition["fs"] == "linuxswap":
|
|
|
|
swap = partition["uuid"]
|
2015-02-15 00:03:50 +01:00
|
|
|
|
2014-10-12 19:45:02 +02:00
|
|
|
lines = [
|
|
|
|
'## This is just an exmaple config file.\n',
|
|
|
|
'## Please edit the paths and kernel parameters according to your system.\n',
|
|
|
|
'\n',
|
2015-02-17 13:53:51 +01:00
|
|
|
"title {!s} GNU/Linux, with Linux core repo kernel\n".format(distribution),
|
|
|
|
"linux {!s}\n".format(kernel),
|
|
|
|
"initrd {!s}\n".format(img),
|
|
|
|
"options root=UUID={!s} quiet resume=UUID={!s} rw\n".format(uuid, swap),
|
2014-10-12 19:45:02 +02:00
|
|
|
]
|
2014-10-16 21:08:18 +02:00
|
|
|
|
2014-10-12 19:45:02 +02:00
|
|
|
with open(conf_path, 'w') as f:
|
|
|
|
for l in lines:
|
|
|
|
f.write(l)
|
|
|
|
f.close()
|
2014-10-16 21:08:18 +02:00
|
|
|
|
2014-11-13 05:10:20 +01:00
|
|
|
|
2014-11-11 06:13:15 +01:00
|
|
|
def create_fallback(uuid, fallback_path):
|
2014-11-19 17:01:02 +01:00
|
|
|
distribution = get_bootloader_entry_name()
|
2014-11-11 06:13:15 +01:00
|
|
|
kernel = libcalamares.job.configuration["kernel"]
|
|
|
|
fb_img = libcalamares.job.configuration["fallback"]
|
|
|
|
partitions = libcalamares.globalstorage.value("partitions")
|
2015-02-15 00:03:50 +01:00
|
|
|
swap = ""
|
2014-11-11 06:13:15 +01:00
|
|
|
for partition in partitions:
|
|
|
|
if partition["fs"] == "linuxswap":
|
|
|
|
swap = partition["uuid"]
|
2015-02-15 00:03:50 +01:00
|
|
|
|
2014-11-11 06:13:15 +01:00
|
|
|
lines = [
|
|
|
|
'## This is just an exmaple config file.\n',
|
|
|
|
'## Please edit the paths and kernel parameters according to your system.\n',
|
|
|
|
'\n',
|
2015-02-17 13:53:51 +01:00
|
|
|
"title {!s} GNU/Linux, with Linux fallback kernel\n".format(distribution),
|
|
|
|
"linux {!s}\n".format(kernel),
|
|
|
|
"initrd {!s}\n".format(fb_img),
|
|
|
|
"options root=UUID={!s} quiet resume=UUID={!s} rw\n".format(uuid, swap),
|
2014-11-11 06:13:15 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
with open(fallback_path, 'w') as f:
|
|
|
|
for l in lines:
|
|
|
|
f.write(l)
|
|
|
|
f.close()
|
|
|
|
|
2014-10-16 21:08:18 +02:00
|
|
|
|
2014-10-12 19:45:02 +02:00
|
|
|
def create_loader(loader_path):
|
2014-11-19 17:01:02 +01:00
|
|
|
distribution = get_bootloader_entry_name()
|
2014-10-12 19:45:02 +02:00
|
|
|
timeout = libcalamares.job.configuration["timeout"]
|
2014-11-16 04:56:11 +01:00
|
|
|
file_name_sanitizer = str.maketrans(" /", "_-")
|
2015-02-17 13:53:51 +01:00
|
|
|
distribution_translated = distribution.translate(file_name_sanitizer)
|
2014-10-12 19:45:02 +02:00
|
|
|
lines = [
|
2015-02-17 13:53:51 +01:00
|
|
|
"timeout {!s}\n".format(timeout),
|
|
|
|
"default {!s}\n".format(distribution_translated),
|
2014-10-12 19:45:02 +02:00
|
|
|
]
|
2014-10-16 21:08:18 +02:00
|
|
|
|
2014-10-12 19:45:02 +02:00
|
|
|
with open(loader_path, 'w') as f:
|
|
|
|
for l in lines:
|
|
|
|
f.write(l)
|
|
|
|
f.close()
|
2014-10-16 21:08:18 +02:00
|
|
|
|
|
|
|
|
2014-10-13 00:21:28 +02:00
|
|
|
def install_bootloader(boot_loader, fw_type):
|
2014-10-12 19:45:02 +02:00
|
|
|
if fw_type == 'efi':
|
2014-10-16 21:08:18 +02:00
|
|
|
install_path = libcalamares.globalstorage.value("rootMountPoint")
|
2015-02-14 22:53:00 +01:00
|
|
|
efi_directory = libcalamares.globalstorage.value("efiSystemPartition")
|
|
|
|
install_efi_directory = install_path + efi_directory
|
2014-10-12 19:45:02 +02:00
|
|
|
uuid = get_uuid()
|
2014-11-19 17:01:02 +01:00
|
|
|
distribution = get_bootloader_entry_name()
|
2014-11-16 04:56:11 +01:00
|
|
|
file_name_sanitizer = str.maketrans(" /", "_-")
|
2015-02-17 13:53:51 +01:00
|
|
|
distribution_translated = distribution.translate(file_name_sanitizer)
|
2014-10-16 21:08:18 +02:00
|
|
|
conf_path = os.path.join(
|
2015-02-17 13:53:51 +01:00
|
|
|
install_efi_directory, "loader", "entries", "{!s}.conf".format(distribution_translated))
|
2014-11-11 06:13:15 +01:00
|
|
|
fallback_path = os.path.join(
|
2015-02-17 13:53:51 +01:00
|
|
|
install_efi_directory, "loader", "entries", "{!s}-fallback.conf".format(distribution_translated))
|
2014-10-16 21:08:18 +02:00
|
|
|
loader_path = os.path.join(
|
2015-02-14 22:53:00 +01:00
|
|
|
install_efi_directory, "loader", "loader.conf")
|
2014-11-11 06:13:15 +01:00
|
|
|
partitions = libcalamares.globalstorage.value("partitions")
|
|
|
|
for partition in partitions:
|
2015-02-14 22:53:00 +01:00
|
|
|
if partition["mountPoint"] == efi_directory:
|
2014-11-11 06:13:15 +01:00
|
|
|
print(partition["device"])
|
|
|
|
boot_device = partition["device"]
|
|
|
|
boot_p = boot_device[-1:]
|
|
|
|
device = boot_device[:-1]
|
|
|
|
print(device)
|
2015-02-17 13:53:51 +01:00
|
|
|
subprocess.call(["sgdisk", "--typecode={!s}:EF00".format(boot_p), "{!s}".format(device)])
|
2014-10-16 21:08:18 +02:00
|
|
|
subprocess.call(
|
2015-02-17 13:53:51 +01:00
|
|
|
["gummiboot", "--path={!s}".format(install_efi_directory), "install"])
|
2014-10-12 19:45:02 +02:00
|
|
|
create_conf(uuid, conf_path)
|
2014-11-11 06:13:15 +01:00
|
|
|
create_fallback(uuid, fallback_path)
|
2014-10-12 19:45:02 +02:00
|
|
|
create_loader(loader_path)
|
|
|
|
else:
|
|
|
|
install_path = boot_loader["installPath"]
|
2014-11-13 05:10:20 +01:00
|
|
|
check_chroot_call(
|
2015-02-17 13:53:51 +01:00
|
|
|
[libcalamares.job.configuration["grubInstall"], "--target=i386-pc", install_path])
|
2014-11-13 05:10:20 +01:00
|
|
|
check_chroot_call([libcalamares.job.configuration[
|
|
|
|
"grubMkconfig"], "-o", libcalamares.job.configuration["grubCfg"]])
|
2014-10-12 19:45:02 +02:00
|
|
|
|
2014-10-16 21:08:18 +02:00
|
|
|
|
2014-10-12 19:45:02 +02:00
|
|
|
def run():
|
|
|
|
boot_loader = libcalamares.globalstorage.value("bootLoader")
|
|
|
|
fw_type = libcalamares.globalstorage.value("firmwareType")
|
2014-10-13 00:21:28 +02:00
|
|
|
install_bootloader(boot_loader, fw_type)
|
2014-10-12 19:45:02 +02:00
|
|
|
return None
|