Esempio n. 1
0
def run():
    """ Run mkinitcpio """
    
    kernel = libcalamares.job.configuration['kernel']
    check_target_env_call(['mkinitcpio', '-p', kernel])

    """ Set hardware clock """

    root_mount_point = libcalamares.globalstorage.value("rootMountPoint")
    try:
        subprocess.check_call(["hwclock", "--systohc", "--utc"])
    except subprocess.CalledProcessError as e:
        return "Cannot set hardware clock.",\
               "hwclock terminated with exit code {}.".format(e.returncode)

    shutil.copy2("/etc/adjtime", "%s/etc/" % root_mount_point)
    
    """ Set Alsa """
    
    # setup alsa volume levels, alsa blacklist for the pc speaker, blacklist
    # for broken realtek nics
    print('setup alsa config')
    install_path = libcalamares.globalstorage.value("rootMountPoint")
    libcalamares.utils.target_env_call(
        ['/usr/bin/mkdir', '-p', '%s/etc/modprobe.d' % install_path])
    if os.path.exists('/etc/asound.state'):
        shutil.copy2('/etc/asound.state', '%s/etc/asound.state' % install_path)
    if os.path.exists('/etc/modprobe.d/alsa_blacklist.conf'):
        shutil.copy2('/etc/modprobe.d/alsa_blacklist.conf',
                     '%s/etc/modprobe.d/alsa_blacklist.conf' % install_path)
    if os.path.exists('/etc/modprobe.d/realtek_blacklist.conf'):
        shutil.copy2('/etc/modprobe.d/realtek_blacklist.conf',
                     '%s/etc/modprobe.d/realtek_blacklist.conf' % install_path)

    return None
Esempio n. 2
0
    def install(self, pkgs, from_local=False):
        if from_local:
            pacman_flags = "-U"
        else:
            pacman_flags = "-S"

        check_target_env_call(["pacman", pacman_flags,
                               "--noconfirm"] + pkgs)
Esempio n. 3
0
def install_secureboot(efi_directory):
    """
    Installs the secureboot shim in the system by calling efibootmgr.
    """
    efi_bootloader_id = efi_label()

    install_path = libcalamares.globalstorage.value("rootMountPoint")
    install_efi_directory = install_path + efi_directory

    if efi_word_size() == "64":
        install_efi_bin = "shim64.efi"
    else:
        install_efi_bin = "shim.efi"

    # Copied, roughly, from openSUSE's install script,
    # and pythonified. *disk* is something like /dev/sda,
    # while *drive* may return "(disk/dev/sda,gpt1)" ..
    # we're interested in the numbers in the second part
    # of that tuple.
    efi_drive = subprocess.check_output([
        libcalamares.job.configuration["grubProbe"],
        "-t", "drive", "--device-map=", install_efi_directory]).decode("ascii")
    efi_disk = subprocess.check_output([
        libcalamares.job.configuration["grubProbe"],
        "-t", "disk", "--device-map=", install_efi_directory]).decode("ascii")

    efi_drive_partition = efi_drive.replace("(","").replace(")","").split(",")[1]
    # Get the first run of digits from the partition
    efi_partition_number = None
    c = 0
    start = None
    while c < len(efi_drive_partition):
        if efi_drive_partition[c].isdigit() and start is None:
            start = c
        if not efi_drive_partition[c].isdigit() and start is not None:
            efi_partition_number = efi_drive_partition[start:c]
            break
        c += 1
    if efi_partition_number is None:
        raise ValueError("No partition number found for %s" % install_efi_directory)

    subprocess.call([
        libcalamares.job.configuration["efiBootMgr"],
        "-c",
        "-w",
        "-L", efi_bootloader_id,
        "-d", efi_disk,
        "-p", efi_partition_number,
        "-l", install_efi_directory + "/" + install_efi_bin])

    # The input file /etc/default/grub should already be filled out by the
    # grubcfg job module.
    check_target_env_call([libcalamares.job.configuration["grubMkconfig"],
                           "-o", os.path.join(efi_directory, "EFI",
                                              efi_bootloader_id, "grub.cfg")])
