luks support

This commit is contained in:
Ward from fusion-voyager-3 2024-08-19 22:41:36 +00:00
parent b4724f7168
commit 8254999555
3 changed files with 204 additions and 77 deletions

View File

@ -26,7 +26,7 @@ pub fn create_efi_row(
partition_array: &Vec<Partition>,
partition_changed_action: &gio::SimpleAction,
language_changed_action: &gio::SimpleAction,
used_partition_array_refcell: &Rc<RefCell<Vec<String>>>,
used_partition_array_refcell: &Rc<RefCell<Vec<FstabEntry>>>,
subvol_partition_array_refcell: &Rc<RefCell<Vec<String>>>,
) {
let partition_scroll_child = gtk::ListBox::builder()
@ -83,7 +83,34 @@ pub fn create_efi_row(
.clone()
.borrow()
.iter()
.any(|e| part_name == e && part_name != &row.partition())
.any(|e| {
(part_name == &e.partition.part_name && part_name != &row.partition()) && (e.mountopts.contains("subvol=") || e.mountopts.contains("subvolid"))
})
{
PartitionRow {
widget: {
let prow = adw::ActionRow::builder()
.activatable_widget(&partition_button)
.title(part_name)
.subtitle(
String::from(&partition.part_fs)
+ " "
+ &pretty_bytes::converter::convert(partition.part_size),
)
.sensitive(false)
.build();
prow
},
swap_fs_error: Rc::new(RefCell::new(false)),
hardcode_fs_error: Rc::new(RefCell::new(false)),
used: Rc::new(RefCell::new(2)),
never: Rc::new(RefCell::new(false)),
}
} else if used_partition_array_refcell
.clone()
.borrow()
.iter()
.any(|e| part_name == &e.partition.part_name && part_name != &row.partition())
{
PartitionRow {
widget: {
@ -202,7 +229,8 @@ pub fn create_efi_row(
partition_changed_action,
move |row: DriveMountRow| {
listbox.remove(&row);
(*used_partition_array_refcell.borrow_mut()).retain(|x| x != &row.partition());
(*used_partition_array_refcell.borrow_mut())
.retain(|x| &x.partition.part_name != &row.partition());
partition_changed_action.activate(None);
}
),
@ -215,7 +243,7 @@ pub fn create_boot_row(
partition_array: &Vec<Partition>,
partition_changed_action: &gio::SimpleAction,
language_changed_action: &gio::SimpleAction,
used_partition_array_refcell: &Rc<RefCell<Vec<String>>>,
used_partition_array_refcell: &Rc<RefCell<Vec<FstabEntry>>>,
subvol_partition_array_refcell: &Rc<RefCell<Vec<String>>>,
) {
let partition_scroll_child = gtk::ListBox::builder()
@ -272,7 +300,34 @@ pub fn create_boot_row(
.clone()
.borrow()
.iter()
.any(|e| part_name == e && part_name != &row.partition())
.any(|e| {
(part_name == &e.partition.part_name && part_name != &row.partition()) && (e.mountopts.contains("subvol=") || e.mountopts.contains("subvolid"))
})
{
PartitionRow {
widget: {
let prow = adw::ActionRow::builder()
.activatable_widget(&partition_button)
.title(part_name)
.subtitle(
String::from(&partition.part_fs)
+ " "
+ &pretty_bytes::converter::convert(partition.part_size),
)
.sensitive(true)
.build();
prow
},
swap_fs_error: Rc::new(RefCell::new(false)),
hardcode_fs_error: Rc::new(RefCell::new(false)),
used: Rc::new(RefCell::new(2)),
never: Rc::new(RefCell::new(false)),
}
} else if used_partition_array_refcell
.clone()
.borrow()
.iter()
.any(|e| part_name == &e.partition.part_name && part_name != &row.partition())
{
PartitionRow {
widget: {
@ -391,7 +446,8 @@ pub fn create_boot_row(
partition_changed_action,
move |row: DriveMountRow| {
listbox.remove(&row);
(*used_partition_array_refcell.borrow_mut()).retain(|x| x != &row.partition());
(*used_partition_array_refcell.borrow_mut())
.retain(|x| &x.partition.part_name != &row.partition());
partition_changed_action.activate(None);
}
),
@ -404,7 +460,7 @@ pub fn create_root_row(
partition_array: &Vec<Partition>,
partition_changed_action: &gio::SimpleAction,
language_changed_action: &gio::SimpleAction,
used_partition_array_refcell: &Rc<RefCell<Vec<String>>>,
used_partition_array_refcell: &Rc<RefCell<Vec<FstabEntry>>>,
subvol_partition_array_refcell: &Rc<RefCell<Vec<String>>>,
) {
let partition_scroll_child = gtk::ListBox::builder()
@ -461,7 +517,34 @@ pub fn create_root_row(
.clone()
.borrow()
.iter()
.any(|e| part_name == e && part_name != &row.partition())
.any(|e| {
(part_name == &e.partition.part_name && part_name != &row.partition()) && (e.mountopts.contains("subvol=") || e.mountopts.contains("subvolid"))
})
{
PartitionRow {
widget: {
let prow = adw::ActionRow::builder()
.activatable_widget(&partition_button)
.title(part_name)
.subtitle(
String::from(&partition.part_fs)
+ " "
+ &pretty_bytes::converter::convert(partition.part_size),
)
.sensitive(false)
.build();
prow
},
swap_fs_error: Rc::new(RefCell::new(false)),
hardcode_fs_error: Rc::new(RefCell::new(false)),
used: Rc::new(RefCell::new(2)),
never: Rc::new(RefCell::new(false)),
}
} else if used_partition_array_refcell
.clone()
.borrow()
.iter()
.any(|e| part_name == &e.partition.part_name && part_name != &row.partition())
{
PartitionRow {
widget: {
@ -585,7 +668,8 @@ pub fn create_root_row(
partition_changed_action,
move |row: DriveMountRow| {
listbox.remove(&row);
(*used_partition_array_refcell.borrow_mut()).retain(|x| x != &row.partition());
(*used_partition_array_refcell.borrow_mut())
.retain(|x| &x.partition.part_name != &row.partition());
partition_changed_action.activate(None);
}
),
@ -598,7 +682,7 @@ pub fn create_mount_row(
partition_array: &Vec<Partition>,
partition_changed_action: &gio::SimpleAction,
language_changed_action: &gio::SimpleAction,
used_partition_array_refcell: &Rc<RefCell<Vec<String>>>,
used_partition_array_refcell: &Rc<RefCell<Vec<FstabEntry>>>,
subvol_partition_array_refcell: &Rc<RefCell<Vec<String>>>,
) {
let partition_scroll_child = gtk::ListBox::builder()
@ -653,7 +737,34 @@ pub fn create_mount_row(
.clone()
.borrow()
.iter()
.any(|e| part_name == e && part_name != &row.partition())
.any(|e| {
(part_name == &e.partition.part_name && part_name != &row.partition()) && (e.mountopts.contains("subvol=") || e.mountopts.contains("subvolid"))
})
{
PartitionRow {
widget: {
let prow = adw::ActionRow::builder()
.activatable_widget(&partition_button)
.title(part_name)
.subtitle(
String::from(&partition.part_fs)
+ " "
+ &pretty_bytes::converter::convert(partition.part_size),
)
.sensitive(true)
.build();
prow
},
swap_fs_error: Rc::new(RefCell::new(false)),
hardcode_fs_error: Rc::new(RefCell::new(false)),
used: Rc::new(RefCell::new(2)),
never: Rc::new(RefCell::new(false)),
}
} else if used_partition_array_refcell
.clone()
.borrow()
.iter()
.any(|e| part_name == &e.partition.part_name && part_name != &row.partition())
{
PartitionRow {
widget: {
@ -669,8 +780,8 @@ pub fn create_mount_row(
.build();
prow
},
hardcode_fs_error: Rc::new(RefCell::new(false)),
swap_fs_error: Rc::new(RefCell::new(false)),
hardcode_fs_error: Rc::new(RefCell::new(false)),
used: Rc::new(RefCell::new(1)),
never: Rc::new(RefCell::new(false)),
}
@ -715,11 +826,6 @@ pub fn create_mount_row(
#[strong]
row,
move |_| {
if row.mountopts().contains("subvol=") || row.mountopts().contains("subvolid") {
(*subvol_partition_array_refcell.borrow_mut()).push(row.partition());
} else {
(*subvol_partition_array_refcell.borrow_mut()).retain(|x| x != &row.partition());
}
partition_changed_action.activate(None);
}
));
@ -740,7 +846,8 @@ pub fn create_mount_row(
partition_changed_action,
move |row: DriveMountRow| {
listbox.remove(&row);
(*used_partition_array_refcell.borrow_mut()).retain(|x| x != &row.partition());
(*used_partition_array_refcell.borrow_mut())
.retain(|x| &x.partition.part_name != &row.partition());
partition_changed_action.activate(None);
}
),
@ -753,7 +860,7 @@ fn post_check_drive_mount(
partition_button: &gtk::CheckButton,
partition_changed_action: &gio::SimpleAction,
partition: &Partition,
used_partition_array_refcell: &Rc<RefCell<Vec<String>>>,
used_partition_array_refcell: &Rc<RefCell<Vec<FstabEntry>>>,
subvol_partition_array_refcell: &Rc<RefCell<Vec<String>>>,
) {
partition_row_struct.widget.add_prefix(partition_button);
@ -769,13 +876,6 @@ fn post_check_drive_mount(
#[strong]
partition,
move |_| {
if partition_button.is_active() == true {
let part_name = &partition.part_name;
row.set_partition(part_name.to_string());
(*used_partition_array_refcell.borrow_mut()).push(part_name.to_string());
} else {
(*used_partition_array_refcell.borrow_mut()).retain(|x| x != &partition.part_name);
}
partition_changed_action.activate(None);
}
));
@ -811,6 +911,8 @@ fn post_check_drive_mount(
));
partition_changed_action.connect_activate(clone!(
#[weak]
partition_button,
#[strong]
partition_row_struct,
#[strong]
@ -822,28 +924,27 @@ fn post_check_drive_mount(
#[strong]
subvol_partition_array_refcell,
move |_, _| {
if partition_button.is_active() == true {
let part_name = &partition.part_name;
row.set_partition(part_name.to_string());
(*used_partition_array_refcell.borrow_mut())
.push(DriveMountRow::get_fstab_entry(&row));
} else {
(*used_partition_array_refcell.borrow_mut())
.retain(|x| &x.partition.part_name != &partition.part_name);
}
if row.mountopts().contains("subvol=") || row.mountopts().contains("subvolid") {
(*subvol_partition_array_refcell.borrow_mut()).push(row.partition());
} else {
(*subvol_partition_array_refcell.borrow_mut()).retain(|x| x != &partition.part_name);
}
let part_name = &partition.part_name;
let used_partition_array = used_partition_array_refcell.borrow();
let subvol_partition_array = subvol_partition_array_refcell.borrow();
if used_partition_array
.iter()
.any(|e| part_name == e && part_name != &row.partition())
.any(|e| part_name == &e.partition.part_name && part_name != &row.partition())
{
if subvol_partition_array
.iter()
.any(|e| part_name == e && part_name != &row.partition())
{
if *partition_row_struct.never.borrow() == false
&& *partition_row_struct.swap_fs_error.borrow() == false
&& *partition_row_struct.hardcode_fs_error.borrow() == false
{
partition_row_struct.widget.set_sensitive(true);
}
(*partition_row_struct.used.borrow_mut()) = 2;
} else {
partition_row_struct.widget.set_sensitive(false);
(*partition_row_struct.used.borrow_mut()) = 1;
}
} else if *partition_row_struct.never.borrow() == false
&& *partition_row_struct.swap_fs_error.borrow() == false
&& *partition_row_struct.hardcode_fs_error.borrow() == false
@ -851,6 +952,24 @@ fn post_check_drive_mount(
partition_row_struct.widget.set_sensitive(true);
(*partition_row_struct.used.borrow_mut()) = 0;
}
if subvol_partition_array
.iter()
.any(|e| part_name == e && part_name != &row.partition())
{
println!("fuvk2");
if *partition_row_struct.never.borrow() == false
&& *partition_row_struct.swap_fs_error.borrow() == false
&& *partition_row_struct.hardcode_fs_error.borrow() == false
{
partition_row_struct.widget.set_sensitive(true);
}
(*partition_row_struct.used.borrow_mut()) = 2;
} else {
println!("fuvk");
partition_row_struct.widget.set_sensitive(false);
(*partition_row_struct.used.borrow_mut()) = 1;
}
}
));
}

View File

@ -1,13 +1,13 @@
use crate::drive_mount_row::DriveMountRow;
use crate::installer_stack_page;
use crate::partitioning_page;
use crate::partitioning_page::get_luks_uuid;
use crate::partitioning_page::{get_partitions, CrypttabEntry, FstabEntry, Partition};
use adw::gio;
use adw::prelude::*;
use glib::{clone, closure_local, ffi::gboolean};
use gtk::{glib, prelude::*, Orientation};
use std::{cell::RefCell, collections::HashSet, rc::Rc};
use crate::partitioning_page::get_luks_uuid;
mod func;
@ -25,10 +25,11 @@ pub fn manual_partitioning_page(
manual_partitioning_page.set_back_visible(true);
manual_partitioning_page.set_next_visible(true);
manual_partitioning_page.set_back_sensitive(true);
manual_partitioning_page.set_next_sensitive(false);
//manual_partitioning_page.set_next_sensitive(false);
manual_partitioning_page.set_next_sensitive(true);
let partition_array_refcell = Rc::new(RefCell::new(get_partitions()));
let used_partition_array_refcell: Rc<RefCell<Vec<String>>> = Rc::new(RefCell::default());
let used_partition_array_refcell: Rc<RefCell<Vec<FstabEntry>>> = Rc::new(RefCell::default());
let subvol_partition_array_refcell: Rc<RefCell<Vec<String>>> = Rc::new(RefCell::default());
//
@ -176,6 +177,7 @@ pub fn manual_partitioning_page(
(*partition_method_manual_luks_enabled_refcell.borrow_mut()) = false;
(*partition_method_manual_crypttab_entry_array_refcell.borrow_mut()) = Vec::new();
let mut seen_mountpoints = HashSet::new();
let mut seen_crypts = HashSet::new();
for fs_entry in generate_filesystem_table_array(&drive_mounts_adw_listbox) {
let fs_entry_clone0 = fs_entry.clone();
@ -184,7 +186,10 @@ pub fn manual_partitioning_page(
println!("mountpoint empty");
break;
}
if fs_entry.mountpoint == "[SWAP]" || fs_entry.mountpoint.starts_with("/") && !fs_entry.mountpoint.starts_with("/dev") {
if fs_entry.mountpoint == "[SWAP]"
|| fs_entry.mountpoint.starts_with("/")
&& !fs_entry.mountpoint.starts_with("/dev")
{
} else {
errored = true;
println!("mountpoint invalid");
@ -205,10 +210,7 @@ pub fn manual_partitioning_page(
//
if fs_entry_clone0.partition.has_encryption
&& !partition_method_manual_crypttab_entry_array_refcell
.borrow()
.iter()
.any(|x| x.partition == fs_entry_clone0.partition.part_name)
&& seen_crypts.insert(fs_entry_clone0.clone().partition.part_name)
{
let fs_entry = fs_entry_clone0.clone();
let (luks_manual_password_sender, luks_manual_password_receiver) =
@ -276,29 +278,34 @@ pub fn manual_partitioning_page(
}
));
let partition_method_manual_crypttab_entry_array_refcell_clone0 = partition_method_manual_crypttab_entry_array_refcell.clone();
let partition_method_manual_crypttab_entry_array_refcell_clone0 =
partition_method_manual_crypttab_entry_array_refcell.clone();
let partition_method_manual_luks_enabled_refcell_clone0 =
partition_method_manual_luks_enabled_refcell.clone();
crypttab_dialog.choose(None::<&gio::Cancellable>,
move |choice|
{
let part_name = fs_entry.partition.part_name;
if choice == "crypttab_dialog_auto" {
(*partition_method_manual_crypttab_entry_array_refcell_clone0.borrow_mut()).push(CrypttabEntry{
partition: part_name.clone(),
map: part_name.replace("mapper/", ""),
uuid: get_luks_uuid(&part_name),
password: None,
});
} else {
(*partition_method_manual_crypttab_entry_array_refcell_clone0.borrow_mut()).push(CrypttabEntry{
partition: part_name.clone(),
map: part_name.replace("mapper/", ""),
uuid: get_luks_uuid(&part_name),
password: Some(crypttab_password.text().to_string()),
});
}
crypttab_dialog.choose(None::<&gio::Cancellable>, move |choice| {
let part_name = fs_entry.partition.part_name;
if choice == "crypttab_dialog_auto" {
(*partition_method_manual_crypttab_entry_array_refcell_clone0
.borrow_mut())
.push(CrypttabEntry {
partition: part_name.clone(),
map: part_name.replace("mapper/", ""),
uuid: get_luks_uuid(&part_name),
password: Some(crypttab_password.text().to_string()),
});
} else {
(*partition_method_manual_crypttab_entry_array_refcell_clone0
.borrow_mut())
.push(CrypttabEntry {
partition: part_name.clone(),
map: part_name.replace("mapper/", ""),
uuid: get_luks_uuid(&part_name),
password: None,
});
}
);
(*partition_method_manual_luks_enabled_refcell_clone0.borrow_mut()) = true;
});
}
}
}
@ -338,9 +345,9 @@ pub fn manual_partitioning_page(
*partition_method_type_refcell.borrow_mut() = String::from("manual");
//partition_carousel.scroll_to(&partition_carousel.nth_page(5), true)
dbg!(partition_method_type_refcell.borrow());
//dbg!(partition_method_manual_fstab_entry_array_refcell.borrow());
dbg!(partition_method_manual_fstab_entry_array_refcell.borrow());
dbg!(partition_method_manual_luks_enabled_refcell.borrow());
//dbg!(partition_method_manual_crypttab_entry_array_refcell.borrow());
dbg!(partition_method_manual_crypttab_entry_array_refcell.borrow());
}
),
);
@ -372,7 +379,7 @@ fn create_hardcoded_rows(
partition_array_refcell: &Rc<RefCell<Vec<Partition>>>,
partition_changed_action: &gio::SimpleAction,
language_changed_action: &gio::SimpleAction,
used_partition_array_refcell: &Rc<RefCell<Vec<String>>>,
used_partition_array_refcell: &Rc<RefCell<Vec<FstabEntry>>>,
subvol_partition_array_refcell: &Rc<RefCell<Vec<String>>>,
) {
let drive_mount_add_button_icon = gtk::Image::builder()

View File

@ -175,7 +175,7 @@ pub struct BlockDevice {
pub block_size_pretty: String,
}
#[derive(Clone, Default)]
#[derive(Default, Clone, Debug)]
pub struct Partition {
pub part_name: String,
pub part_fs: String,
@ -186,13 +186,14 @@ pub struct Partition {
pub part_size_pretty: String,
}
#[derive(Default, Clone)]
#[derive(Default, Clone, Debug)]
pub struct FstabEntry {
pub partition: Partition,
pub mountpoint: String,
pub mountopts: String,
}
#[derive(Default, Clone, Debug)]
pub struct CrypttabEntry {
pub partition: String,
pub map: String,