diff --git a/common/DBusStructures.vala b/common/DBusStructures.vala index 1ca14fb0f..eaa64cecd 100644 --- a/common/DBusStructures.vala +++ b/common/DBusStructures.vala @@ -79,6 +79,50 @@ public enum InstallerDaemon.FileSystem { } } +public struct InstallerDaemon.PartitionUsage { + /** + * None = 0; Some(usage) = 1; + */ + public uint8 tag; + /** + * The size, in sectors, that a partition is used. + */ + public uint64 value; +} + +public enum InstallerDaemon.PartitionTable { + NONE, + GPT, + MSDOS; +} + +public enum InstallerDaemon.Step { + BACKUP, + INIT, + PARTITION, + EXTRACT, + CONFIGURE, + BOOTLOADER; +} + +public struct InstallerDaemon.Status { + Step step; + int percent; +} + +public enum InstallerDaemon.LogLevel { + TRACE, + DEBUG, + INFO, + WARN, + ERROR; +} + +public struct InstallerDaemon.Error { + Step step; + int err; +} + public struct InstallerDaemon.Partition { string device_path; @@ -86,7 +130,7 @@ public struct InstallerDaemon.Partition { uint64 start_sector; uint64 end_sector; - Distinst.PartitionUsage sectors_used; + PartitionUsage sectors_used; string? current_lvm_volume_group; } @@ -95,7 +139,8 @@ public struct InstallerDaemon.InstallConfig { string keyboard_layout; string keyboard_variant; string lang; - uint8 flags; + bool modify_boot_order; + bool install_drivers; } [Flags] diff --git a/daemon/Daemon.vala b/daemon/Daemon.vala index 04a53fe55..0fd716099 100644 --- a/daemon/Daemon.vala +++ b/daemon/Daemon.vala @@ -17,573 +17,11 @@ private static GLib.MainLoop loop; -[DBus (name = "io.elementary.InstallerDaemon")] -public class InstallerDaemon.Daemon : GLib.Object { - public signal void on_log_message (Distinst.LogLevel level, string message); - public signal void on_status (Distinst.Status status); - public signal void on_error (Distinst.Error error); - - private Distinst.Disks disks; - - construct { - Distinst.log ((level, message) => { - Idle.add (() => { - on_log_message (level, message); - }); - }); - } - - public Distinst.PartitionTable bootloader_detect () throws GLib.Error { - return Distinst.bootloader_detect (); - } - - public DiskInfo get_disks (bool get_partitions = false) throws GLib.Error { - disks = Distinst.Disks.probe (); - - if (get_partitions) { - disks.initialize_volume_groups (); - } - - DiskInfo result = DiskInfo (); - - Disk[] physical_disks = {}; - Disk[] logical_disks = {}; - - foreach (unowned Distinst.Disk disk in disks.list ()) { - if (disk.is_read_only ()) { - continue; - } - - // Skip root disk or live disk - if (disk.contains_mount ("/", disks) || disk.contains_mount ("/cdrom", disks)) { - continue; - } - - Partition[] partitions = {}; - - if (get_partitions) { - foreach (unowned Distinst.Partition part in disk.list_partitions ()) { - string lvm_vg = (part.get_file_system () == Distinst.FileSystem.LVM) - ? string_from_utf8 (part.get_current_lvm_volume_group ()) - : ""; - - partitions += Partition () { - device_path = string_from_utf8 (part.get_device_path ()), - filesystem = to_common_fs (part.get_file_system ()), - start_sector = part.get_start_sector (), - end_sector = part.get_end_sector (), - sectors_used = part.sectors_used (disk.get_sector_size ()), - current_lvm_volume_group = lvm_vg - }; - } - } - - string model = string_from_utf8 (disk.get_model ()); - string name = model.length == 0 ? string_from_utf8 (disk.get_serial ()).replace ("_", " ") : model; - - physical_disks += Disk () { - name = name, - device_path = string_from_utf8 (disk.get_device_path ()), - sectors = disk.get_sectors (), - sector_size = disk.get_sector_size (), - rotational = disk.is_rotational (), - removable = disk.is_removable (), - partitions = partitions - }; - } - - if (get_partitions) { - foreach (unowned Distinst.LvmDevice disk in disks.list_logical ()) { - Partition[] partitions = {}; - - foreach (unowned Distinst.Partition part in disk.list_partitions ()) { - string lvm_vg = (part.get_file_system () == Distinst.FileSystem.LVM) - ? string_from_utf8 (part.get_current_lvm_volume_group ()) - : ""; - - partitions += Partition () { - device_path = string_from_utf8 (part.get_device_path ()), - filesystem = to_common_fs (part.get_file_system ()), - start_sector = part.get_start_sector (), - end_sector = part.get_end_sector (), - sectors_used = part.sectors_used (disk.get_sector_size ()), - current_lvm_volume_group = lvm_vg - }; - } - - logical_disks += Disk () { - name = string_from_utf8 (disk.get_model ()), - device_path = string_from_utf8 (disk.get_device_path ()), - sectors = disk.get_sectors (), - sector_size = disk.get_sector_size (), - partitions = partitions - }; - } - } - - result.physical_disks = physical_disks; - result.logical_disks = logical_disks; - return result; - } - - public int decrypt_partition (string path, string pv, string password) throws GLib.Error { - return disks.decrypt_partition (path, Distinst.LvmEncryption () { - physical_volume = pv, - password = password, - keydata = null - }); - } - - public Disk get_logical_device (string pv) throws GLib.Error { - unowned Distinst.LvmDevice disk = disks.get_logical_device (pv); - if (disk == null) { - throw new GLib.IOError.NOT_FOUND ("Couldn't find a logical device with that name"); - } - - Partition[] partitions = {}; - - foreach (unowned Distinst.Partition part in disk.list_partitions ()) { - string lvm_vg = (part.get_file_system () == Distinst.FileSystem.LVM) - ? string_from_utf8 (part.get_current_lvm_volume_group ()) - : ""; - - partitions += Partition () { - device_path = string_from_utf8 (part.get_device_path ()), - filesystem = to_common_fs (part.get_file_system ()), - start_sector = part.get_start_sector (), - end_sector = part.get_end_sector (), - sectors_used = part.sectors_used (disk.get_sector_size ()), - current_lvm_volume_group = lvm_vg - }; - } - - return Disk () { - name = string_from_utf8 (disk.get_model ()), - device_path = string_from_utf8 (disk.get_device_path ()), - sectors = disk.get_sectors (), - sector_size = disk.get_sector_size (), - partitions = partitions - }; - } - - public void install_with_default_disk_layout (InstallConfig config, string disk, bool encrypt, string encryption_password) throws GLib.Error { - var disks = new Distinst.Disks (); - default_disk_configuration (disks, disk, encrypt ? encryption_password : null); - - install (config, (owned) disks); - } - - public void install_with_custom_disk_layout (InstallConfig config, Mount[] disk_config, LuksCredentials[] credentials) throws GLib.Error { - var disks = new Distinst.Disks (); - custom_disk_configuration (disks, disk_config, credentials); - - install (config, (owned) disks); - } - - private void install (InstallConfig config, owned Distinst.Disks disks) { - var installer = new Distinst.Installer (); - installer.on_error ((error) => on_error (error)); - installer.on_status ((status) => on_status (status)); - - var distinst_config = Distinst.Config (); - distinst_config.flags = config.flags; - distinst_config.hostname = config.hostname; - - var casper = casper_dir (); - distinst_config.remove = GLib.Path.build_filename (casper, "filesystem.manifest-remove"); - distinst_config.squashfs = GLib.Path.build_filename (casper, "filesystem.squashfs"); - - debug ("language: %s\n", config.lang); - distinst_config.lang = config.lang; - - distinst_config.keyboard_layout = config.keyboard_layout; - distinst_config.keyboard_model = null; - distinst_config.keyboard_variant = config.keyboard_variant == "" ? null : config.keyboard_variant; - - new Thread (null, () => { - if (installer.install ((owned) disks, distinst_config) != 0) { - Idle.add (() => { - on_error (Distinst.Error ()); - return GLib.Source.REMOVE; - }); - } - - return null; - }); - } - - public void set_demo_mode_locale (string locale) throws GLib.Error { - GLib.FileUtils.set_contents ("/etc/default/locale", "LANG=" + locale); - } - - public void trigger_demo_mode () throws GLib.Error { - var demo_mode_file = GLib.File.new_for_path ("/var/lib/lightdm/demo-mode"); - try { - demo_mode_file.create (GLib.FileCreateFlags.NONE); - } catch (Error e) { - if (!(e is GLib.IOError.EXISTS)) { - throw e; - } - } - } - - private string casper_dir () { - const string CDROM = "/cdrom"; - - try { - var cdrom_dir = File.new_for_path (CDROM); - var iter = cdrom_dir.enumerate_children (FileAttribute.STANDARD_NAME, 0); - - FileInfo info; - while ((info = iter.next_file ()) != null) { - unowned string name = info.get_name (); - if (name.has_prefix ("casper")) { - return GLib.Path.build_filename (CDROM, name); - } - } - } catch (GLib.Error e) { - critical ("failed to find casper dir automatically: %s\n", e.message); - } - - return GLib.Path.build_filename (CDROM, "casper"); - } - - private void default_disk_configuration (Distinst.Disks disks, string disk_path, string? encryption_password) throws GLib.IOError { - var encrypted_vg = Distinst.generate_unique_id ("cryptdata"); - var root_vg = Distinst.generate_unique_id ("data"); - if (encrypted_vg == null || root_vg == null) { - throw new GLib.IOError.FAILED ("Unable to generate unique volume group IDs"); - } - - Distinst.LvmEncryption? encryption; - if (encryption_password != null) { - debug ("encrypting"); - encryption = Distinst.LvmEncryption () { - physical_volume = encrypted_vg, - password = encryption_password, - keydata = null - }; - } else { - debug ("not encrypting"); - encryption = null; - } - - debug ("disk: %s\n", disk_path); - var disk = new Distinst.Disk (disk_path); - if (disk == null) { - throw new GLib.IOError.FAILED ("Could not find %s", disk_path); - } - - var bootloader = Distinst.bootloader_detect (); - - var start_sector = Distinst.Sector () { - flag = Distinst.SectorKind.START, - value = 0 - }; - - // 256 MiB is the minimum distinst ESP partition size, so this is 256 MiB in MB plus a bit - // extra for safety - var efi_sector = Distinst.Sector () { - flag = Distinst.SectorKind.MEGABYTE, - value = 278 - }; - - // 1024MB /boot partition that's created if we're doing encryption - var boot_sector = Distinst.Sector () { - flag = Distinst.SectorKind.MEGABYTE, - value = efi_sector.value + 1024 - }; - - // 4GB swap partition at the end - var swap_sector = Distinst.Sector () { - flag = Distinst.SectorKind.MEGABYTE_FROM_END, - value = 4096 - }; - - var end_sector = Distinst.Sector () { - flag = Distinst.SectorKind.END, - value = 0 - }; - - // Prepares a new partition table. - int result = disk.mklabel (bootloader); - - if (result != 0) { - throw new GLib.IOError.FAILED ("Unable to write partition table to %s", disk_path); - } - - var start = disk.get_sector (ref start_sector); - var end = disk.get_sector (ref boot_sector); - - switch (bootloader) { - case Distinst.PartitionTable.MSDOS: - // This is used to ensure LVM installs will work with BIOS - result = disk.add_partition ( - new Distinst.PartitionBuilder (start, end, Distinst.FileSystem.EXT4) - .partition_type (Distinst.PartitionType.PRIMARY) - .flag (Distinst.PartitionFlag.BOOT) - .mount ("/boot") - ); - - if (result != 0) { - throw new GLib.IOError.FAILED ("Unable to add boot partition to %s", disk_path); - } - - // Start the LVM from the end of our /boot partition - start = disk.get_sector (ref boot_sector); - break; - case Distinst.PartitionTable.GPT: - end = disk.get_sector (ref efi_sector); - - // A FAT32 partition is required for EFI installs - result = disk.add_partition ( - new Distinst.PartitionBuilder (start, end, Distinst.FileSystem.FAT32) - .partition_type (Distinst.PartitionType.PRIMARY) - .flag (Distinst.PartitionFlag.ESP) - .mount ("/boot/efi") - ); - - if (result != 0) { - throw new GLib.IOError.FAILED ("Unable to add EFI partition to %s", disk_path); - } - - // If we're encrypting, we need an unencrypted partition to store kernels and initramfs images - if (encryption != null) { - start = disk.get_sector (ref efi_sector); - end = disk.get_sector (ref boot_sector); - - result = disk.add_partition ( - new Distinst.PartitionBuilder (start, end, Distinst.FileSystem.EXT4) - .partition_type (Distinst.PartitionType.PRIMARY) - .mount ("/boot") - ); - - if (result != 0) { - throw new GLib.IOError.FAILED ("unable to add /boot partition to %s", disk_path); - } - - // Start the LVM from the end of our /boot/efi and /boot partitions - start = disk.get_sector (ref boot_sector); - } else { - // No encryption, we only have a /boot/efi partition, start the LVM from there - start = disk.get_sector (ref efi_sector); - } - - break; - } - - end = disk.get_sector (ref end_sector); - - result = disk.add_partition ( - new Distinst.PartitionBuilder (start, end, Distinst.FileSystem.LVM) - .partition_type (Distinst.PartitionType.PRIMARY) - .logical_volume (root_vg, encryption) - ); - - if (result != 0) { - throw new GLib.IOError.FAILED ("Unable to add LVM partition to %s", disk_path); - } - - disks.push ((owned) disk); - - result = disks.initialize_volume_groups (); - - if (result != 0) { - throw new GLib.IOError.FAILED ("Unable to initialize volume groups on %s", disk_path); - } - - unowned Distinst.LvmDevice lvm_device = disks.get_logical_device (root_vg); - - if (lvm_device == null) { - throw new GLib.IOError.FAILED ("Unable to find '%s' volume group on %s", root_vg, disk_path); - } - - start = lvm_device.get_sector (ref start_sector); - end = lvm_device.get_sector (ref swap_sector); - - result = lvm_device.add_partition ( - new Distinst.PartitionBuilder (start, end, Distinst.FileSystem.EXT4) - .name ("root") - .mount ("/") - ); - - if (result != 0) { - throw new GLib.IOError.FAILED ("Unable to add / partition to LVM on %s", disk_path); - } - - start = lvm_device.get_sector (ref swap_sector); - end = lvm_device.get_sector (ref end_sector); - - result = lvm_device.add_partition ( - new Distinst.PartitionBuilder (start, end, Distinst.FileSystem.SWAP) - .name ("swap") - ); - - if (result != 0) { - throw new GLib.IOError.FAILED ("Unable to add swap partition to LVM on %s", disk_path); - } - } - - private void custom_disk_configuration (Distinst.Disks disks, Mount[] mounts, LuksCredentials[] credentials) throws GLib.IOError { - Mount[] lvm_devices = {}; - - foreach (Mount m in mounts) { - if (m.is_lvm ()) { - lvm_devices += m; - } else { - unowned Distinst.Disk disk = disks.get_physical_device (m.parent_disk); - if (disk == null) { - var new_disk = new Distinst.Disk (m.parent_disk); - if (new_disk == null) { - throw new GLib.IOError.FAILED ("Could not find physical device: '%s'", m.parent_disk); - } - - disks.push ((owned) new_disk); - disk = disks.get_physical_device (m.parent_disk); - } - - unowned Distinst.Partition partition = disk.get_partition_by_path (m.partition_path); - - if (partition == null) { - throw new GLib.IOError.FAILED ("Could not find %s", m.partition_path); - } - - if (m.mount_point == "/boot/efi") { - if (m.is_valid_boot_mount ()) { - if (m.should_format ()) { - partition.format_with (to_distinst_fs (m.filesystem)); - } - - partition.set_mount (m.mount_point); - partition.set_flags ({ Distinst.PartitionFlag.ESP }); - } else { - throw new GLib.IOError.FAILED ("Unreachable code path -- EFI partition is invalid"); - } - } else { - if (m.filesystem != SWAP) { - partition.set_mount (m.mount_point); - } - - if (m.mount_point == "/boot") { - partition.set_flags ({ Distinst.PartitionFlag.BOOT }); - } - - if (m.should_format ()) { - partition.format_with (to_distinst_fs (m.filesystem)); - } - } - } - } - - disks.initialize_volume_groups (); - - foreach (LuksCredentials cred in credentials) { - disks.decrypt_partition (cred.device, Distinst.LvmEncryption () { - physical_volume = cred.pv, - password = cred.password, - keydata = null - }); - } - - foreach (Mount m in lvm_devices) { - var vg = m.parent_disk.offset (12); - unowned Distinst.LvmDevice disk = disks.get_logical_device (vg); - if (disk == null) { - throw new GLib.IOError.FAILED ("Could not find %s", vg); - } - - unowned Distinst.Partition partition = disk.get_partition_by_path (m.partition_path); - - if (partition == null) { - throw new GLib.IOError.FAILED ("could not find %s", m.partition_path); - } - - if (m.filesystem != SWAP) { - partition.set_mount (m.mount_point); - } - - if (m.should_format ()) { - partition.format_and_keep_name (to_distinst_fs (m.filesystem)); - } - } - } - - private static string string_from_utf8 (uint8[] input) { - var builder = new GLib.StringBuilder.sized (input.length); - builder.append_len ((string) input, input.length); - return (owned) builder.str; - } - - private InstallerDaemon.FileSystem to_common_fs (Distinst.FileSystem fs) { - switch (fs) { - case BTRFS: - return InstallerDaemon.FileSystem.BTRFS; - case EXT2: - return InstallerDaemon.FileSystem.EXT2; - case EXT3: - return InstallerDaemon.FileSystem.EXT3; - case EXT4: - return InstallerDaemon.FileSystem.EXT4; - case F2FS: - return InstallerDaemon.FileSystem.F2FS; - case FAT16: - return InstallerDaemon.FileSystem.FAT16; - case FAT32: - return InstallerDaemon.FileSystem.FAT32; - case NONE: - return InstallerDaemon.FileSystem.NONE; - case NTFS: - return InstallerDaemon.FileSystem.NTFS; - case SWAP: - return InstallerDaemon.FileSystem.SWAP; - case XFS: - return InstallerDaemon.FileSystem.XFS; - case LVM: - return InstallerDaemon.FileSystem.LVM; - case LUKS: - return InstallerDaemon.FileSystem.LUKS; - default: - return InstallerDaemon.FileSystem.NONE; - } - } - - private Distinst.FileSystem to_distinst_fs (InstallerDaemon.FileSystem fs) { - switch (fs) { - case BTRFS: - return Distinst.FileSystem.BTRFS; - case EXT2: - return Distinst.FileSystem.EXT2; - case EXT3: - return Distinst.FileSystem.EXT3; - case EXT4: - return Distinst.FileSystem.EXT4; - case F2FS: - return Distinst.FileSystem.F2FS; - case FAT16: - return Distinst.FileSystem.FAT16; - case FAT32: - return Distinst.FileSystem.FAT32; - case NONE: - return Distinst.FileSystem.NONE; - case NTFS: - return Distinst.FileSystem.NTFS; - case SWAP: - return Distinst.FileSystem.SWAP; - case XFS: - return Distinst.FileSystem.XFS; - case LVM: - return Distinst.FileSystem.LVM; - case LUKS: - return Distinst.FileSystem.LUKS; - default: - return Distinst.FileSystem.NONE; - } - } -} - private void on_bus_acquired (GLib.DBusConnection connection, string name) { try { - connection.register_object ("/io/elementary/InstallerDaemon", new InstallerDaemon.Daemon ()); +#if DISTINST_BACKEND + connection.register_object ("/io/elementary/InstallerDaemon", new InstallerDaemon.DistinstBackend ()); +#endif } catch (GLib.Error e) { critical ("Unable to register the object: %s", e.message); } diff --git a/daemon/DistinstBackend.vala b/daemon/DistinstBackend.vala new file mode 100644 index 000000000..b356ba868 --- /dev/null +++ b/daemon/DistinstBackend.vala @@ -0,0 +1,656 @@ +/* + * Copyright 2021 elementary, Inc. + * + * This program 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. + * + * This program 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 this program. If not, see . + */ + +[DBus (name = "io.elementary.InstallerDaemon")] +public class InstallerDaemon.DistinstBackend : GLib.Object { + public signal void on_log_message (InstallerDaemon.LogLevel level, string message); + public signal void on_status (InstallerDaemon.Status status); + public signal void on_error (InstallerDaemon.Error error); + + private Distinst.Disks disks; + + construct { + Distinst.log ((level, message) => { + Idle.add (() => { + on_log_message (to_common_log_level (level), message); + }); + }); + } + + public InstallerDaemon.PartitionTable bootloader_detect () throws GLib.Error { + return to_common_usage_bootloader (Distinst.bootloader_detect ()); + } + + public DiskInfo get_disks (bool get_partitions = false) throws GLib.Error { + disks = Distinst.Disks.probe (); + + if (get_partitions) { + disks.initialize_volume_groups (); + } + + DiskInfo result = DiskInfo (); + + Disk[] physical_disks = {}; + Disk[] logical_disks = {}; + + foreach (unowned Distinst.Disk disk in disks.list ()) { + if (disk.is_read_only ()) { + continue; + } + + // Skip root disk or live disk + if (disk.contains_mount ("/", disks) || disk.contains_mount ("/cdrom", disks)) { + continue; + } + + Partition[] partitions = {}; + + if (get_partitions) { + foreach (unowned Distinst.Partition part in disk.list_partitions ()) { + string lvm_vg = (part.get_file_system () == Distinst.FileSystem.LVM) + ? string_from_utf8 (part.get_current_lvm_volume_group ()) + : ""; + + partitions += Partition () { + device_path = string_from_utf8 (part.get_device_path ()), + filesystem = to_common_fs (part.get_file_system ()), + start_sector = part.get_start_sector (), + end_sector = part.get_end_sector (), + sectors_used = to_common_usage (part.sectors_used (disk.get_sector_size ())), + current_lvm_volume_group = lvm_vg + }; + } + } + + string model = string_from_utf8 (disk.get_model ()); + string name = model.length == 0 ? string_from_utf8 (disk.get_serial ()).replace ("_", " ") : model; + + physical_disks += Disk () { + name = name, + device_path = string_from_utf8 (disk.get_device_path ()), + sectors = disk.get_sectors (), + sector_size = disk.get_sector_size (), + rotational = disk.is_rotational (), + removable = disk.is_removable (), + partitions = partitions + }; + } + + if (get_partitions) { + foreach (unowned Distinst.LvmDevice disk in disks.list_logical ()) { + Partition[] partitions = {}; + + foreach (unowned Distinst.Partition part in disk.list_partitions ()) { + string lvm_vg = (part.get_file_system () == Distinst.FileSystem.LVM) + ? string_from_utf8 (part.get_current_lvm_volume_group ()) + : ""; + + partitions += Partition () { + device_path = string_from_utf8 (part.get_device_path ()), + filesystem = to_common_fs (part.get_file_system ()), + start_sector = part.get_start_sector (), + end_sector = part.get_end_sector (), + sectors_used = to_common_usage (part.sectors_used (disk.get_sector_size ())), + current_lvm_volume_group = lvm_vg + }; + } + + logical_disks += Disk () { + name = string_from_utf8 (disk.get_model ()), + device_path = string_from_utf8 (disk.get_device_path ()), + sectors = disk.get_sectors (), + sector_size = disk.get_sector_size (), + partitions = partitions + }; + } + } + + result.physical_disks = physical_disks; + result.logical_disks = logical_disks; + return result; + } + + public int decrypt_partition (string path, string pv, string password) throws GLib.Error { + return disks.decrypt_partition (path, Distinst.LvmEncryption () { + physical_volume = pv, + password = password, + keydata = null + }); + } + + public Disk get_logical_device (string pv) throws GLib.Error { + unowned Distinst.LvmDevice disk = disks.get_logical_device (pv); + if (disk == null) { + throw new GLib.IOError.NOT_FOUND ("Couldn't find a logical device with that name"); + } + + Partition[] partitions = {}; + + foreach (unowned Distinst.Partition part in disk.list_partitions ()) { + string lvm_vg = (part.get_file_system () == Distinst.FileSystem.LVM) + ? string_from_utf8 (part.get_current_lvm_volume_group ()) + : ""; + + partitions += Partition () { + device_path = string_from_utf8 (part.get_device_path ()), + filesystem = to_common_fs (part.get_file_system ()), + start_sector = part.get_start_sector (), + end_sector = part.get_end_sector (), + sectors_used = to_common_usage (part.sectors_used (disk.get_sector_size ())), + current_lvm_volume_group = lvm_vg + }; + } + + return Disk () { + name = string_from_utf8 (disk.get_model ()), + device_path = string_from_utf8 (disk.get_device_path ()), + sectors = disk.get_sectors (), + sector_size = disk.get_sector_size (), + partitions = partitions + }; + } + + public void install_with_default_disk_layout (InstallConfig config, string disk, bool encrypt, string encryption_password) throws GLib.Error { + var disks = new Distinst.Disks (); + default_disk_configuration (disks, disk, encrypt ? encryption_password : null); + + install (config, (owned) disks); + } + + public void install_with_custom_disk_layout (InstallConfig config, Mount[] disk_config, LuksCredentials[] credentials) throws GLib.Error { + var disks = new Distinst.Disks (); + custom_disk_configuration (disks, disk_config, credentials); + + install (config, (owned) disks); + } + + private void install (InstallConfig config, owned Distinst.Disks disks) { + var installer = new Distinst.Installer (); + installer.on_error ((error) => on_error (to_common_error (error))); + installer.on_status ((status) => on_status (to_common_status (status))); + + var distinst_config = Distinst.Config (); + uint8 flags = 0; + if (config.modify_boot_order) { + flags = Distinst.MODIFY_BOOT_ORDER; + } + + if (config.install_drivers) { + flags |= Distinst.RUN_UBUNTU_DRIVERS; + } + + distinst_config.flags = flags; + distinst_config.hostname = config.hostname; + + var casper = casper_dir (); + distinst_config.remove = GLib.Path.build_filename (casper, "filesystem.manifest-remove"); + distinst_config.squashfs = GLib.Path.build_filename (casper, "filesystem.squashfs"); + + debug ("language: %s\n", config.lang); + distinst_config.lang = config.lang; + + distinst_config.keyboard_layout = config.keyboard_layout; + distinst_config.keyboard_model = null; + distinst_config.keyboard_variant = config.keyboard_variant == "" ? null : config.keyboard_variant; + + new Thread (null, () => { + if (installer.install ((owned) disks, distinst_config) != 0) { + Idle.add (() => { + on_error (InstallerDaemon.Error ()); + return GLib.Source.REMOVE; + }); + } + + return null; + }); + } + + public void set_demo_mode_locale (string locale) throws GLib.Error { + GLib.FileUtils.set_contents ("/etc/default/locale", "LANG=" + locale); + } + + public void trigger_demo_mode () throws GLib.Error { + var demo_mode_file = GLib.File.new_for_path ("/var/lib/lightdm/demo-mode"); + try { + demo_mode_file.create (GLib.FileCreateFlags.NONE); + } catch (GLib.Error e) { + if (!(e is GLib.IOError.EXISTS)) { + throw e; + } + } + } + + private string casper_dir () { + const string CDROM = "/cdrom"; + + try { + var cdrom_dir = File.new_for_path (CDROM); + var iter = cdrom_dir.enumerate_children (FileAttribute.STANDARD_NAME, 0); + + FileInfo info; + while ((info = iter.next_file ()) != null) { + unowned string name = info.get_name (); + if (name.has_prefix ("casper")) { + return GLib.Path.build_filename (CDROM, name); + } + } + } catch (GLib.Error e) { + critical ("failed to find casper dir automatically: %s\n", e.message); + } + + return GLib.Path.build_filename (CDROM, "casper"); + } + + private void default_disk_configuration (Distinst.Disks disks, string disk_path, string? encryption_password) throws GLib.IOError { + var encrypted_vg = Distinst.generate_unique_id ("cryptdata"); + var root_vg = Distinst.generate_unique_id ("data"); + if (encrypted_vg == null || root_vg == null) { + throw new GLib.IOError.FAILED ("Unable to generate unique volume group IDs"); + } + + Distinst.LvmEncryption? encryption; + if (encryption_password != null) { + debug ("encrypting"); + encryption = Distinst.LvmEncryption () { + physical_volume = encrypted_vg, + password = encryption_password, + keydata = null + }; + } else { + debug ("not encrypting"); + encryption = null; + } + + debug ("disk: %s\n", disk_path); + var disk = new Distinst.Disk (disk_path); + if (disk == null) { + throw new GLib.IOError.FAILED ("Could not find %s", disk_path); + } + + var bootloader = Distinst.bootloader_detect (); + + var start_sector = Distinst.Sector () { + flag = Distinst.SectorKind.START, + value = 0 + }; + + // 256 MiB is the minimum distinst ESP partition size, so this is 256 MiB in MB plus a bit + // extra for safety + var efi_sector = Distinst.Sector () { + flag = Distinst.SectorKind.MEGABYTE, + value = 278 + }; + + // 1024MB /boot partition that's created if we're doing encryption + var boot_sector = Distinst.Sector () { + flag = Distinst.SectorKind.MEGABYTE, + value = efi_sector.value + 1024 + }; + + // 4GB swap partition at the end + var swap_sector = Distinst.Sector () { + flag = Distinst.SectorKind.MEGABYTE_FROM_END, + value = 4096 + }; + + var end_sector = Distinst.Sector () { + flag = Distinst.SectorKind.END, + value = 0 + }; + + // Prepares a new partition table. + int result = disk.mklabel (bootloader); + + if (result != 0) { + throw new GLib.IOError.FAILED ("Unable to write partition table to %s", disk_path); + } + + var start = disk.get_sector (ref start_sector); + var end = disk.get_sector (ref boot_sector); + + switch (bootloader) { + case Distinst.PartitionTable.MSDOS: + // This is used to ensure LVM installs will work with BIOS + result = disk.add_partition ( + new Distinst.PartitionBuilder (start, end, Distinst.FileSystem.EXT4) + .partition_type (Distinst.PartitionType.PRIMARY) + .flag (Distinst.PartitionFlag.BOOT) + .mount ("/boot") + ); + + if (result != 0) { + throw new GLib.IOError.FAILED ("Unable to add boot partition to %s", disk_path); + } + + // Start the LVM from the end of our /boot partition + start = disk.get_sector (ref boot_sector); + break; + case Distinst.PartitionTable.GPT: + end = disk.get_sector (ref efi_sector); + + // A FAT32 partition is required for EFI installs + result = disk.add_partition ( + new Distinst.PartitionBuilder (start, end, Distinst.FileSystem.FAT32) + .partition_type (Distinst.PartitionType.PRIMARY) + .flag (Distinst.PartitionFlag.ESP) + .mount ("/boot/efi") + ); + + if (result != 0) { + throw new GLib.IOError.FAILED ("Unable to add EFI partition to %s", disk_path); + } + + // If we're encrypting, we need an unencrypted partition to store kernels and initramfs images + if (encryption != null) { + start = disk.get_sector (ref efi_sector); + end = disk.get_sector (ref boot_sector); + + result = disk.add_partition ( + new Distinst.PartitionBuilder (start, end, Distinst.FileSystem.EXT4) + .partition_type (Distinst.PartitionType.PRIMARY) + .mount ("/boot") + ); + + if (result != 0) { + throw new GLib.IOError.FAILED ("unable to add /boot partition to %s", disk_path); + } + + // Start the LVM from the end of our /boot/efi and /boot partitions + start = disk.get_sector (ref boot_sector); + } else { + // No encryption, we only have a /boot/efi partition, start the LVM from there + start = disk.get_sector (ref efi_sector); + } + + break; + } + + end = disk.get_sector (ref end_sector); + + result = disk.add_partition ( + new Distinst.PartitionBuilder (start, end, Distinst.FileSystem.LVM) + .partition_type (Distinst.PartitionType.PRIMARY) + .logical_volume (root_vg, encryption) + ); + + if (result != 0) { + throw new GLib.IOError.FAILED ("Unable to add LVM partition to %s", disk_path); + } + + disks.push ((owned) disk); + + result = disks.initialize_volume_groups (); + + if (result != 0) { + throw new GLib.IOError.FAILED ("Unable to initialize volume groups on %s", disk_path); + } + + unowned Distinst.LvmDevice lvm_device = disks.get_logical_device (root_vg); + + if (lvm_device == null) { + throw new GLib.IOError.FAILED ("Unable to find '%s' volume group on %s", root_vg, disk_path); + } + + start = lvm_device.get_sector (ref start_sector); + end = lvm_device.get_sector (ref swap_sector); + + result = lvm_device.add_partition ( + new Distinst.PartitionBuilder (start, end, Distinst.FileSystem.EXT4) + .name ("root") + .mount ("/") + ); + + if (result != 0) { + throw new GLib.IOError.FAILED ("Unable to add / partition to LVM on %s", disk_path); + } + + start = lvm_device.get_sector (ref swap_sector); + end = lvm_device.get_sector (ref end_sector); + + result = lvm_device.add_partition ( + new Distinst.PartitionBuilder (start, end, Distinst.FileSystem.SWAP) + .name ("swap") + ); + + if (result != 0) { + throw new GLib.IOError.FAILED ("Unable to add swap partition to LVM on %s", disk_path); + } + } + + private void custom_disk_configuration (Distinst.Disks disks, Mount[] mounts, LuksCredentials[] credentials) throws GLib.IOError { + Mount[] lvm_devices = {}; + + foreach (Mount m in mounts) { + if (m.is_lvm ()) { + lvm_devices += m; + } else { + unowned Distinst.Disk disk = disks.get_physical_device (m.parent_disk); + if (disk == null) { + var new_disk = new Distinst.Disk (m.parent_disk); + if (new_disk == null) { + throw new GLib.IOError.FAILED ("Could not find physical device: '%s'", m.parent_disk); + } + + disks.push ((owned) new_disk); + disk = disks.get_physical_device (m.parent_disk); + } + + unowned Distinst.Partition partition = disk.get_partition_by_path (m.partition_path); + + if (partition == null) { + throw new GLib.IOError.FAILED ("Could not find %s", m.partition_path); + } + + if (m.mount_point == "/boot/efi") { + if (m.is_valid_boot_mount ()) { + if (m.should_format ()) { + partition.format_with (to_distinst_fs (m.filesystem)); + } + + partition.set_mount (m.mount_point); + partition.set_flags ({ Distinst.PartitionFlag.ESP }); + } else { + throw new GLib.IOError.FAILED ("Unreachable code path -- EFI partition is invalid"); + } + } else { + if (m.filesystem != InstallerDaemon.FileSystem.SWAP) { + partition.set_mount (m.mount_point); + } + + if (m.mount_point == "/boot") { + partition.set_flags ({ Distinst.PartitionFlag.BOOT }); + } + + if (m.should_format ()) { + partition.format_with (to_distinst_fs (m.filesystem)); + } + } + } + } + + disks.initialize_volume_groups (); + + foreach (LuksCredentials cred in credentials) { + disks.decrypt_partition (cred.device, Distinst.LvmEncryption () { + physical_volume = cred.pv, + password = cred.password, + keydata = null + }); + } + + foreach (Mount m in lvm_devices) { + var vg = m.parent_disk.offset (12); + unowned Distinst.LvmDevice disk = disks.get_logical_device (vg); + if (disk == null) { + throw new GLib.IOError.FAILED ("Could not find %s", vg); + } + + unowned Distinst.Partition partition = disk.get_partition_by_path (m.partition_path); + + if (partition == null) { + throw new GLib.IOError.FAILED ("could not find %s", m.partition_path); + } + + if (m.filesystem != InstallerDaemon.FileSystem.SWAP) { + partition.set_mount (m.mount_point); + } + + if (m.should_format ()) { + partition.format_and_keep_name (to_distinst_fs (m.filesystem)); + } + } + } + + private static string string_from_utf8 (uint8[] input) { + var builder = new GLib.StringBuilder.sized (input.length); + builder.append_len ((string) input, input.length); + return (owned) builder.str; + } + + private InstallerDaemon.FileSystem to_common_fs (Distinst.FileSystem fs) { + switch (fs) { + case BTRFS: + return InstallerDaemon.FileSystem.BTRFS; + case EXT2: + return InstallerDaemon.FileSystem.EXT2; + case EXT3: + return InstallerDaemon.FileSystem.EXT3; + case EXT4: + return InstallerDaemon.FileSystem.EXT4; + case F2FS: + return InstallerDaemon.FileSystem.F2FS; + case FAT16: + return InstallerDaemon.FileSystem.FAT16; + case FAT32: + return InstallerDaemon.FileSystem.FAT32; + case NONE: + return InstallerDaemon.FileSystem.NONE; + case NTFS: + return InstallerDaemon.FileSystem.NTFS; + case SWAP: + return InstallerDaemon.FileSystem.SWAP; + case XFS: + return InstallerDaemon.FileSystem.XFS; + case LVM: + return InstallerDaemon.FileSystem.LVM; + case LUKS: + return InstallerDaemon.FileSystem.LUKS; + default: + return InstallerDaemon.FileSystem.NONE; + } + } + + private InstallerDaemon.PartitionUsage to_common_usage (Distinst.PartitionUsage usage) { + return InstallerDaemon.PartitionUsage () { + tag = usage.tag, + value = usage.value + }; + } + + private Distinst.FileSystem to_distinst_fs (InstallerDaemon.FileSystem fs) { + switch (fs) { + case BTRFS: + return Distinst.FileSystem.BTRFS; + case EXT2: + return Distinst.FileSystem.EXT2; + case EXT3: + return Distinst.FileSystem.EXT3; + case EXT4: + return Distinst.FileSystem.EXT4; + case F2FS: + return Distinst.FileSystem.F2FS; + case FAT16: + return Distinst.FileSystem.FAT16; + case FAT32: + return Distinst.FileSystem.FAT32; + case NONE: + return Distinst.FileSystem.NONE; + case NTFS: + return Distinst.FileSystem.NTFS; + case SWAP: + return Distinst.FileSystem.SWAP; + case XFS: + return Distinst.FileSystem.XFS; + case LVM: + return Distinst.FileSystem.LVM; + case LUKS: + return Distinst.FileSystem.LUKS; + default: + return Distinst.FileSystem.NONE; + } + } + + private InstallerDaemon.PartitionTable to_common_usage_bootloader (Distinst.PartitionTable bootloader) { + switch (bootloader) { + case GPT: + return InstallerDaemon.PartitionTable.GPT; + case MSDOS: + return InstallerDaemon.PartitionTable.MSDOS; + case NONE: + default: + return InstallerDaemon.PartitionTable.NONE; + } + } + + private InstallerDaemon.LogLevel to_common_log_level (Distinst.LogLevel level) { + switch (level) { + case DEBUG: + return InstallerDaemon.LogLevel.DEBUG; + case INFO: + return InstallerDaemon.LogLevel.INFO; + case WARN: + return InstallerDaemon.LogLevel.WARN; + case ERROR: + return InstallerDaemon.LogLevel.ERROR; + case TRACE: + default: + return InstallerDaemon.LogLevel.TRACE; + } + } + + private InstallerDaemon.Error to_common_error (Distinst.Error error) { + return InstallerDaemon.Error () { + step = to_common_step (error.step), + err = error.err + }; + } + + private InstallerDaemon.Step to_common_step (Distinst.Step step) { + switch (step) { + case BACKUP: + return InstallerDaemon.Step.BACKUP; + case PARTITION: + return InstallerDaemon.Step.PARTITION; + case EXTRACT: + return InstallerDaemon.Step.EXTRACT; + case CONFIGURE: + return InstallerDaemon.Step.CONFIGURE; + case BOOTLOADER: + return InstallerDaemon.Step.BOOTLOADER; + case INIT: + default: + return InstallerDaemon.Step.INIT; + } + } + + private InstallerDaemon.Status to_common_status (Distinst.Status status) { + return InstallerDaemon.Status () { + step = to_common_step (status.step), + percent = status.percent + }; + } +} diff --git a/daemon/meson.build b/daemon/meson.build index f041264cc..f4a07ee25 100644 --- a/daemon/meson.build +++ b/daemon/meson.build @@ -4,13 +4,22 @@ vala_files = [ ] daemon_dependencies = [ - distinst_dep, gee_dep, glib_dep, gio_dep, gobject_dep, ] +args = '' + +if installer_backend == 'distinst' + vala_files += ['DistinstBackend.vala'] + daemon_dependencies += [distinst_dep] + args += '--define=DISTINST_BACKEND' +else + error('No supported installer backend provided') +endif + systemdunitdir = systemd_dep.get_pkgconfig_variable('systemdsystemunitdir') install_data( @@ -22,4 +31,5 @@ install_data('io.elementary.InstallerDaemon.conf', install_dir : get_option('dat executable(meson.project_name() + '-daemon', vala_files, dependencies : daemon_dependencies, + vala_args : args, install: true) diff --git a/meson.build b/meson.build index 662a778b4..85c73b6b3 100644 --- a/meson.build +++ b/meson.build @@ -12,7 +12,6 @@ add_project_arguments(['--vapidir', join_paths(meson.current_source_dir(), 'vapi gnome = import('gnome') i18n = import('i18n') -distinst_dep = dependency('distinst') glib_dep = dependency('glib-2.0', version: '>=2.74') gobject_dep = dependency('gobject-2.0') gtk_dep = dependency('gtk4') @@ -25,6 +24,13 @@ xml2_dep = dependency('libxml-2.0') pwquality_dep = dependency('pwquality') systemd_dep = dependency('systemd') +installer_backend = get_option('installer_backend') +if installer_backend == 'distinst' + distinst_dep = dependency('distinst') +else + error('No supported installer backend provided') +endif + asresources = gnome.compile_resources( 'as-resources', 'data/' + meson.project_name() + '.gresource.xml', source_dir: 'data', diff --git a/meson_options.txt b/meson_options.txt index 0f016d82e..9f76e1d3b 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,2 +1,3 @@ option('supported_languages', type : 'string', value : 'aa;ab;ae;af;ak;am;an;ar;as;ast;av;ay;az;ba;be;bg;bh;bi;bm;bn;bo;br;bs;ca;ce;ch;ckb;co;cr;cs;cu;cv;cy;da;de;de_CH;de_DE;dv;dz;ee;el;en;en_US;en_AU;en_CA;en_GB;eo;es;et;eu;fa;ff;fi;fj;fo;fr;fr_BE;fr_CA;fr_FR;fy;ga;gd;gl;gn;gu;gv;ha;he;hi;ho;hr;ht;hu;hy;hz;ia;id;ie;ig;ii;ik;io;is;it;iu;ja;jv;ka;kab;kg;ki;kj;kk;kl;km;kn;ko;kr;ks;ku;kv;kw;ky;la;lb;lg;li;ln;lo;lt;lu;lv;mg;mh;mi;mk;ml;mn;mo;mr;ms;mt;my;na;nb;nd;ne;ng;nl;nn;nr;nv;ny;oc;oj;om;or;os;pa;pi;pl;ps;pt;pt_PT;pt_BR;qu;rm;rn;ro;ru;rue;rw;sa;sc;sd;se;sg;si;sk;sl;sm;sma;sn;so;sq;sr;ss;st;su;sv;sw;szl;ta;te;tg;th;ti;tk;tl;tn;to;tr;ts;tt;tw;ty;udm;ug;uk;ur;uz;ve;vi;vo;wa;wo;xh;yi;yo;za;zh;zh_CN;zh_HK;zh_TW;zu', description : 'The list of supported languages') option('preferred_languages', type : 'string', value : 'en;zh;es;fr;pt;ru;de', description : 'A prioritized list of languages') +option('installer_backend', type : 'combo', choices : ['distinst'], value : 'distinst') diff --git a/src/Helpers/InstallerDaemon.vala b/src/Helpers/InstallerDaemon.vala index 254bb8f90..25cdbec16 100644 --- a/src/Helpers/InstallerDaemon.vala +++ b/src/Helpers/InstallerDaemon.vala @@ -23,11 +23,11 @@ public class Installer.Daemon { [DBus (name = "io.elementary.InstallerDaemon")] private interface InstallerInterface : GLib.DBusProxy { - public signal void on_error (Distinst.Error error); - public signal void on_status (Distinst.Status status); - public signal void on_log_message (Distinst.LogLevel level, string message); + public signal void on_error (InstallerDaemon.Error error); + public signal void on_status (InstallerDaemon.Status status); + public signal void on_log_message (InstallerDaemon.LogLevel level, string message); - public abstract Distinst.PartitionTable bootloader_detect () throws GLib.Error; + public abstract InstallerDaemon.PartitionTable bootloader_detect () throws GLib.Error; public async abstract InstallerDaemon.DiskInfo get_disks (bool get_partitions = false) throws GLib.Error; public async abstract int decrypt_partition (string path, string pv, string password) throws GLib.Error; @@ -38,9 +38,9 @@ public class Installer.Daemon { public async abstract void trigger_demo_mode () throws GLib.Error; } - public signal void on_error (Distinst.Error error); - public signal void on_status (Distinst.Status status); - public signal void on_log_message (Distinst.LogLevel level, string message); + public signal void on_error (InstallerDaemon.Error error); + public signal void on_status (InstallerDaemon.Status status); + public signal void on_log_message (InstallerDaemon.LogLevel level, string message); private InstallerInterface daemon; @@ -59,7 +59,7 @@ public class Installer.Daemon { daemon.on_log_message.connect ((level, message) => on_log_message (level, message)); } - public Distinst.PartitionTable bootloader_detect () { + public InstallerDaemon.PartitionTable bootloader_detect () { if (daemon == null) { return fallback_bootloader_detect (); } @@ -71,12 +71,12 @@ public class Installer.Daemon { } } - private Distinst.PartitionTable fallback_bootloader_detect () { + private InstallerDaemon.PartitionTable fallback_bootloader_detect () { var efi_file = GLib.File.new_for_path ("/sys/firmware/efi"); if (efi_file.query_exists ()) { - return Distinst.PartitionTable.GPT; + return InstallerDaemon.PartitionTable.GPT; } else { - return Distinst.PartitionTable.MSDOS; + return InstallerDaemon.PartitionTable.MSDOS; } } diff --git a/src/Helpers/LogHelper.vala b/src/Helpers/LogHelper.vala index 00677e1db..0bbb1e72f 100644 --- a/src/Helpers/LogHelper.vala +++ b/src/Helpers/LogHelper.vala @@ -16,17 +16,17 @@ * along with this program. If not, see . */ -static string level_name (Distinst.LogLevel level) { +static string level_name (InstallerDaemon.LogLevel level) { switch (level) { - case Distinst.LogLevel.TRACE: + case TRACE: return "TRACE"; - case Distinst.LogLevel.DEBUG: + case DEBUG: return "DEBUG"; - case Distinst.LogLevel.INFO: + case INFO: return "INFO"; - case Distinst.LogLevel.WARN: + case WARN: return "WARN"; - case Distinst.LogLevel.ERROR: + case ERROR: return "ERROR"; default: return "UNKNOWN"; @@ -50,7 +50,7 @@ public class LogHelper : GLib.Object { buffer.text = ""; } - public void log_func (Distinst.LogLevel level, string message) { + public void log_func (InstallerDaemon.LogLevel level, string message) { stdout.printf ("log: %s: %s\n", level_name (level), message); Gtk.TextIter end_iter; buffer.get_end_iter (out end_iter); diff --git a/src/Views/PartitioningView.vala b/src/Views/PartitioningView.vala index 98549b48f..5092e5311 100644 --- a/src/Views/PartitioningView.vala +++ b/src/Views/PartitioningView.vala @@ -60,11 +60,11 @@ public class Installer.PartitioningView : AbstractInstallerView { var bootloader = Daemon.get_default ().bootloader_detect (); switch (bootloader) { - case Distinst.PartitionTable.MSDOS: + case MSDOS: // Device is in BIOS mode, so we just require a root partition required_description = _("You must at least select a Root (/) partition."); break; - case Distinst.PartitionTable.GPT: + case GPT: // Device is in EFI mode, so we also require a boot partition required_description = _("You must at least select a Root (/) partition and an optional Boot (/boot/efi) partition."); break; @@ -233,9 +233,9 @@ public class Installer.PartitioningView : AbstractInstallerView { var bootloader = Daemon.get_default ().bootloader_detect (); switch (bootloader) { - case Distinst.PartitionTable.MSDOS: + case MSDOS: break; - case Distinst.PartitionTable.GPT: + case GPT: break; } @@ -341,7 +341,7 @@ public class Installer.PartitioningView : AbstractInstallerView { InstallerDaemon.Partition[] partitions = {}; - var usage_1 = Distinst.PartitionUsage () { + var usage_1 = InstallerDaemon.PartitionUsage () { tag = 1, value = 30312 }; @@ -355,7 +355,7 @@ public class Installer.PartitioningView : AbstractInstallerView { current_lvm_volume_group = "" }; - var usage_2 = Distinst.PartitionUsage () { + var usage_2 = InstallerDaemon.PartitionUsage () { tag = 0, value = 0 }; diff --git a/src/Views/ProgressView.vala b/src/Views/ProgressView.vala index 26dd5ba7a..3c7450574 100644 --- a/src/Views/ProgressView.vala +++ b/src/Views/ProgressView.vala @@ -109,10 +109,10 @@ public class ProgressView : Adw.NavigationPage { public void start_installation () { if (Installer.App.test_mode) { new Thread (null, () => { - fake_status (Distinst.Step.PARTITION); - fake_status (Distinst.Step.EXTRACT); - fake_status (Distinst.Step.CONFIGURE); - fake_status (Distinst.Step.BOOTLOADER); + fake_status (InstallerDaemon.Step.PARTITION); + fake_status (InstallerDaemon.Step.EXTRACT); + fake_status (InstallerDaemon.Step.CONFIGURE); + fake_status (InstallerDaemon.Step.BOOTLOADER); return null; }); } else { @@ -130,9 +130,9 @@ public class ProgressView : Adw.NavigationPage { unowned Configuration current_config = Configuration.get_default (); var config = InstallerDaemon.InstallConfig (); - config.flags = Distinst.MODIFY_BOOT_ORDER; + config.modify_boot_order = true; if (current_config.install_drivers) { - config.flags |= Distinst.RUN_UBUNTU_DRIVERS; + config.install_drivers = true; } config.hostname = Utils.get_hostname (); config.lang = "en_US.UTF-8"; @@ -164,7 +164,7 @@ public class ProgressView : Adw.NavigationPage { current_config.encryption_password ?? "" ); } catch (Error e) { - log_helper.log_func (Distinst.LogLevel.ERROR, e.message); + log_helper.log_func (InstallerDaemon.LogLevel.ERROR, e.message); on_error (); } } else { @@ -190,17 +190,17 @@ public class ProgressView : Adw.NavigationPage { try { yield daemon.install_with_custom_disk_layout (config, mounts, creds); } catch (Error e) { - log_helper.log_func (Distinst.LogLevel.ERROR, e.message); + log_helper.log_func (InstallerDaemon.LogLevel.ERROR, e.message); on_error (); } } } - private void fake_status (Distinst.Step step) { + private void fake_status (InstallerDaemon.Step step) { unowned var log_helper = LogHelper.get_default (); for (var percent = 0; percent <= 100; percent++) { log_helper.log_func (INFO, "I'm faking it!"); - Distinst.Status status = Distinst.Status () { + InstallerDaemon.Status status = InstallerDaemon.Status () { step = step, percent = percent }; @@ -209,9 +209,9 @@ public class ProgressView : Adw.NavigationPage { } } - private void installation_status_callback (Distinst.Status status) { + private void installation_status_callback (InstallerDaemon.Status status) { Idle.add (() => { - if (status.percent == 100 && status.step == Distinst.Step.BOOTLOADER) { + if (status.percent == 100 && status.step == InstallerDaemon.Step.BOOTLOADER) { on_success (); return GLib.Source.REMOVE; } @@ -219,21 +219,21 @@ public class ProgressView : Adw.NavigationPage { string step_string = ""; double fraction = ((double) status.percent) / (100.0 * NUM_STEP); switch (status.step) { - case Distinst.Step.PARTITION: + case PARTITION: ///TRANSLATORS: The current step of the installer back-end step_string = _("Partitioning Drive"); break; - case Distinst.Step.EXTRACT: + case EXTRACT: fraction += 2 * (1.0 / NUM_STEP); ///TRANSLATORS: The current step of the installer back-end step_string = _("Extracting Files"); break; - case Distinst.Step.CONFIGURE: + case CONFIGURE: fraction += 3 * (1.0 / NUM_STEP); ///TRANSLATORS: The current step of the installer back-end step_string = _("Configuring the System"); break; - case Distinst.Step.BOOTLOADER: + case BOOTLOADER: fraction += 4 * (1.0 / NUM_STEP); ///TRANSLATORS: The current step of the installer back-end step_string = _("Finishing the Installation"); @@ -246,7 +246,7 @@ public class ProgressView : Adw.NavigationPage { }); } - private void installation_error_callback (Distinst.Error error) { + private void installation_error_callback (InstallerDaemon.Error error) { Idle.add (() => { on_error (); return GLib.Source.REMOVE; diff --git a/src/Widgets/PartitionMenu.vala b/src/Widgets/PartitionMenu.vala index 35ee8e01f..d124d9292 100644 --- a/src/Widgets/PartitionMenu.vala +++ b/src/Widgets/PartitionMenu.vala @@ -49,7 +49,7 @@ public class Installer.PartitionMenu : Gtk.Popover { partition_path = path; parent_disk = parent; - string boot_partition = (Daemon.get_default ().bootloader_detect () == Distinst.PartitionTable.GPT) + string boot_partition = (Daemon.get_default ().bootloader_detect () == InstallerDaemon.PartitionTable.GPT) ? "/boot/efi" : "/boot"; @@ -158,7 +158,7 @@ public class Installer.PartitionMenu : Gtk.Popover { custom.visible = visible; if (active == 2) { - if (Daemon.get_default ().bootloader_detect () == Distinst.PartitionTable.GPT) { + if (Daemon.get_default ().bootloader_detect () == InstallerDaemon.PartitionTable.GPT) { type.active = 2; } else { type.active = 0; @@ -315,7 +315,7 @@ public class Installer.PartitionMenu : Gtk.Popover { case 1: return "/home"; case 2: - if (Daemon.get_default ().bootloader_detect () == Distinst.PartitionTable.GPT) { + if (Daemon.get_default ().bootloader_detect () == InstallerDaemon.PartitionTable.GPT) { return "/boot/efi"; } else { return "/boot"; diff --git a/src/meson.build b/src/meson.build index 3ecf0f994..13bf7e43a 100644 --- a/src/meson.build +++ b/src/meson.build @@ -57,7 +57,6 @@ config_file = configure_file( ) gui_dependencies = [ - distinst_dep, gee_dep, glib_dep, gobject_dep,