Esempio n. 4
0
def run():
    """
    This module sets up a file crypto_keyfile.bin on the rootfs, assuming the rootfs
    is LUKS encrypted and a passphrase is provided. This file is then included in the
    initramfs and used for unlocking the rootfs from a previously unlocked GRUB2
    session.
    :return:
    """

    partitions = libcalamares.globalstorage.value("partitions")

    luks_root_device = ""
    luks_root_passphrase = ""

    additional_luks_devices = []

    for partition in partitions:
        if partition["mountPoint"] == "/" and "luksMapperName" in partition:
            luks_root_device = partition["device"]
            luks_root_passphrase = partition["luksPassphrase"]
        elif "luksMapperName" in partition and\
             (partition["mountPoint"] or partition["fs"] == "linuxswap"):
            additional_luks_devices.append((partition["device"],
                                            partition["luksPassphrase"]))

    if not luks_root_device:
        return None

    if not luks_root_passphrase:
        return ("Encrypted rootfs setup error",
                "Rootfs partition {!s} is LUKS but no passphrase found.".format(luks_root_device))

    # Generate random keyfile
    check_target_env_call(["dd",
                           "bs=512",
                           "count=4",
                           "if=/dev/urandom",
                           "of=/crypto_keyfile.bin"])

    check_target_env_call(["cryptsetup",
                           "luksAddKey",
                           luks_root_device,
                           "/crypto_keyfile.bin"],
                          luks_root_passphrase,
                          15)  # timeout 15s

    for additional_device in additional_luks_devices:
        check_target_env_call(["cryptsetup",
                               "luksAddKey",
                               additional_device[0],
                               "/crypto_keyfile.bin"],
                              additional_device[1],
                              15)  # timeout 15s

    check_target_env_call(["chmod",
                           "g-rwx,o-rwx",
                           "/crypto_keyfile.bin"])

    return None
Esempio n. 5
0
def install_bootloader(boot_loader, fw_type):
    if fw_type == 'efi':
        install_path = libcalamares.globalstorage.value("rootMountPoint")
        uuid = get_uuid()
        distribution = libcalamares.job.configuration["distribution"]
        conf_path = os.path.join(
            install_path, "boot", "loader", "entries",
            "{!s}.conf".format(distribution))
        fallback_path = os.path.join(
            install_path, "boot", "loader", "entries", "{!s}-fallback.conf".format(distribution))
        loader_path = os.path.join(
            install_path, "boot", "loader", "loader.conf")
        partitions = libcalamares.globalstorage.value("partitions")
        device = ""

        for partition in partitions:
            if partition["mountPoint"] == "/boot":
                libcalamares.utils.debug(partition["device"])
                boot_device = partition["device"]
                boot_p = boot_device[-1:]
                device = boot_device[:-1]
                if boot_device.startswith('/dev/nvme'):
                    device = boot_device[:-2]

                if not boot_p or not device:
                    return ("EFI directory /boot not found!",
                            "Boot partition: \"{!s}\"",
                            "Boot device: \"{!s}\"".format(boot_p, device))
                else:
                    print("EFI directory: /boot")
                    print("Boot partition: \"{!s}\"".format(boot_p))
                    print("Boot device: \"{!s}\"".format(device))
                    
        if not device:
            print("WARNING: no EFI system partition or EFI system partition mount point not set.")
            print("         >>> no EFI bootloader will be installed <<<")
            return None
        print("Set 'EF00' flag")
        subprocess.call(
            ["sgdisk", "--typecode={!s}:EF00".format(boot_p), "{!s}".format(device)])
        subprocess.call(
            ["bootctl", "--path={!s}/boot".format(install_path), "install"])
        create_conf(uuid, conf_path)
        create_fallback(uuid, fallback_path)
        create_loader(loader_path)
    else:
        install_path = boot_loader["installPath"]
        check_target_env_call(["grub-install", install_path])
        check_target_env_call(["grub-mkconfig", "-o", "/boot/grub/grub.cfg"])
