From 8741225d1bde8e3499d6871c51837252599f9aea Mon Sep 17 00:00:00 2001 From: Ward from fusion-voyager-3 Date: Sat, 24 Aug 2024 07:16:18 +0300 Subject: [PATCH] begin terminal page --- locales/en_US.json | 2 +- src/build_ui.rs | 2 + src/installation_progress_page/mod.rs | 503 ++++-------------- src/installation_summary_page/mod.rs | 9 +- .../script_gen}/auto_basic.rs | 0 .../script_gen}/auto_btrfs.rs | 0 .../script_gen}/auto_ext4.rs | 0 .../script_gen}/auto_xfs.rs | 0 .../script_gen}/manual_basic.rs | 0 .../script_gen/mod.rs | 436 +++++++++++++++ src/main.rs | 2 +- src/style.css | 2 +- 12 files changed, 542 insertions(+), 414 deletions(-) rename src/{installation_progress_page => installation_summary_page/script_gen}/auto_basic.rs (100%) rename src/{installation_progress_page => installation_summary_page/script_gen}/auto_btrfs.rs (100%) rename src/{installation_progress_page => installation_summary_page/script_gen}/auto_ext4.rs (100%) rename src/{installation_progress_page => installation_summary_page/script_gen}/auto_xfs.rs (100%) rename src/{installation_progress_page => installation_summary_page/script_gen}/manual_basic.rs (100%) create mode 100644 src/installation_summary_page/script_gen/mod.rs diff --git a/locales/en_US.json b/locales/en_US.json index 4691547..e0196a4 100644 --- a/locales/en_US.json +++ b/locales/en_US.json @@ -27,7 +27,7 @@ "keyboard_page_title": "Keyboard", "crypttab_dialog_response_crypttab_dialog_boot": "Unlock on Boot Manually", "crypttab_dialog_response_crypttab_dialog_auto": "Unlock Automatically with Root Unlock", - "view_logs": "View Logs", + "progress_log_button_content_tooltip": "View Logs", "parting_status_text": "Partitioning The Target Drives.", "image_status_text": "Writing Image to target.", "flag1_status_text": "Enabling BLS_BOOT flag on /boot.", diff --git a/src/build_ui.rs b/src/build_ui.rs index fe6d7a5..80436d8 100644 --- a/src/build_ui.rs +++ b/src/build_ui.rs @@ -193,5 +193,7 @@ pub fn build_ui(app: &adw::Application) { &partition_method_manual_crypttab_entry_array_refcell, ); + installation_progress_page::installation_progress_page(&carousel, &language_changed_action); + window.present() } diff --git a/src/installation_progress_page/mod.rs b/src/installation_progress_page/mod.rs index a66bdaa..f9ce27e 100644 --- a/src/installation_progress_page/mod.rs +++ b/src/installation_progress_page/mod.rs @@ -1,436 +1,121 @@ use crate::{ build_ui::{BlockDevice, CrypttabEntry, FstabEntry, PikaKeymap, PikaLocale}, - config::{MINIMUM_BOOT_BYTE_SIZE, MINIMUM_EFI_BYTE_SIZE}, + config::{MINIMUM_BOOT_BYTE_SIZE, MINIMUM_EFI_BYTE_SIZE, DISTRO_ICON}, installer_stack_page, + installation_progress_page, }; use adw::prelude::*; -use glib::{clone, closure_local}; +use glib::{clone, closure_local, GString}; use gtk::{gio, glib}; use std::{cell::RefCell, fs, ops::Deref, path::Path, process::Command, rc::Rc}; -mod auto_basic; -mod auto_btrfs; -mod auto_ext4; -mod auto_xfs; -mod manual_basic; +/// DEBUG +use std::io::{self, Write}; +use duct::cmd; +/// DEBUG END -pub const standard_installation_prog: &str = r###"#! /bin/bash -set -e +pub fn installation_progress_page( + main_carousel: &adw::Carousel, + language_changed_action: &gio::SimpleAction, +) { + let installation_progress_box = gtk::Box::builder() + .orientation(gtk::Orientation::Vertical) + .build(); -SOCKET_PATH="/tmp/pikainstall-status.sock" + let installation_progress_log_stack = gtk::Stack::builder() + .transition_type(gtk::StackTransitionType::SlideUpDown) + .margin_start(15) + .margin_end(15) + .build(); -rm -rf /tmp/pika-installer-gtk4-swaplist -rm -rf /tmp/PIKA_CRYPT + let installation_progress_log_terminal_buffer = gtk::TextBuffer::builder().build(); -PIKA_INSTALL_CHROOT_PATH='{CHROOT_PATH}' -PIKA_INSTALL_LOCALE='{LOCALE}.UTF-8' -PIKA_INSTALL_KEYMAP_BASE='{KEYMAP_BASE}' -PIKA_INSTALL_KEYMAP_VARIANT='{KEYMAP_VARIANT}' -PIKA_INSTALL_TIMEZONE='{TIMEZONE}' -"###; + let installation_progress_log_terminal = gtk::TextView::builder() + .vexpand(true) + .hexpand(true) + .editable(false) + .buffer(&installation_progress_log_terminal_buffer) + .build(); -pub fn create_installation_script( - language_selection_text_refcell: &Rc>, - keymap_selection_text_refcell: &Rc>, - timezone_selection_text_refcell: &Rc>, - partition_method_type_refcell: &Rc>, - partition_method_automatic_target_refcell: &Rc>, - partition_method_automatic_target_fs_refcell: &Rc>, - partition_method_automatic_luks_enabled_refcell: &Rc>, - partition_method_automatic_luks_refcell: &Rc>, - partition_method_automatic_ratio_refcell: &Rc>, - partition_method_automatic_seperation_refcell: &Rc>, - partition_method_manual_fstab_entry_array_refcell: &Rc>>, - partition_method_manual_luks_enabled_refcell: &Rc>, - partition_method_manual_crypttab_entry_array_refcell: &Rc>>, -) -> String { - let mut final_script = String::new(); - - let variant = match keymap_selection_text_refcell.borrow().clone().variant { - Some(t) => { - t.replace("'", r###"'"'"'"###) - } - None => "".to_string(), - }; + let placeholder_icon = gtk::Image::builder() + .icon_name(DISTRO_ICON) + .halign(gtk::Align::Center) + .valign(gtk::Align::Center) + .hexpand(true) + .vexpand(true) + .pixel_size(256) + .margin_top(5) + .margin_bottom(5) + .margin_start(5) + .margin_end(5) + .build(); - let standard_installation_format = strfmt::strfmt( - standard_installation_prog, - &std::collections::HashMap::from([ - ("CHROOT_PATH".to_string(), "/media/pikaos/installation"), - ( - "LOCALE".to_string(), - language_selection_text_refcell.borrow().name.replace("'", r###"'"'"'"###).as_str(), - ), - ( - "KEYMAP_BASE".to_string(), - keymap_selection_text_refcell.borrow().name.replace("'", r###"'"'"'"###).as_str(), - ), - ( - "KEYMAP_VARIANT".to_string(), - variant.as_str() - ), - ( - "TIMEZONE".to_string(), - timezone_selection_text_refcell.borrow().replace("'", r###"'"'"'"###).as_str(), - ), - ]), - ) - .unwrap(); + let progress_bar_box = gtk::Box::builder() + .orientation(gtk::Orientation::Horizontal) + .margin_start(10) + .margin_end(15) + .build(); - final_script.push_str(&standard_installation_format); + let installation_progress_bar = gtk::ProgressBar::builder() + .hexpand(true) + .margin_end(5) + .margin_top(5) + .margin_bottom(5) + .show_text(true) + .build(); + installation_progress_bar.add_css_class("small_fg_text"); - match &*partition_method_type_refcell.borrow().as_str() { - "automatic" => { - let is_encrypted = *partition_method_automatic_luks_enabled_refcell.borrow(); - // - let automatic_standard_installation_format = strfmt::strfmt( - auto_basic::automatic_standard_installation_prog, - &std::collections::HashMap::from([ - ( - "AUTO_INSTALL_TARGET_DISK".to_string(), - partition_method_automatic_target_refcell.borrow().block_name.replace("'", r###"'"'"'"###).as_str(), - ), - ]), - ) - .unwrap(); + let progress_log_button = gtk::Button::builder() + .icon_name("terminal-symbolic") + .halign(gtk::Align::End) + .margin_start(5) + .margin_top(5) + .margin_bottom(5) + .build(); - final_script.push_str(&automatic_standard_installation_format); + progress_bar_box.append(&installation_progress_bar); + progress_bar_box.append(&progress_log_button); - // - match &*partition_method_automatic_target_fs_refcell.borrow().as_str().to_lowercase() { - "btrfs" => { - match &*partition_method_automatic_seperation_refcell.borrow().as_str() { - "subvol" => { - if is_encrypted { - final_script.push_str(&strfmt::strfmt( - auto_btrfs::automatic_home_subvol_btrfs_locked_installation_prog, - &std::collections::HashMap::from([ - ("CHROOT_PATH".to_string(), "/media/pikaos/installation"), - ( - "AUTO_LUKS_PASSWORD".to_string(), - partition_method_automatic_luks_refcell.borrow().replace("'", r###"'"'"'"###).as_str(), - ) - ]), - ) - .unwrap()); - } else { - final_script.push_str(&strfmt::strfmt( - auto_btrfs::automatic_home_subvol_btrfs_open_installation_prog, - &std::collections::HashMap::from([ - ("CHROOT_PATH".to_string(), "/media/pikaos/installation"), - ]), - ) - .unwrap()); - } - } - "partition" => { - if is_encrypted { - final_script.push_str(&strfmt::strfmt( - auto_btrfs::automatic_home_part_btrfs_locked_installation_prog, - &std::collections::HashMap::from([ - ("CHROOT_PATH".to_string(), "/media/pikaos/installation"), - ( - "AUTO_LUKS_PASSWORD".to_string(), - partition_method_automatic_luks_refcell.borrow().replace("'", r###"'"'"'"###).as_str(), - ), - ( - "ROOT_PART_SIZE_AS_I64_MIB".to_string(), - (partition_method_automatic_ratio_refcell.borrow().round() as i64 / 1048576).to_string().replace("'", r###"'"'"'"###).as_str(), - ) - ]), - ) - .unwrap()); - } else { - final_script.push_str(&strfmt::strfmt( - auto_btrfs::automatic_home_part_btrfs_open_installation_prog, - &std::collections::HashMap::from([ - ("CHROOT_PATH".to_string(), "/media/pikaos/installation"), - ( - "ROOT_PART_SIZE_AS_I64_MIB".to_string(), - (partition_method_automatic_ratio_refcell.borrow().round() as i64 / 1048576).to_string().replace("'", r###"'"'"'"###).as_str(), - ) - ]), - ) - .unwrap()); - } - } - "none" => { - if is_encrypted { - final_script.push_str(&strfmt::strfmt( - auto_btrfs::automatic_home_none_btrfs_locked_installation_prog, - &std::collections::HashMap::from([ - ("CHROOT_PATH".to_string(), "/media/pikaos/installation"), - ( - "AUTO_LUKS_PASSWORD".to_string(), - partition_method_automatic_luks_refcell.borrow().replace("'", r###"'"'"'"###).as_str(), - ) - ]), - ) - .unwrap()); - } else { - final_script.push_str(&strfmt::strfmt( - auto_btrfs::automatic_home_none_btrfs_open_installation_prog, - &std::collections::HashMap::from([ - ("CHROOT_PATH".to_string(), "/media/pikaos/installation"), - ]), - ) - .unwrap()); - } - } - _ => panic!() - } - } - "ext4" => { - match &*partition_method_automatic_seperation_refcell.borrow().as_str() { - "partition" => { - if is_encrypted { - final_script.push_str(&strfmt::strfmt( - auto_ext4::automatic_home_part_ext4_locked_installation_prog, - &std::collections::HashMap::from([ - ("CHROOT_PATH".to_string(), "/media/pikaos/installation"), - ( - "AUTO_LUKS_PASSWORD".to_string(), - partition_method_automatic_luks_refcell.borrow().replace("'", r###"'"'"'"###).as_str(), - ), - ( - "ROOT_PART_SIZE_AS_I64_MIB".to_string(), - (partition_method_automatic_ratio_refcell.borrow().round() as i64 / 1048576).to_string().replace("'", r###"'"'"'"###).as_str(), - ) - ]), - ) - .unwrap()); - } else { - final_script.push_str(&strfmt::strfmt( - auto_ext4::automatic_home_part_ext4_open_installation_prog, - &std::collections::HashMap::from([ - ("CHROOT_PATH".to_string(), "/media/pikaos/installation"), - ( - "ROOT_PART_SIZE_AS_I64_MIB".to_string(), - (partition_method_automatic_ratio_refcell.borrow().round() as i64 / 1048576).to_string().replace("'", r###"'"'"'"###).as_str(), - ) - ]), - ) - .unwrap()); - } - } - "none" => { - if is_encrypted { - final_script.push_str(&strfmt::strfmt( - auto_ext4::automatic_home_none_ext4_locked_installation_prog, - &std::collections::HashMap::from([ - ("CHROOT_PATH".to_string(), "/media/pikaos/installation"), - ( - "AUTO_LUKS_PASSWORD".to_string(), - partition_method_automatic_luks_refcell.borrow().replace("'", r###"'"'"'"###).as_str(), - ) - ]), - ) - .unwrap()); - } else { - final_script.push_str(&strfmt::strfmt( - auto_ext4::automatic_home_none_ext4_open_installation_prog, - &std::collections::HashMap::from([ - ("CHROOT_PATH".to_string(), "/media/pikaos/installation"), - ]), - ) - .unwrap()); - } - } - _ => panic!() - } - } - "xfs" => { - match &*partition_method_automatic_seperation_refcell.borrow().as_str() { - "partition" => { - if is_encrypted { - final_script.push_str(&strfmt::strfmt( - auto_xfs::automatic_home_part_xfs_locked_installation_prog, - &std::collections::HashMap::from([ - ("CHROOT_PATH".to_string(), "/media/pikaos/installation"), - ( - "AUTO_LUKS_PASSWORD".to_string(), - partition_method_automatic_luks_refcell.borrow().replace("'", r###"'"'"'"###).as_str(), - ), - ( - "ROOT_PART_SIZE_AS_I64_MIB".to_string(), - (partition_method_automatic_ratio_refcell.borrow().round() as i64 / 1048576).to_string().replace("'", r###"'"'"'"###).as_str(), - ) - ]), - ) - .unwrap()); - } else { - final_script.push_str(&strfmt::strfmt( - auto_xfs::automatic_home_part_xfs_open_installation_prog, - &std::collections::HashMap::from([ - ("CHROOT_PATH".to_string(), "/media/pikaos/installation"), - ( - "ROOT_PART_SIZE_AS_I64_MIB".to_string(), - (partition_method_automatic_ratio_refcell.borrow().round() as i64 / 1048576).to_string().replace("'", r###"'"'"'"###).as_str(), - ) - ]), - ) - .unwrap()); - } - } - "none" => { - if is_encrypted { - final_script.push_str(&strfmt::strfmt( - auto_xfs::automatic_home_none_xfs_locked_installation_prog, - &std::collections::HashMap::from([ - ("CHROOT_PATH".to_string(), "/media/pikaos/installation"), - ( - "AUTO_LUKS_PASSWORD".to_string(), - partition_method_automatic_luks_refcell.borrow().replace("'", r###"'"'"'"###).as_str(), - ) - ]), - ) - .unwrap()); - } else { - final_script.push_str(&strfmt::strfmt( - auto_xfs::automatic_home_none_xfs_open_installation_prog, - &std::collections::HashMap::from([ - ("CHROOT_PATH".to_string(), "/media/pikaos/installation"), - ]), - ) - .unwrap()); - } - } - _ => panic!() - } - } - _ => panic!() - } - // - if is_encrypted { - final_script.push_str(auto_basic::automatic_locked_part_pikainstall_prog); - } else { - final_script.push_str(auto_basic::automatic_open_part_pikainstall_prog); - } - } - "manual" => { - let is_encrypted = *partition_method_manual_luks_enabled_refcell.borrow(); - - if is_encrypted { - final_script.push_str( -r###" - -mkdir -p /tmp/PIKA_CRYPT/ -touch /tmp/PIKA_CRYPT/crypttab - -"### - ); - - for crypt_entry in partition_method_manual_crypttab_entry_array_refcell.borrow().iter() { - match &crypt_entry.password { - Some(p) => { - final_script.push_str(&strfmt::strfmt( - manual_basic::manual_crypt_entry_with_keyfile, - &std::collections::HashMap::from([ - ( - "MAP".to_string(), - crypt_entry.map.replace("'", r###"'"'"'"###).as_str() - ), - ( - "UUID".to_string(), - crypt_entry.uuid.replace("'", r###"'"'"'"###).as_str() - ), - ( - "LUKS_PASSWD".to_string(), - p.replace("'", r###"'"'"'"###).as_str() - ) - ]), - ) - .unwrap()); - } - None => { - final_script.push_str(&strfmt::strfmt( - manual_basic::manual_crypt_entry, - &std::collections::HashMap::from([ - ( - "MAP".to_string(), - crypt_entry.map.replace("'", r###"'"'"'"###).as_str() - ), - ( - "UUID".to_string(), - crypt_entry.uuid.replace("'", r###"'"'"'"###).as_str() - ) - ]), - ) - .unwrap()); - } - } - }; - } + installation_progress_log_stack.add_titled( + &placeholder_icon, + Some("slideshow_page"), + "slideshow_page", + ); + installation_progress_log_stack.add_titled( + &installation_progress_log_terminal, + Some("terminal_log_page"), + "terminal_log_page", + ); - let mut did_make_swap_list = false; + installation_progress_box.append(&installation_progress_log_stack); + installation_progress_box.append(&progress_bar_box); - for fstab_entry in partition_method_manual_fstab_entry_array_refcell.borrow().iter() { - if fstab_entry.mountpoint == "[SWAP]" { - if !did_make_swap_list { - final_script.push_str( -r###" + // -touch /tmp/pika-installer-gtk4-swaplist - -"### - ); - did_make_swap_list = true - } - final_script.push_str(&strfmt::strfmt( - manual_basic::manual_swap_mount_prog, - &std::collections::HashMap::from([ - ( - "PART".to_string(), - fstab_entry.partition.part_name.replace("'", r###"'"'"'"###).as_str() - ), - ]), - ) - .unwrap()); - } else if !fstab_entry.mountopts.is_empty() { - final_script.push_str(&strfmt::strfmt( - manual_basic::manual_partition_mount_with_opts_prog, - &std::collections::HashMap::from([ - ( - "PART".to_string(), - fstab_entry.partition.part_name.replace("'", r###"'"'"'"###).as_str() - ), - ( - "MOUNTPOINT".to_string(), - fstab_entry.mountpoint.replace("'", r###"'"'"'"###).as_str() - ), - ( - "OPTS".to_string(), - fstab_entry.mountopts.replace("'", r###"'"'"'"###).as_str() - ), - ]), - ) - .unwrap()); + progress_log_button.connect_clicked( + clone!( + #[weak] + installation_progress_log_stack, + move |_| + { + if installation_progress_log_stack.visible_child_name() == Some(GString::from_string_unchecked("slideshow_page".into())) { + installation_progress_log_stack.set_visible_child_name("terminal_log_page"); } else { - final_script.push_str(&strfmt::strfmt( - manual_basic::manual_partition_mount_prog, - &std::collections::HashMap::from([ - ( - "PART".to_string(), - fstab_entry.partition.part_name.replace("'", r###"'"'"'"###).as_str() - ), - ( - "MOUNTPOINT".to_string(), - fstab_entry.mountpoint.replace("'", r###"'"'"'"###).as_str() - ), - ]), - ) - .unwrap()); + installation_progress_log_stack.set_visible_child_name("slideshow_page"); } } + ) + ); - if is_encrypted { - final_script.push_str(manual_basic::manual_locked_part_pikainstall_prog); - } else { - final_script.push_str(manual_basic::manual_open_part_pikainstall_prog); - } + // + + language_changed_action.connect_activate(clone!( + #[weak] + progress_log_button, + move |_, _| { + progress_log_button.set_tooltip_text(Some(&t!("progress_log_button_content_tooltip"))); } - _ => panic!() - } + )); - final_script -} + main_carousel.append(&installation_progress_box); +} \ No newline at end of file diff --git a/src/installation_summary_page/mod.rs b/src/installation_summary_page/mod.rs index b678e40..38e91eb 100644 --- a/src/installation_summary_page/mod.rs +++ b/src/installation_summary_page/mod.rs @@ -9,6 +9,8 @@ use glib::{clone, closure_local}; use gtk::{gio, glib}; use std::{cell::RefCell, fs, ops::Deref, path::Path, process::Command, rc::Rc}; +mod script_gen; + /// DEBUG use std::io::{self, Write}; use duct::cmd; @@ -79,6 +81,8 @@ pub fn installation_summary_page( // install_confirm_button.connect_clicked(clone!( + #[weak] + main_carousel, #[strong] language_selection_text_refcell, #[strong] @@ -108,7 +112,7 @@ pub fn installation_summary_page( move |_| { std::io::stdout().flush().unwrap(); - let cmd = installation_progress_page::create_installation_script( + let cmd = script_gen::create_installation_script( &language_selection_text_refcell, &keymap_selection_text_refcell, &timezone_selection_text_refcell, @@ -126,7 +130,8 @@ pub fn installation_summary_page( let big_cmd = cmd!("sudo", "bash", "-c", cmd ); - assert!(big_cmd.run().is_ok()); + //assert!(big_cmd.run().is_ok()); + main_carousel.scroll_to(&main_carousel.nth_page(7), true); } ) ); diff --git a/src/installation_progress_page/auto_basic.rs b/src/installation_summary_page/script_gen/auto_basic.rs similarity index 100% rename from src/installation_progress_page/auto_basic.rs rename to src/installation_summary_page/script_gen/auto_basic.rs diff --git a/src/installation_progress_page/auto_btrfs.rs b/src/installation_summary_page/script_gen/auto_btrfs.rs similarity index 100% rename from src/installation_progress_page/auto_btrfs.rs rename to src/installation_summary_page/script_gen/auto_btrfs.rs diff --git a/src/installation_progress_page/auto_ext4.rs b/src/installation_summary_page/script_gen/auto_ext4.rs similarity index 100% rename from src/installation_progress_page/auto_ext4.rs rename to src/installation_summary_page/script_gen/auto_ext4.rs diff --git a/src/installation_progress_page/auto_xfs.rs b/src/installation_summary_page/script_gen/auto_xfs.rs similarity index 100% rename from src/installation_progress_page/auto_xfs.rs rename to src/installation_summary_page/script_gen/auto_xfs.rs diff --git a/src/installation_progress_page/manual_basic.rs b/src/installation_summary_page/script_gen/manual_basic.rs similarity index 100% rename from src/installation_progress_page/manual_basic.rs rename to src/installation_summary_page/script_gen/manual_basic.rs diff --git a/src/installation_summary_page/script_gen/mod.rs b/src/installation_summary_page/script_gen/mod.rs new file mode 100644 index 0000000..a66bdaa --- /dev/null +++ b/src/installation_summary_page/script_gen/mod.rs @@ -0,0 +1,436 @@ +use crate::{ + build_ui::{BlockDevice, CrypttabEntry, FstabEntry, PikaKeymap, PikaLocale}, + config::{MINIMUM_BOOT_BYTE_SIZE, MINIMUM_EFI_BYTE_SIZE}, + installer_stack_page, +}; +use adw::prelude::*; +use glib::{clone, closure_local}; +use gtk::{gio, glib}; +use std::{cell::RefCell, fs, ops::Deref, path::Path, process::Command, rc::Rc}; + +mod auto_basic; +mod auto_btrfs; +mod auto_ext4; +mod auto_xfs; +mod manual_basic; + +pub const standard_installation_prog: &str = r###"#! /bin/bash +set -e + +SOCKET_PATH="/tmp/pikainstall-status.sock" + +rm -rf /tmp/pika-installer-gtk4-swaplist +rm -rf /tmp/PIKA_CRYPT + +PIKA_INSTALL_CHROOT_PATH='{CHROOT_PATH}' +PIKA_INSTALL_LOCALE='{LOCALE}.UTF-8' +PIKA_INSTALL_KEYMAP_BASE='{KEYMAP_BASE}' +PIKA_INSTALL_KEYMAP_VARIANT='{KEYMAP_VARIANT}' +PIKA_INSTALL_TIMEZONE='{TIMEZONE}' +"###; + +pub fn create_installation_script( + language_selection_text_refcell: &Rc>, + keymap_selection_text_refcell: &Rc>, + timezone_selection_text_refcell: &Rc>, + partition_method_type_refcell: &Rc>, + partition_method_automatic_target_refcell: &Rc>, + partition_method_automatic_target_fs_refcell: &Rc>, + partition_method_automatic_luks_enabled_refcell: &Rc>, + partition_method_automatic_luks_refcell: &Rc>, + partition_method_automatic_ratio_refcell: &Rc>, + partition_method_automatic_seperation_refcell: &Rc>, + partition_method_manual_fstab_entry_array_refcell: &Rc>>, + partition_method_manual_luks_enabled_refcell: &Rc>, + partition_method_manual_crypttab_entry_array_refcell: &Rc>>, +) -> String { + let mut final_script = String::new(); + + let variant = match keymap_selection_text_refcell.borrow().clone().variant { + Some(t) => { + t.replace("'", r###"'"'"'"###) + } + None => "".to_string(), + }; + + let standard_installation_format = strfmt::strfmt( + standard_installation_prog, + &std::collections::HashMap::from([ + ("CHROOT_PATH".to_string(), "/media/pikaos/installation"), + ( + "LOCALE".to_string(), + language_selection_text_refcell.borrow().name.replace("'", r###"'"'"'"###).as_str(), + ), + ( + "KEYMAP_BASE".to_string(), + keymap_selection_text_refcell.borrow().name.replace("'", r###"'"'"'"###).as_str(), + ), + ( + "KEYMAP_VARIANT".to_string(), + variant.as_str() + ), + ( + "TIMEZONE".to_string(), + timezone_selection_text_refcell.borrow().replace("'", r###"'"'"'"###).as_str(), + ), + ]), + ) + .unwrap(); + + final_script.push_str(&standard_installation_format); + + match &*partition_method_type_refcell.borrow().as_str() { + "automatic" => { + let is_encrypted = *partition_method_automatic_luks_enabled_refcell.borrow(); + // + let automatic_standard_installation_format = strfmt::strfmt( + auto_basic::automatic_standard_installation_prog, + &std::collections::HashMap::from([ + ( + "AUTO_INSTALL_TARGET_DISK".to_string(), + partition_method_automatic_target_refcell.borrow().block_name.replace("'", r###"'"'"'"###).as_str(), + ), + ]), + ) + .unwrap(); + + final_script.push_str(&automatic_standard_installation_format); + + // + match &*partition_method_automatic_target_fs_refcell.borrow().as_str().to_lowercase() { + "btrfs" => { + match &*partition_method_automatic_seperation_refcell.borrow().as_str() { + "subvol" => { + if is_encrypted { + final_script.push_str(&strfmt::strfmt( + auto_btrfs::automatic_home_subvol_btrfs_locked_installation_prog, + &std::collections::HashMap::from([ + ("CHROOT_PATH".to_string(), "/media/pikaos/installation"), + ( + "AUTO_LUKS_PASSWORD".to_string(), + partition_method_automatic_luks_refcell.borrow().replace("'", r###"'"'"'"###).as_str(), + ) + ]), + ) + .unwrap()); + } else { + final_script.push_str(&strfmt::strfmt( + auto_btrfs::automatic_home_subvol_btrfs_open_installation_prog, + &std::collections::HashMap::from([ + ("CHROOT_PATH".to_string(), "/media/pikaos/installation"), + ]), + ) + .unwrap()); + } + } + "partition" => { + if is_encrypted { + final_script.push_str(&strfmt::strfmt( + auto_btrfs::automatic_home_part_btrfs_locked_installation_prog, + &std::collections::HashMap::from([ + ("CHROOT_PATH".to_string(), "/media/pikaos/installation"), + ( + "AUTO_LUKS_PASSWORD".to_string(), + partition_method_automatic_luks_refcell.borrow().replace("'", r###"'"'"'"###).as_str(), + ), + ( + "ROOT_PART_SIZE_AS_I64_MIB".to_string(), + (partition_method_automatic_ratio_refcell.borrow().round() as i64 / 1048576).to_string().replace("'", r###"'"'"'"###).as_str(), + ) + ]), + ) + .unwrap()); + } else { + final_script.push_str(&strfmt::strfmt( + auto_btrfs::automatic_home_part_btrfs_open_installation_prog, + &std::collections::HashMap::from([ + ("CHROOT_PATH".to_string(), "/media/pikaos/installation"), + ( + "ROOT_PART_SIZE_AS_I64_MIB".to_string(), + (partition_method_automatic_ratio_refcell.borrow().round() as i64 / 1048576).to_string().replace("'", r###"'"'"'"###).as_str(), + ) + ]), + ) + .unwrap()); + } + } + "none" => { + if is_encrypted { + final_script.push_str(&strfmt::strfmt( + auto_btrfs::automatic_home_none_btrfs_locked_installation_prog, + &std::collections::HashMap::from([ + ("CHROOT_PATH".to_string(), "/media/pikaos/installation"), + ( + "AUTO_LUKS_PASSWORD".to_string(), + partition_method_automatic_luks_refcell.borrow().replace("'", r###"'"'"'"###).as_str(), + ) + ]), + ) + .unwrap()); + } else { + final_script.push_str(&strfmt::strfmt( + auto_btrfs::automatic_home_none_btrfs_open_installation_prog, + &std::collections::HashMap::from([ + ("CHROOT_PATH".to_string(), "/media/pikaos/installation"), + ]), + ) + .unwrap()); + } + } + _ => panic!() + } + } + "ext4" => { + match &*partition_method_automatic_seperation_refcell.borrow().as_str() { + "partition" => { + if is_encrypted { + final_script.push_str(&strfmt::strfmt( + auto_ext4::automatic_home_part_ext4_locked_installation_prog, + &std::collections::HashMap::from([ + ("CHROOT_PATH".to_string(), "/media/pikaos/installation"), + ( + "AUTO_LUKS_PASSWORD".to_string(), + partition_method_automatic_luks_refcell.borrow().replace("'", r###"'"'"'"###).as_str(), + ), + ( + "ROOT_PART_SIZE_AS_I64_MIB".to_string(), + (partition_method_automatic_ratio_refcell.borrow().round() as i64 / 1048576).to_string().replace("'", r###"'"'"'"###).as_str(), + ) + ]), + ) + .unwrap()); + } else { + final_script.push_str(&strfmt::strfmt( + auto_ext4::automatic_home_part_ext4_open_installation_prog, + &std::collections::HashMap::from([ + ("CHROOT_PATH".to_string(), "/media/pikaos/installation"), + ( + "ROOT_PART_SIZE_AS_I64_MIB".to_string(), + (partition_method_automatic_ratio_refcell.borrow().round() as i64 / 1048576).to_string().replace("'", r###"'"'"'"###).as_str(), + ) + ]), + ) + .unwrap()); + } + } + "none" => { + if is_encrypted { + final_script.push_str(&strfmt::strfmt( + auto_ext4::automatic_home_none_ext4_locked_installation_prog, + &std::collections::HashMap::from([ + ("CHROOT_PATH".to_string(), "/media/pikaos/installation"), + ( + "AUTO_LUKS_PASSWORD".to_string(), + partition_method_automatic_luks_refcell.borrow().replace("'", r###"'"'"'"###).as_str(), + ) + ]), + ) + .unwrap()); + } else { + final_script.push_str(&strfmt::strfmt( + auto_ext4::automatic_home_none_ext4_open_installation_prog, + &std::collections::HashMap::from([ + ("CHROOT_PATH".to_string(), "/media/pikaos/installation"), + ]), + ) + .unwrap()); + } + } + _ => panic!() + } + } + "xfs" => { + match &*partition_method_automatic_seperation_refcell.borrow().as_str() { + "partition" => { + if is_encrypted { + final_script.push_str(&strfmt::strfmt( + auto_xfs::automatic_home_part_xfs_locked_installation_prog, + &std::collections::HashMap::from([ + ("CHROOT_PATH".to_string(), "/media/pikaos/installation"), + ( + "AUTO_LUKS_PASSWORD".to_string(), + partition_method_automatic_luks_refcell.borrow().replace("'", r###"'"'"'"###).as_str(), + ), + ( + "ROOT_PART_SIZE_AS_I64_MIB".to_string(), + (partition_method_automatic_ratio_refcell.borrow().round() as i64 / 1048576).to_string().replace("'", r###"'"'"'"###).as_str(), + ) + ]), + ) + .unwrap()); + } else { + final_script.push_str(&strfmt::strfmt( + auto_xfs::automatic_home_part_xfs_open_installation_prog, + &std::collections::HashMap::from([ + ("CHROOT_PATH".to_string(), "/media/pikaos/installation"), + ( + "ROOT_PART_SIZE_AS_I64_MIB".to_string(), + (partition_method_automatic_ratio_refcell.borrow().round() as i64 / 1048576).to_string().replace("'", r###"'"'"'"###).as_str(), + ) + ]), + ) + .unwrap()); + } + } + "none" => { + if is_encrypted { + final_script.push_str(&strfmt::strfmt( + auto_xfs::automatic_home_none_xfs_locked_installation_prog, + &std::collections::HashMap::from([ + ("CHROOT_PATH".to_string(), "/media/pikaos/installation"), + ( + "AUTO_LUKS_PASSWORD".to_string(), + partition_method_automatic_luks_refcell.borrow().replace("'", r###"'"'"'"###).as_str(), + ) + ]), + ) + .unwrap()); + } else { + final_script.push_str(&strfmt::strfmt( + auto_xfs::automatic_home_none_xfs_open_installation_prog, + &std::collections::HashMap::from([ + ("CHROOT_PATH".to_string(), "/media/pikaos/installation"), + ]), + ) + .unwrap()); + } + } + _ => panic!() + } + } + _ => panic!() + } + // + if is_encrypted { + final_script.push_str(auto_basic::automatic_locked_part_pikainstall_prog); + } else { + final_script.push_str(auto_basic::automatic_open_part_pikainstall_prog); + } + } + "manual" => { + let is_encrypted = *partition_method_manual_luks_enabled_refcell.borrow(); + + if is_encrypted { + final_script.push_str( +r###" + +mkdir -p /tmp/PIKA_CRYPT/ +touch /tmp/PIKA_CRYPT/crypttab + +"### + ); + + for crypt_entry in partition_method_manual_crypttab_entry_array_refcell.borrow().iter() { + match &crypt_entry.password { + Some(p) => { + final_script.push_str(&strfmt::strfmt( + manual_basic::manual_crypt_entry_with_keyfile, + &std::collections::HashMap::from([ + ( + "MAP".to_string(), + crypt_entry.map.replace("'", r###"'"'"'"###).as_str() + ), + ( + "UUID".to_string(), + crypt_entry.uuid.replace("'", r###"'"'"'"###).as_str() + ), + ( + "LUKS_PASSWD".to_string(), + p.replace("'", r###"'"'"'"###).as_str() + ) + ]), + ) + .unwrap()); + } + None => { + final_script.push_str(&strfmt::strfmt( + manual_basic::manual_crypt_entry, + &std::collections::HashMap::from([ + ( + "MAP".to_string(), + crypt_entry.map.replace("'", r###"'"'"'"###).as_str() + ), + ( + "UUID".to_string(), + crypt_entry.uuid.replace("'", r###"'"'"'"###).as_str() + ) + ]), + ) + .unwrap()); + } + } + }; + } + + let mut did_make_swap_list = false; + + for fstab_entry in partition_method_manual_fstab_entry_array_refcell.borrow().iter() { + if fstab_entry.mountpoint == "[SWAP]" { + if !did_make_swap_list { + final_script.push_str( +r###" + +touch /tmp/pika-installer-gtk4-swaplist + +"### + ); + did_make_swap_list = true + } + final_script.push_str(&strfmt::strfmt( + manual_basic::manual_swap_mount_prog, + &std::collections::HashMap::from([ + ( + "PART".to_string(), + fstab_entry.partition.part_name.replace("'", r###"'"'"'"###).as_str() + ), + ]), + ) + .unwrap()); + } else if !fstab_entry.mountopts.is_empty() { + final_script.push_str(&strfmt::strfmt( + manual_basic::manual_partition_mount_with_opts_prog, + &std::collections::HashMap::from([ + ( + "PART".to_string(), + fstab_entry.partition.part_name.replace("'", r###"'"'"'"###).as_str() + ), + ( + "MOUNTPOINT".to_string(), + fstab_entry.mountpoint.replace("'", r###"'"'"'"###).as_str() + ), + ( + "OPTS".to_string(), + fstab_entry.mountopts.replace("'", r###"'"'"'"###).as_str() + ), + ]), + ) + .unwrap()); + } else { + final_script.push_str(&strfmt::strfmt( + manual_basic::manual_partition_mount_prog, + &std::collections::HashMap::from([ + ( + "PART".to_string(), + fstab_entry.partition.part_name.replace("'", r###"'"'"'"###).as_str() + ), + ( + "MOUNTPOINT".to_string(), + fstab_entry.mountpoint.replace("'", r###"'"'"'"###).as_str() + ), + ]), + ) + .unwrap()); + } + } + + if is_encrypted { + final_script.push_str(manual_basic::manual_locked_part_pikainstall_prog); + } else { + final_script.push_str(manual_basic::manual_open_part_pikainstall_prog); + } + } + _ => panic!() + } + + final_script +} diff --git a/src/main.rs b/src/main.rs index eadf1a0..d171821 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,8 +19,8 @@ mod automatic_partitioning_page; mod manual_partitioning_page; mod partitioning_page; // -mod installation_progress_page; mod installation_summary_page; +mod installation_progress_page; #[macro_use] extern crate rust_i18n; diff --git a/src/style.css b/src/style.css index 7c3fb14..a8f2c59 100644 --- a/src/style.css +++ b/src/style.css @@ -14,7 +14,7 @@ } .small_fg_text { - font-size: 48px; + font-size: 18px; } .big_error_text {