From 633dd20936565d7d3ce5ae516166d50f3ce15015 Mon Sep 17 00:00:00 2001 From: Ward from fusion-voyager-3 Date: Fri, 16 Aug 2024 16:51:55 +0300 Subject: [PATCH] begin basis for manual parting --- locales/en_US.json | 3 +- src/main.rs | 1 + src/manual_partitioning/mod.rs | 0 src/partitioning_page/mod.rs | 116 +++++++++++++++++++++++++++++++++ 4 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 src/manual_partitioning/mod.rs diff --git a/locales/en_US.json b/locales/en_US.json index 5617f58..19f3603 100644 --- a/locales/en_US.json +++ b/locales/en_US.json @@ -103,5 +103,6 @@ "choose_home_seperation_auto": "Seperate /home ?", "advanced_home_seperation_selection_checkbutton_subvol_label": "Yes, via a Subvolume", "advanced_home_seperation_selection_checkbutton_partition_label": "Yes, via a Partition", - "advanced_home_seperation_selection_checkbutton_none_label": "No" + "advanced_home_seperation_selection_checkbutton_none_label": "No", + "fs_unknown": "Unknown" } diff --git a/src/main.rs b/src/main.rs index c114a5d..cccf889 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,6 +15,7 @@ mod keyboard_page; mod timezone_page; mod partitioning_page; mod automatic_partitioning_page; +mod manual_partitioning; #[macro_use] extern crate rust_i18n; diff --git a/src/manual_partitioning/mod.rs b/src/manual_partitioning/mod.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/partitioning_page/mod.rs b/src/partitioning_page/mod.rs index 632005e..13b1d97 100644 --- a/src/partitioning_page/mod.rs +++ b/src/partitioning_page/mod.rs @@ -117,6 +117,8 @@ pub fn partitioning_page( ) ); + dbg!(get_partitions()); + main_carousel.append(&partitioning_carousel) } @@ -126,6 +128,16 @@ pub struct BlockDevice { pub block_size_pretty: String } +#[derive(Debug)] +pub struct Partition { + pub part_name: String, + pub part_fs: String, + pub has_encryption: bool, + pub need_mapper: bool, + pub part_size: f64, + pub part_size_pretty: String +} + pub fn get_block_devices() -> Vec { let mut block_devices = Vec::new(); @@ -180,4 +192,108 @@ fn get_block_size(block_dev: &str) -> f64 { }; size +} + +pub fn get_partitions() -> Vec { + let mut partitions = Vec::new(); + + let command = match std::process::Command::new("sudo") + .arg("/usr/lib/pika/pika-installer-gtk4/scripts/partition-utility.sh") + .arg("get_partitions") + .stdin(std::process::Stdio::piped()) + .stdout(std::process::Stdio::piped()) + .spawn() { + Ok(t) => t, + Err(_) => return partitions + }; + + match command.stdout { + Some(t) => { + for partition in std::io::BufReader::new(t).lines() { + match partition { + Ok(r) => { + let part_size = get_part_size(&r); + let part_fs = get_part_fs(&r); + partitions.push( + Partition { + has_encryption: is_encrypted(&r), + need_mapper: is_needs_mapper(&part_fs), + part_name: r, + part_fs: part_fs, + part_size: part_size, + part_size_pretty: pretty_bytes::converter::convert(part_size) + } + ) + } + Err(_) => return partitions + } + } + }, + None => return partitions + }; + + partitions +} + +fn get_part_size(part_dev: &str) -> f64 { + let command = match std::process::Command::new("sudo") + .arg("/usr/lib/pika/pika-installer-gtk4/scripts/partition-utility.sh") + .arg("get_part_size") + .arg(part_dev) + .output() { + Ok(t) => t, + Err(_) => return 0.0 + }; + let size = match String::from_utf8(command.stdout) { + Ok(t) => { + t.trim().parse::().unwrap_or(0.0) + } + Err(_) => 0.0 + }; + + size +} + +fn get_part_fs(part_dev: &str) -> String { + let command = match std::process::Command::new("sudo") + .arg("/usr/lib/pika/pika-installer-gtk4/scripts/partition-utility.sh") + .arg("get_part_fs") + .arg(part_dev.replace("mapper/", "")) + .output() { + Ok(t) => t, + Err(_) => return String::from(t!("fs_unknown")) + }; + let fs = match String::from_utf8(command.stdout) { + Ok(t) => { + t.trim().to_owned() + } + Err(_) => String::from(t!("fs_unknown")) + }; + + fs +} + +fn is_needs_mapper(part_fs: &str) -> bool { + if part_fs.contains("crypto_LUKS") || part_fs.contains("lvm") { + true + } else { + false + } +} + +fn is_encrypted(part_dev: &str) -> bool { + let command = match std::process::Command::new("sudo") + .arg("/usr/lib/pika/pika-installer-gtk4/scripts/partition-utility.sh") + .arg("has_encryption") + .arg(part_dev) + .output() { + Ok(t) => t, + Err(_) => return false + }; + + if command.status.success() { + true + } else { + false + } } \ No newline at end of file