Esempio n. 6
0
def run():
    """ Run mkinitcpio """
    
    kernel = libcalamares.job.configuration['kernel']
    check_target_env_call(['mkinitcpio', '-p', kernel])

    """ Set hardware clock """

    hwclock_rtc = ["hwclock", "--systohc", "--utc"]
    hwclock_isa = ["hwclock", "--systohc", "--utc", "--directisa"]
    is_broken_rtc = False
    is_broken_isa = False

    ret = libcalamares.utils.target_env_call(hwclock_rtc)
    if ret != 0:
        is_broken_rtc = True
        libcalamares.utils.debug("Hwclock returned error code {}".format(ret))
        libcalamares.utils.debug("  .. RTC method failed, trying ISA bus method.")
    else:
        libcalamares.utils.debug("Hwclock set using RTC method.")
    if is_broken_rtc:
        ret = libcalamares.utils.target_env_call(hwclock_isa)
        if  ret != 0:
            is_broken_isa = True
            libcalamares.utils.debug("Hwclock returned error code {}".format(ret))
            libcalamares.utils.debug("  .. ISA bus method failed.")
        else:
            libcalamares.utils.debug("Hwclock set using ISA bus methode.")
    if is_broken_rtc and is_broken_isa:
        libcalamares.utils.debug("BIOS or Kernel BUG: Setting hwclock failed.")
    
    """ Set Alsa """
    
    # setup alsa volume levels, alsa blacklist for the pc speaker, blacklist
    # for broken realtek nics
    print('setup alsa config')
    install_path = libcalamares.globalstorage.value("rootMountPoint")
    libcalamares.utils.target_env_call(
        ['/usr/bin/mkdir', '-p', '%s/etc/modprobe.d' % install_path])
    if os.path.exists('/etc/asound.state'):
        shutil.copy2('/etc/asound.state', '%s/etc/asound.state' % install_path)
    if os.path.exists('/etc/modprobe.d/alsa_blacklist.conf'):
        shutil.copy2('/etc/modprobe.d/alsa_blacklist.conf',
                     '%s/etc/modprobe.d/alsa_blacklist.conf' % install_path)
    if os.path.exists('/etc/modprobe.d/realtek_blacklist.conf'):
        shutil.copy2('/etc/modprobe.d/realtek_blacklist.conf',
                     '%s/etc/modprobe.d/realtek_blacklist.conf' % install_path)

    return None
Esempio n. 7
0
def run():
    """
    Generate machine-id using dbus and systemd.

    :return:
    """
    root_mount_point = libcalamares.globalstorage.value("rootMountPoint")

    if root_mount_point is None:
        libcalamares.utils.warning("rootMountPoint is empty, {!s}".format(root_mount_point))
        return (_("Configuration Error"),
                _("No root mount point is given for <pre>{!s}</pre> to use." ).format("machineid"))

    enable_systemd = libcalamares.job.configuration["systemd"]
    enable_dbus = libcalamares.job.configuration["dbus"]
    enable_symlink = libcalamares.job.configuration["symlink"]
    target_systemd_machineid_file = root_mount_point + "/etc/machine-id"
    target_dbus_machineid_file = root_mount_point + "/var/lib/dbus/machine-id"

    if os.path.exists(target_dbus_machineid_file):
        os.remove(target_dbus_machineid_file)

    if enable_systemd:
        if os.path.exists(target_systemd_machineid_file):
            os.remove(target_systemd_machineid_file)
        check_target_env_call("systemd-machine-id-setup")

    if enable_dbus:
        if enable_symlink and os.path.exists(target_systemd_machineid_file):
            check_target_env_call(["ln", "-s", "/etc/machine-id",
                                   "/var/lib/dbus/machine-id"])
        else:
            check_target_env_call(["dbus-uuidgen", "--ensure"])

    return None
Esempio n. 8
0
def run():
    """
    Generate machine-id using dbus and systemd.

    :return:
    """
    root_mount_point = libcalamares.globalstorage.value("rootMountPoint")
    enable_systemd = libcalamares.job.configuration["systemd"]
    enable_dbus = libcalamares.job.configuration["dbus"]
    enable_symlink = libcalamares.job.configuration["symlink"]
    target_systemd_machineid_file = root_mount_point + "/etc/machine-id"
    target_dbus_machineid_file = root_mount_point + "/var/lib/dbus/machine-id"

    if os.path.exists(target_dbus_machineid_file):
        os.remove(target_dbus_machineid_file)

    if enable_systemd:
        if os.path.exists(target_systemd_machineid_file):
            os.remove(target_systemd_machineid_file)
        check_target_env_call("systemd-machine-id-setup")

    if enable_dbus:
        if enable_symlink and os.path.exists(target_systemd_machineid_file):
            check_target_env_call(["ln", "-s", "/etc/machine-id",
                                   "/var/lib/dbus/machine-id"])
        else:
            check_target_env_call(["dbus-uuidgen", "--ensure"])

    return None
Esempio n. 9
0
def install_bootloader(boot_loader, fw_type):
    if fw_type == 'efi':
        install_path = libcalamares.globalstorage.value("rootMountPoint")
        uuid = get_uuid()
        distribution = libcalamares.job.configuration["distribution"]
        conf_path = os.path.join(
            install_path, "boot", "loader", "entries", "%s.conf" % distribution)
        fallback_path = os.path.join(
            install_path, "boot", "loader", "entries", "%s-fallback.conf" % distribution)
        loader_path = os.path.join(
            install_path, "boot", "loader", "loader.conf")
        partitions = libcalamares.globalstorage.value("partitions")
        for partition in partitions:
            if partition["mountPoint"] == "/boot":
                print(partition["device"])
                boot_device = partition["device"]
                boot_p = boot_device[-1:]
                device = boot_device[:-1]

                if not boot_p or not device:
                    return ("EFI directory /boot not found!",
                            "Boot partition: \"{!s}\"",
                            "Boot device: \"{!s}\"".format(boot_p, device))
                else:
                    print("EFI directory: /boot")
                    print("Boot partition: \"{!s}\"".format(boot_p))
                    print("Boot device: \"{!s}\"".format(device))
        subprocess.call(["sgdisk", "--typecode=%s:EF00" % boot_p, "%s" % device])
        subprocess.call(
            ["bootctl", "--path=%s/boot" % install_path, "install"])
        create_conf(uuid, conf_path)
        create_fallback(uuid, fallback_path)
        create_loader(loader_path)
    else:
        install_path = boot_loader["installPath"]
        check_target_env_call(["grub-install", install_path])
        check_target_env_call(["grub-mkconfig", "-o", "/boot/grub/grub.cfg"])
Esempio n. 10
0
 def update_system(self):
     check_target_env_call(["dnf", "-y", "upgrade"])
Esempio n. 11
0
 def update_db(self):
     check_target_env_call(["urpmi.update", "-a"])
Esempio n. 12
0
 def update_db(self):
     check_target_env_call(["pkcon", "refresh"])
Esempio n. 13
0
 def update_db(self):
     check_target_env_call(["zypper", "--non-interactive", "update"])
Esempio n. 14
0
 def update_db(self):
     check_target_env_call(["emerge", "--sync"])
Esempio n. 15
0
 def install(self, pkgs, from_local=False):
     check_target_env_call(["pisi", "install" "-y"] + pkgs)
Esempio n. 16
0
 def update_db(self):
     check_target_env_call(["apt-get", "update"])
Esempio n. 17
0
 def update_db(self):
     check_target_env_call(["pacman", "-Sy"])
Esempio n. 18
0
 def install(self, pkgs, from_local=False):
     check_target_env_call(["apt-get", "-q", "-y", "install"] + pkgs)
Esempio n. 19
0
 def remove(self, pkgs):
     check_target_env_call(["apt-get", "--purge", "-q", "-y", "remove"] +
                           pkgs)
     check_target_env_call(["apt-get", "--purge", "-q", "-y", "autoremove"])
Esempio n. 20
0
 def update_db(self):
     check_target_env_call(["urpmi.update", "-a"])
Esempio n. 21
0
 def remove(self, pkgs):
     check_target_env_call(["urpme", "--auto"] + pkgs)
Esempio n. 22
0
 def install(self, pkgs, from_local=False):
     check_target_env_call([
         "urpmi", "--download-all", "--no-suggests", "--no-verify-rpm",
         "--fastunsafe", "--ignoresize", "--nolock", "--auto"
     ] + pkgs)
Esempio n. 23
0
 def remove(self, pkgs):
     check_target_env_call(["apt-get", "--purge", "-q", "-y",
                            "remove"] + pkgs)
     check_target_env_call(["apt-get", "--purge", "-q", "-y",
                            "autoremove"])
Esempio n. 24
0
 def install(self, pkgs, from_local=False):
     check_target_env_call(["xbps-install", "-Sy"] + pkgs)
Esempio n. 25
0
 def update_system(self):
     check_target_env_call(["pkcon", "-py", "update"])
Esempio n. 26
0
 def remove(self, pkgs):
     check_target_env_call(["xbps-remove", "-Ry", "--noconfirm"] + pkgs)
Esempio n. 27
0
 def install(self, pkgs, from_local=False):
     check_target_env_call(["emerge", "-v"] + pkgs)
Esempio n. 28
0
 def update_db(self):
     check_target_env_call(["xbps-install", "-S"])
Esempio n. 29
0
 def remove(self, pkgs):
     check_target_env_call(["equo", "rm"] + pkgs)
Esempio n. 30
0
 def update_system(self):
     check_target_env_call(["xbps", "-Suy"])
Esempio n. 31
0
 def update_db(self):
     check_target_env_call(["pisi", "update-repo"])
Esempio n. 32
0
 def remove(self, pkgs):
     check_target_env_call(["yum", "--disablerepo=*", "-C", "-y",
                            "remove"] + pkgs)
Esempio n. 33
0
 def remove(self, pkgs):
     check_target_env_call(["zypper", "--non-interactive", "remove"] + pkgs)
Esempio n. 34
0
 def install(self, pkgs, from_local=False):
     check_target_env_call(["urpmi", "--download-all", "--no-suggests",
                            "--no-verify-rpm", "--fastunsafe",
                            "--ignoresize", "--nolock",
                            "--auto"] + pkgs)
Esempio n. 35
0
 def remove(self, pkgs):
     check_target_env_call(["pacman", "-Rs", "--noconfirm"] + pkgs)
Esempio n. 36
0
 def remove(self, pkgs):
     check_target_env_call(
         ["yum", "--disablerepo=*", "-C", "-y", "remove"] + pkgs)
Esempio n. 37
0
 def update_system(self):
     check_target_env_call(["dnf", "-y", "upgrade"])
Esempio n. 38
0
 def update_db(self):
     check_target_env_call(["pacman", "-Sy"])
Esempio n. 39
0
 def remove(self, pkgs):
     check_target_env_call(["urpme", "--auto"] + pkgs)
Esempio n. 40
0
 def update_system(self):
     check_target_env_call(["pacman", "-Su", "--noconfirm"])
Esempio n. 41
0
 def install(self, pkgs, from_local=False):
     check_target_env_call(["apt-get", "-q", "-y", "install"] + pkgs)
Esempio n. 42
0
 def install(self, pkgs, from_local=False):
     check_target_env_call(["emerge", "-v"] + pkgs)
Esempio n. 43
0
 def update_db(self):
     check_target_env_call(["apt-get", "update"])
Esempio n. 44
0
 def remove(self, pkgs):
     check_target_env_call(["emerge", "-C"] + pkgs)
     check_target_env_call(["emerge", "--depclean", "-q"])
Esempio n. 45
0
 def remove(self, pkgs):
     check_target_env_call(["pacman", "-Rs", "--noconfirm"] + pkgs)
Esempio n. 46
0
 def update_db(self):
     check_target_env_call(["emerge", "--sync"])
Esempio n. 47
0
 def update_system(self):
     check_target_env_call(["pacman", "-Su", "--noconfirm"])
Esempio n. 48
0
 def install(self, pkgs, from_local=False):
     check_target_env_call(["equo", "i"] + pkgs)
Esempio n. 49
0
 def remove(self, pkgs):
     check_target_env_call(["emerge", "-C"] + pkgs)
     check_target_env_call(["emerge", "--depclean", "-q"])
Esempio n. 50
0
 def remove(self, pkgs):
     check_target_env_call(["equo", "rm"] + pkgs)
Esempio n. 51
0
 def install(self, pkgs, from_local=False):
     check_target_env_call(["equo", "i"] + pkgs)
Esempio n. 52
0
 def update_db(self):
     check_target_env_call(["equo", "update"])
Esempio n. 53
0
 def update_db(self):
     check_target_env_call(["equo", "update"])
Esempio n. 54
0
 def remove(self, pkgs):
     check_target_env_call(["pisi", "remove", "-y"] + pkgs)
Esempio n. 55
0
 def remove(self, pkgs):
     check_target_env_call(["pisi", "remove", "-y"] + pkgs)
Esempio n. 56
0
 def update_db(self):
     check_target_env_call(["pisi", "update-repo"])
Esempio n. 57
0
def install_grub(efi_directory, fw_type):
    """ Installs grub as bootloader, either in pc or efi mode.

    :param efi_directory:
    :param fw_type:
    """
    if fw_type == "efi":
        print("Bootloader: grub (efi)")
        efi_directory_firmware = efi_directory + "/EFI"
        check_target_env_call(["mkdir", "-p", "{!s}".format(efi_directory)])

        if "efiBootloaderId" in libcalamares.job.configuration:
            efi_bootloader_id = libcalamares.job.configuration["efiBootloaderId"]
        else:
            branding = libcalamares.globalstorage.value("branding")
            distribution = branding["bootloaderEntryName"]
            file_name_sanitizer = str.maketrans(" /", "_-")
            efi_bootloader_id = distribution.translate(file_name_sanitizer)
        check_target_env_call(
            [
                libcalamares.job.configuration["grubInstall"],
                "--target=x86_64-efi",
                "--efi-directory={!s}".format(efi_directory),
                "--bootloader-id={!s}".format(efi_bootloader_id),
                "--force",
            ]
        )
        # Workaround for some UEFI firmwares
        check_target_env_call(["mkdir", "-p", "{!s}/boot".format(efi_directory_firmware)])
        check_target_env_call(
            [
                "cp",
                "{!s}/{!s}/grubx64.efi".format(efi_directory_firmware, efi_bootloader_id),
                "{!s}/boot/bootx64.efi".format(efi_directory_firmware),
            ]
        )
    else:
        print("Bootloader: grub (bios)")
        boot_loader = libcalamares.globalstorage.value("bootLoader")
        check_target_env_call(
            [
                libcalamares.job.configuration["grubInstall"],
                "--target=i386-pc",
                "--recheck",
                "--force",
                boot_loader["installPath"],
            ]
        )

    check_target_env_call(
        [libcalamares.job.configuration["grubMkconfig"], "-o", libcalamares.job.configuration["grubCfg"]]
    )
Esempio n. 58
0
 def install(self, pkgs, from_local=False):
     for pkg in pkgs:
         check_target_env_call(["apk", "add", pkg])
Esempio n. 59
0
 def install(self, pkgs, from_local=False):
     check_target_env_call(["pisi", "install" "-y"] + pkgs)
Esempio n. 60
0
 def install(self, pkgs, from_local=False):
     check_target_env_call([
         "zypper", "--non-interactive", "--quiet-install", "install",
         "--auto-agree-with-licenses", "install"
     ] + pkgs)