SHA256
Compare commits
6
Commits
| Author | SHA256 | Date | |
|---|---|---|---|
|
|
f404ff385a | ||
|
|
c56da21eab | ||
|
|
ed6ffcdee1 | ||
|
|
4d8c9540d0 | ||
|
|
56e87a62cf | ||
|
|
9769ae409e |
@@ -4,3 +4,4 @@ reqire_network = true
|
||||
|
||||
[partition]
|
||||
min_disk_size_mb = 8192
|
||||
efi_size_mb = 128
|
||||
|
||||
+233
-16
@@ -18,9 +18,9 @@
|
||||
Functions for working with disk layout
|
||||
*/
|
||||
|
||||
use crate::kira_size::KiraSize;
|
||||
use log;
|
||||
use std::collections::HashMap;
|
||||
use crate::kira_size::{KiraSize};
|
||||
use std::{collections::HashMap};
|
||||
///
|
||||
/// size - device size in bytes
|
||||
/// sector size - default 4096
|
||||
@@ -38,6 +38,7 @@ impl std::fmt::Display for BlkDev {
|
||||
}
|
||||
|
||||
impl BlkDev {
|
||||
/// Create new BlkDev struct with specifyed name and size
|
||||
pub fn new(name: String, size: KiraSize) -> Self {
|
||||
Self {
|
||||
name: name,
|
||||
@@ -45,6 +46,9 @@ impl BlkDev {
|
||||
sector_size: KiraSize::new_b(4096),
|
||||
}
|
||||
}
|
||||
|
||||
/// Create new BlkDev struct with name and size parsed from hashmap
|
||||
/// that contains String key val pairs with "NAME" and "SIZE" keys
|
||||
pub fn from_hash_map(data: &HashMap<String, String>) -> Option<Self> {
|
||||
Some(Self {
|
||||
name: data.get("NAME")?.clone(),
|
||||
@@ -52,7 +56,13 @@ impl BlkDev {
|
||||
sector_size: KiraSize::new_b(4096),
|
||||
})
|
||||
}
|
||||
/// returns dev name in a "/dev/name" form
|
||||
pub fn full_name(&self) -> String {
|
||||
format!("/dev/{}", self.name)
|
||||
}
|
||||
|
||||
/// this is blocking function
|
||||
/// Lists block devices in system thru "lsbk" command
|
||||
pub fn list_sys_blk_dev() -> Result<Vec<Self>, String> {
|
||||
use std::process::Command;
|
||||
|
||||
@@ -96,6 +106,11 @@ impl BlkDev {
|
||||
Err(ex) => Err(ex.to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_sys(name: &str) -> Option<Self> {
|
||||
Self::list_sys_blk_dev().ok()?.iter().find(|v| v.name == name).cloned()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
@@ -139,6 +154,22 @@ impl FSType {
|
||||
_ => Self::UNKNOWN,
|
||||
}
|
||||
}
|
||||
|
||||
/// return fs type that can be used with parted utility
|
||||
pub fn to_parted_str(&self) -> &str {
|
||||
match self {
|
||||
Self::VFAT => "fat32",
|
||||
Self::XFS => "xfs",
|
||||
Self::LUKS => "luks",
|
||||
Self::SWAP => "linux-swap",
|
||||
Self::EXT4 => "ext4",
|
||||
Self::BTRFS => "btrfs",
|
||||
// workaroud as parted do not support bcachefs partition type
|
||||
Self::BCACHEFS => "bcachefs",
|
||||
// lets do something generic here instead of panic
|
||||
Self::UNKNOWN => "linux-swap",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// fn part_type_to_color(t: &str) -> Color {
|
||||
@@ -177,13 +208,7 @@ pub struct PartInfo {
|
||||
|
||||
impl std::fmt::Display for PartInfo {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"{} {} {}",
|
||||
&self.name,
|
||||
&self.fs_type,
|
||||
self.size
|
||||
)
|
||||
write!(f, "{} {} {}", &self.name, &self.fs_type, self.size)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,7 +316,8 @@ pub fn align_part(size: u64, start: u64, align: u64) -> Option<(u64, u64, u64)>
|
||||
if align_size < align {
|
||||
log::warn!(
|
||||
"!!! align_size < align !!! align_size: {} align: {}",
|
||||
align_size, align
|
||||
align_size,
|
||||
align
|
||||
);
|
||||
return None;
|
||||
}
|
||||
@@ -299,6 +325,7 @@ pub fn align_part(size: u64, start: u64, align: u64) -> Option<(u64, u64, u64)>
|
||||
Some((align_size, align_start, align_end))
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct PartLayout {
|
||||
pub dev: BlkDev,
|
||||
pub empty_space: KiraSize,
|
||||
@@ -316,7 +343,9 @@ impl PartLayout {
|
||||
|
||||
pub fn read_from_disk(dev: &BlkDev) -> Result<Self, String> {
|
||||
let part_list = get_dev_part_blocking(&dev.name)?;
|
||||
let parts_size = part_list.iter().fold(KiraSize::new_b(0), |acc, part| acc + part.size);
|
||||
let parts_size = part_list
|
||||
.iter()
|
||||
.fold(KiraSize::new_b(0), |acc, part| acc + part.size);
|
||||
Ok(Self {
|
||||
dev: dev.clone(),
|
||||
empty_space: dev.size - parts_size,
|
||||
@@ -377,7 +406,7 @@ impl PartLayout {
|
||||
self.add_part(p_size, fs_type, gpt_label, fs_label, mount_point, role)
|
||||
}
|
||||
|
||||
pub fn gen_classic_layout(dev: BlkDev, efi_size: KiraSize, swap_size: KiraSize) -> Self {
|
||||
pub fn gen_kira_layout(dev: BlkDev, efi_size: KiraSize, swap_size: KiraSize) -> Self {
|
||||
let mut res: PartLayout = PartLayout::new(dev);
|
||||
|
||||
// UEFI partition
|
||||
@@ -385,15 +414,15 @@ impl PartLayout {
|
||||
.add_part(
|
||||
efi_size,
|
||||
FSType::VFAT,
|
||||
Some("efi".into()),
|
||||
Some("bee-efi".into()),
|
||||
Some("EFI".into()),
|
||||
Some("/efi".into()),
|
||||
Some(PartRole::EFI),
|
||||
)
|
||||
.add_part_reserve(
|
||||
swap_size,
|
||||
FSType::XFS,
|
||||
Some("root".into()),
|
||||
FSType::BTRFS,
|
||||
Some("bee-root".into()),
|
||||
None,
|
||||
Some("/".into()),
|
||||
Some(PartRole::ROOT),
|
||||
@@ -415,6 +444,195 @@ impl PartLayout {
|
||||
}
|
||||
}
|
||||
|
||||
/// Executes parted command with given arguments
|
||||
fn exec_parted(args: &Vec<&str>) -> Result<String, String> {
|
||||
use std::process::Command;
|
||||
|
||||
match Command::new("parted").args(args).output() {
|
||||
Err(ex) => Err(ex.to_string()),
|
||||
Ok(out) => {
|
||||
if out.status.success() {
|
||||
String::from_utf8(out.stdout).map_err(|ex| ex.to_string())
|
||||
} else {
|
||||
Err(out.status.to_string())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn parted_get_last_part_num(dev: &BlkDev) -> Result<u32, String> {
|
||||
// parted -m /dev/loop0 print
|
||||
match exec_parted(&vec!["-m", dev.full_name().as_str(), "print"]) {
|
||||
Ok(res) => {
|
||||
match res.lines().last().and_then(|last_line| {
|
||||
last_line
|
||||
.split_once(':')
|
||||
.and_then(|(first_part, _)| u32::from_str_radix(first_part, 10).ok())
|
||||
}) {
|
||||
Some(n) => Ok(n),
|
||||
None => Err("Error parsing parted output".to_string()),
|
||||
}
|
||||
}
|
||||
Err(ex) => Err(ex),
|
||||
}
|
||||
}
|
||||
|
||||
/// init gpt partition table
|
||||
/// parted --script $install_device mklabel gpt
|
||||
/// Its blocking function
|
||||
pub fn parted_init_gpt_part_table(dev: &BlkDev) -> Result<(), String> {
|
||||
exec_parted(&vec![
|
||||
"--script",
|
||||
dev.full_name().as_str(),
|
||||
"mklabel",
|
||||
"gpt",
|
||||
])
|
||||
.map(|_| ())
|
||||
}
|
||||
|
||||
const LINUX_ROOT_X86_64_TYPE: &str = "4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709";
|
||||
|
||||
/// creating partition from PartInfo specification
|
||||
/// It assumes that we add partitions sequentially to empty space (for part attributes settings)
|
||||
/// Otherwise can produce bonkers layout
|
||||
pub fn parted_mkpart(dev: &BlkDev, part: &PartInfo) -> Result<(), String> {
|
||||
let part_end = part.start + part.size;
|
||||
|
||||
// gpt label should be in double qutes
|
||||
let gpt_label = if let Some(s) = &part.gpt_label {
|
||||
format!("\"{}\"", s)
|
||||
} else {
|
||||
"\"\"".to_string()
|
||||
};
|
||||
// creating partition
|
||||
exec_parted(&vec![
|
||||
"--script",
|
||||
dev.full_name().as_str(),
|
||||
"mkpart",
|
||||
gpt_label.as_str(),
|
||||
part.fs_type.to_parted_str(),
|
||||
part.start.to_parted_bytes_str().as_str(),
|
||||
part_end.to_parted_bytes_str().as_str(),
|
||||
])?;
|
||||
|
||||
// set partition options depending on its role
|
||||
if let Some(role) = &part.role {
|
||||
// getting part number of last created partition (hopefully)
|
||||
let part_id = parted_get_last_part_num(dev)?;
|
||||
match role {
|
||||
PartRole::EFI => {
|
||||
exec_parted(&vec![
|
||||
"--script",
|
||||
dev.full_name().as_str(),
|
||||
"set",
|
||||
&part_id.to_string(),
|
||||
"esp",
|
||||
"on",
|
||||
])?;
|
||||
}
|
||||
// parted --script $install_device type 3 4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709
|
||||
PartRole::ROOT => {
|
||||
exec_parted(&vec![
|
||||
"--script",
|
||||
dev.full_name().as_str(),
|
||||
"type",
|
||||
&part_id.to_string(),
|
||||
LINUX_ROOT_X86_64_TYPE,
|
||||
])?;
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
};
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// creating single drive bcachefs volume
|
||||
pub fn bcachefs_format(
|
||||
dev: &BlkDev,
|
||||
compression: Option<String>,
|
||||
password: Option<String>,
|
||||
) -> Result<(), String> {
|
||||
// sudo bcachefs format --compression=lz4 --background_compression=lz4 --encrypted /dev/loop0
|
||||
// --data_checksum=none - do not make sense on single dev volumes
|
||||
// sudo bcachefs format --force --compression=lz4 --background_compression=lz4 --encrypted --passphrase_file=./test.pass /dev/loop0
|
||||
use std::fs;
|
||||
use std::process::Command;
|
||||
|
||||
let mut arg = vec!["format", "--force", "--data_checksum=none"];
|
||||
// if compression algorythm specified
|
||||
if let Some(compresss_alg) = &compression {
|
||||
arg.push(compresss_alg.as_str());
|
||||
}
|
||||
// if we want encrypted volume
|
||||
if let Some(passw) = password {
|
||||
// creating tmp file with password
|
||||
fs::write("/tmp/bzzpsspass.txt", &passw).map_err(|ex| ex.to_string())?;
|
||||
arg.push("--encrypted");
|
||||
arg.push("--passphrase_file=/tmp/bzzpsspass.txt");
|
||||
}
|
||||
|
||||
// add dev name at the end
|
||||
let dev_name = dev.full_name();
|
||||
arg.push(dev_name.as_str());
|
||||
|
||||
let out = Command::new("bcachefs")
|
||||
.args(arg)
|
||||
.output()
|
||||
.map_err(|ex| ex.to_string())?;
|
||||
|
||||
// ignore any errors while deleting pass tmp file
|
||||
let _ = fs::remove_file("/tmp/bzzpsspass.txt");
|
||||
|
||||
if out.status.success() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(String::from_utf8(out.stderr).map_err(|ex| ex.to_string())?)
|
||||
}
|
||||
}
|
||||
|
||||
/// unlok encrypted bcache volume
|
||||
pub fn bcachefs_unlock(dev: &BlkDev, pass: String) -> Result<(), String> {
|
||||
use std::fs;
|
||||
use std::process::Command;
|
||||
|
||||
// bcachefs unlock --file=/tmp/bzzpsspass.txt /dev/loop0
|
||||
let dev_name = dev.full_name();
|
||||
let arg = vec!["unlock", "--file=/tmp/bzzpsspass.txt ", dev_name.as_str()];
|
||||
// creating tmp file with password
|
||||
fs::write("/tmp/bzzpsspass.txt", &pass).map_err(|ex| ex.to_string())?;
|
||||
|
||||
let out = Command::new("bcachefs")
|
||||
.args(arg)
|
||||
.output()
|
||||
.map_err(|ex| ex.to_string())?;
|
||||
// ignore any errors while deleting pass tmp file
|
||||
let _ = fs::remove_file("/tmp/bzzpsspass.txt");
|
||||
|
||||
if out.status.success() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(String::from_utf8(out.stderr).map_err(|ex| ex.to_string())?)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// create subvolume
|
||||
pub fn bcachefs_create_subvolume(vol_path: &str) -> Result<(), String> {
|
||||
use std::process::Command;
|
||||
|
||||
// sudo bcachefs subvolume create /mnt/test/nyan
|
||||
let out = Command::new("bcachefs")
|
||||
.args(["subvolume", "create", vol_path])
|
||||
.output()
|
||||
.map_err(|ex| ex.to_string())?;
|
||||
if out.status.success() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(String::from_utf8(out.stderr).map_err(|ex| ex.to_string())?)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use rand::RngExt;
|
||||
@@ -466,4 +684,3 @@ mod tests {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -46,6 +46,13 @@ impl std::fmt::Display for KiraSize {
|
||||
|
||||
impl KiraSize {
|
||||
pub const SUFFIXS: [&str; 5] = ["KB", "MB", "GB", "TB", "PB"];
|
||||
|
||||
/// returns size in bytes suffixed with "B" character
|
||||
pub fn to_parted_bytes_str(&self)-> String {
|
||||
format!("{}B", self.size_bytes)
|
||||
}
|
||||
|
||||
|
||||
pub fn new_b(size:u64) -> Self {
|
||||
Self { size_bytes: size }
|
||||
}
|
||||
|
||||
+7
-1
@@ -4,7 +4,10 @@
|
||||
"button.next": "Next",
|
||||
"button.back": "Back",
|
||||
"button.cancel": "Cancel",
|
||||
"button.finish": "Finish",
|
||||
"button.exit": "Exit",
|
||||
"button.yes": "Yes",
|
||||
"button.no": "No",
|
||||
"wellcome.text": "Welcome to Kira Installer!",
|
||||
"wellcome.choose_language": "Please select language to use during istalation!",
|
||||
"license.license": "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.\n\nThis 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.\n\nYou should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.",
|
||||
@@ -37,6 +40,7 @@
|
||||
"partition.select_swapmode": "Select swap partition mode",
|
||||
"partition.use_zram": "Use zram technology",
|
||||
"partition.use_secure_boot": "Setup secure boot",
|
||||
"partition.encrypt_drive": "Encrypt drive",
|
||||
"partition.current_dev_layout": "Current device layout",
|
||||
"partition.current_after_install": "After installation device will look like this",
|
||||
"security.user_name": "User login name",
|
||||
@@ -46,5 +50,7 @@
|
||||
"security.root_password": "Root password",
|
||||
"security.pass_low": "low security",
|
||||
"security.pass_middle": "normal security",
|
||||
"security.pass_hight": "hight security"
|
||||
"security.pass_hight": "hight security",
|
||||
"install.caption": "Now we will beee install Bzz Linux to your PC",
|
||||
"install.warning": "We a ready to start installation, this action will destroy all data on select drive!\nDo you want to proceed?"
|
||||
}
|
||||
+95
-66
@@ -18,87 +18,116 @@
|
||||
This file contains basic enums and structs to be used with stages.
|
||||
*/
|
||||
|
||||
use std::collections::HashMap;
|
||||
use crate::stages;
|
||||
|
||||
// #[derive(Debug, Clone)]
|
||||
// pub enum ConfigValue {
|
||||
// String(String),
|
||||
// I64(i64),
|
||||
// U64(u64),
|
||||
// F64(f64),
|
||||
// Bool(bool),
|
||||
// PartLayout(PartLayout),
|
||||
// KiraSize(KiraSize),
|
||||
// Vector(Vec<ConfigValue>),
|
||||
// Dictionary(HashMap<String, ConfigValue>),
|
||||
// }
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum ConfigValue {
|
||||
String(String),
|
||||
I64(i64),
|
||||
U64(u64),
|
||||
F64(f64),
|
||||
Bool(bool),
|
||||
Vector(Vec<ConfigValue>),
|
||||
Dictionary(HashMap<String, ConfigValue>),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct StageResult {
|
||||
pub name: String,
|
||||
pub config: Option<HashMap<String, ConfigValue>>,
|
||||
pub error: Option<String>,
|
||||
pub enum StageResult {
|
||||
WelcomeStageResult(stages::welcome::WelcomeStageResult),
|
||||
NetworkStageResult(stages::network::NetworkStageResult),
|
||||
LocaleStageResult(stages::locale::LocaleStageResult),
|
||||
TimeZoneStageResult(stages::timezone::TimeZoneStageResult),
|
||||
KeyboardStageResult(stages::keyboard::KeyboardStageResult),
|
||||
SecurityStageResult(stages::security::SecurityStageResult),
|
||||
PartitionStageResult(stages::partition::PartitionStageResult),
|
||||
None,
|
||||
}
|
||||
|
||||
impl StageResult {
|
||||
pub fn new(name: &str) -> Self {
|
||||
Self {
|
||||
name: name.into(),
|
||||
config: None,
|
||||
error: None,
|
||||
pub fn name(&self) -> String {
|
||||
match self {
|
||||
Self::LocaleStageResult(_) => "locale".into(),
|
||||
Self::WelcomeStageResult(_) => "welcome".into(),
|
||||
Self::NetworkStageResult(_) => "network".into(),
|
||||
Self::TimeZoneStageResult(_) => "timezone".into(),
|
||||
Self::KeyboardStageResult(_) => "keyboard".into(),
|
||||
Self::PartitionStageResult(_) => "partition".into(),
|
||||
Self::SecurityStageResult(_) => "security".into(),
|
||||
Self::None => "none".into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
// impl StageResult {
|
||||
// pub fn new(name: &str) -> Self {
|
||||
// Self {
|
||||
// name: name.into(),
|
||||
// config: None,
|
||||
// error: None,
|
||||
// }
|
||||
// }
|
||||
|
||||
pub fn add_error(mut self, ex: String) -> Self {
|
||||
self.error = Some(ex);
|
||||
self
|
||||
}
|
||||
// pub fn add_error(mut self, ex: String) -> Self {
|
||||
// self.error = Some(ex);
|
||||
// self
|
||||
// }
|
||||
|
||||
pub fn add_val(mut self, val_name: &str, conf_val: ConfigValue) -> Self {
|
||||
match &mut self.config {
|
||||
Some(c) => {
|
||||
c.insert(val_name.into(), conf_val);
|
||||
}
|
||||
None => {
|
||||
self.config = Some(HashMap::from([(val_name.into(), conf_val)]));
|
||||
}
|
||||
}
|
||||
self
|
||||
}
|
||||
// pub fn add_val(mut self, val_name: &str, conf_val: ConfigValue) -> Self {
|
||||
// match &mut self.config {
|
||||
// Some(c) => {
|
||||
// c.insert(val_name.into(), conf_val);
|
||||
// }
|
||||
// None => {
|
||||
// self.config = Some(HashMap::from([(val_name.into(), conf_val)]));
|
||||
// }
|
||||
// }
|
||||
// self
|
||||
// }
|
||||
|
||||
pub fn add_val_string(self, val_name: &str, v: String) -> Self {
|
||||
self.add_val(val_name, ConfigValue::String(v))
|
||||
}
|
||||
// pub fn add_val_string(self, val_name: &str, v: String) -> Self {
|
||||
// self.add_val(val_name, ConfigValue::String(v))
|
||||
// }
|
||||
|
||||
pub fn add_val_bool(self, val_name: &str, v: bool) -> Self {
|
||||
self.add_val(val_name, ConfigValue::Bool(v))
|
||||
}
|
||||
// pub fn add_val_bool(self, val_name: &str, v: bool) -> Self {
|
||||
// self.add_val(val_name, ConfigValue::Bool(v))
|
||||
// }
|
||||
|
||||
pub fn add_val_u64(self, val_name: &str, v: u64) -> Self {
|
||||
self.add_val(val_name, ConfigValue::U64(v))
|
||||
}
|
||||
// pub fn add_val_u64(self, val_name: &str, v: u64) -> Self {
|
||||
// self.add_val(val_name, ConfigValue::U64(v))
|
||||
// }
|
||||
|
||||
pub fn get_val(&self, val_name: &str) -> Option<ConfigValue> {
|
||||
let v = self
|
||||
.config
|
||||
.as_ref()
|
||||
.and_then(|hm| hm.get(val_name).cloned());
|
||||
return v;
|
||||
}
|
||||
// pub fn get_val(&self, val_name: &str) -> Option<ConfigValue> {
|
||||
// let v = self
|
||||
// .config
|
||||
// .as_ref()
|
||||
// .and_then(|hm| hm.get(val_name).cloned());
|
||||
// return v;
|
||||
// }
|
||||
|
||||
pub fn get_val_str(&self, val_name: &str) -> Option<String> {
|
||||
match self.get_val(val_name) {
|
||||
Some(ConfigValue::String(v)) => Some(v),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
// pub fn get_val_str(&self, val_name: &str) -> Option<String> {
|
||||
// match self.get_val(val_name) {
|
||||
// Some(ConfigValue::String(v)) => Some(v),
|
||||
// _ => None,
|
||||
// }
|
||||
// }
|
||||
|
||||
pub fn get_val_bool(&self, val_name: &str) -> Option<bool> {
|
||||
match self.get_val(val_name) {
|
||||
Some(ConfigValue::Bool(v)) => Some(v),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
// pub fn get_val_bool(&self, val_name: &str) -> Option<bool> {
|
||||
// match self.get_val(val_name) {
|
||||
// Some(ConfigValue::Bool(v)) => Some(v),
|
||||
// _ => None,
|
||||
// }
|
||||
// }
|
||||
|
||||
// pub fn get_val_part_layout(&self, val_name: &str) -> Option<PartLayout> {
|
||||
// match self.get_val(val_name) {
|
||||
// Some(ConfigValue::PartLayout(v)) => Some(v),
|
||||
// _ => None,
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct KiraConfig {
|
||||
pub config_trail: Vec<StageResult>,
|
||||
}
|
||||
@@ -115,7 +144,7 @@ impl KiraConfig {
|
||||
pub fn get_stage(&self, name: &str) -> Option<StageResult> {
|
||||
self.config_trail
|
||||
.iter()
|
||||
.find(|v| v.name == name)
|
||||
.find(|v| v.name() == name)
|
||||
.and_then(|v| Some(v.clone()))
|
||||
}
|
||||
pub fn pop_last(&mut self) -> Option<StageResult> {
|
||||
|
||||
@@ -0,0 +1,217 @@
|
||||
// <Kira Installer - universal Linux installer.>
|
||||
// Copyright (C) <2026> <Kira Foundation>
|
||||
|
||||
// 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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
/*
|
||||
Actual installation script.
|
||||
*/
|
||||
|
||||
///
|
||||
/// So. I am goind to make dir structure lile this
|
||||
/// /bzz/root
|
||||
/// /bzz/home
|
||||
/// Mount root from it and binmount home
|
||||
///
|
||||
|
||||
use log;
|
||||
use crate::{
|
||||
kira_disk_layout::{self, BlkDev, PartLayout}, kira_size::KiraSize, kira_theming, stage::{KiraConfig, StageAction, StageResult}
|
||||
};
|
||||
use iced::{Alignment, Task, futures::{self, SinkExt}, widget};
|
||||
use rust_i18n::t;
|
||||
use iced::futures::channel::mpsc::{Sender};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
enum InstallationState {
|
||||
UserConfirmDialog,
|
||||
Partitionning,
|
||||
CopyFiles,
|
||||
Configuring,
|
||||
Finish,
|
||||
Error,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct InstallStage {
|
||||
state: InstallationState,
|
||||
progress: f32,
|
||||
progress_message: String,
|
||||
kira_config: KiraConfig,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Message {
|
||||
UserConfirms,
|
||||
UserDenies,
|
||||
StartPartitioning,
|
||||
UpdateProgress(Result<(f32, String), String>),
|
||||
PartitioningFinish(Result<(), String>),
|
||||
Back,
|
||||
Cancel,
|
||||
Finish,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Update {
|
||||
StgAct(StageAction),
|
||||
Task(Task<Message>),
|
||||
}
|
||||
|
||||
|
||||
fn partition_disk(disk_layout: PartLayout, password: Option<String>) -> impl futures::Stream<Item = Result<(f32, String), String>> {
|
||||
use blocking;
|
||||
|
||||
iced::stream::channel(100, |mut output: Sender<Result<(f32, String), String>>| async move {
|
||||
for i in 0..=1000 {
|
||||
//sleep(Duration::from_millis(10)).await;
|
||||
let dev = disk_layout.dev.clone();
|
||||
// creating gpt partition table
|
||||
match output.send(blocking::unblock(move || kira_disk_layout::parted_init_gpt_part_table(&dev)).await.and(Ok((1.0f32, String::new())))).await {
|
||||
Err(ex) =>{
|
||||
log::error!("Error creating GPT partition table: {}", ex.to_string());
|
||||
return;
|
||||
},
|
||||
_ => ()
|
||||
};
|
||||
|
||||
// Check if send fails (receiver dropped/cancelled)
|
||||
// if output.send(res).await.is_err() {
|
||||
// return; // Exit early if UI is gone
|
||||
// }
|
||||
}
|
||||
|
||||
// Optional: Send completion or error state here
|
||||
// output.send(Message::WorkFailed).await.ok();
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
impl InstallStage {
|
||||
pub fn new(config: &KiraConfig) -> Self {
|
||||
Self {
|
||||
state: InstallationState::UserConfirmDialog,
|
||||
progress: 0.0,
|
||||
progress_message: String::new(),
|
||||
kira_config: config.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
fn gen_result(&self) -> StageResult {
|
||||
StageResult::None
|
||||
}
|
||||
|
||||
pub fn update(&mut self, message: Message) -> Update {
|
||||
match message {
|
||||
Message::UserDenies => Update::StgAct(StageAction::Back),
|
||||
Message::UserConfirms => {
|
||||
// starting installation process here
|
||||
let part_data = self.kira_config.config_trail.iter().find_map(|v| match v {
|
||||
StageResult::PartitionStageResult(res) => Some(res.clone()),
|
||||
_ => None,
|
||||
}).unwrap();
|
||||
self.state = InstallationState::Partitionning;
|
||||
let disk_layout = part_data.part_layout.clone();
|
||||
let disk_password = part_data.password.clone();
|
||||
|
||||
|
||||
Update::Task(Task::run(partition_disk(disk_layout, disk_password), Message::UpdateProgress))
|
||||
//Update::Task(Task::perform(, Message::PartitioningFinish))
|
||||
}
|
||||
Message::StartPartitioning => Update::StgAct(StageAction::None),
|
||||
Message::PartitioningFinish(res) => Update::StgAct(StageAction::None),
|
||||
Message::UpdateProgress(maybe_msg) => {
|
||||
match maybe_msg {
|
||||
Ok((progress, msg))=> {
|
||||
self.progress = progress;
|
||||
self.progress_message = msg;
|
||||
Update::StgAct(StageAction::None)
|
||||
}
|
||||
Err(ex) => {
|
||||
log::error!("{}", &ex);
|
||||
self.state = InstallationState::Error;
|
||||
Update::StgAct(StageAction::None)
|
||||
}
|
||||
}
|
||||
//Update::StgAct(StageAction::None)
|
||||
|
||||
},
|
||||
Message::Cancel => Update::StgAct(StageAction::Abort),
|
||||
Message::Back => Update::StgAct(StageAction::Back),
|
||||
Message::Finish => Update::StgAct(StageAction::None),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn view(&self) -> iced::Element<'_, Message> {
|
||||
let action_button = if self.state == InstallationState::Finish {
|
||||
widget::button(widget::text(t!("button.finish"))).on_press(Message::Finish)
|
||||
} else {
|
||||
widget::button(widget::text(t!("button.cancel"))).on_press(Message::Cancel)
|
||||
};
|
||||
|
||||
// Embed the image bytes into the executable
|
||||
let welcom_logo_handle = widget::image::Handle::from_bytes(kira_theming::get_logo_bytes());
|
||||
|
||||
let main_content = widget::column![
|
||||
widget::container(
|
||||
widget::column![
|
||||
widget::image(welcom_logo_handle)
|
||||
.width(iced::Pixels(128.0))
|
||||
.height(iced::Pixels(128.0)),
|
||||
widget::text(t!("install.caption")),
|
||||
widget::progress_bar(0.0..=100.0, self.progress),
|
||||
widget::text(self.progress_message.clone()),
|
||||
]
|
||||
.padding(10)
|
||||
.spacing(10)
|
||||
.align_x(Alignment::Center)
|
||||
)
|
||||
.height(iced::Length::Fill)
|
||||
.width(iced::Length::Fill)
|
||||
.align_x(Alignment::Center)
|
||||
.align_y(Alignment::Center),
|
||||
widget::container(action_button)
|
||||
.width(iced::Length::Fill)
|
||||
.align_y(Alignment::End)
|
||||
.padding(10),
|
||||
]
|
||||
.align_x(Alignment::Center)
|
||||
.spacing(10);
|
||||
|
||||
let page_stack = widget::Stack::with_capacity(2).push(main_content);
|
||||
|
||||
if self.state == InstallationState::UserConfirmDialog {
|
||||
page_stack
|
||||
.push(
|
||||
widget::column![
|
||||
widget::text(t!("install.warning")),
|
||||
widget::row![
|
||||
widget::button(widget::text(t!("button.no")))
|
||||
.on_press(Message::UserDenies),
|
||||
widget::space::horizontal(), // Pushes the right button to the far right
|
||||
widget::button(widget::text(t!("button.yes")))
|
||||
.on_press(Message::UserConfirms)
|
||||
]
|
||||
.width(iced::Length::Fill)
|
||||
.align_y(Alignment::End)
|
||||
.padding(10)
|
||||
]
|
||||
.align_x(Alignment::Center),
|
||||
)
|
||||
.into()
|
||||
} else {
|
||||
page_stack.into()
|
||||
}
|
||||
}
|
||||
}
|
||||
+14
-11
@@ -18,10 +18,10 @@
|
||||
This is Keyboar stage, used to select Keyboard Layouts
|
||||
*/
|
||||
|
||||
use log;
|
||||
use crate::kira_scroll_list::{self, ListViewMessage};
|
||||
use crate::stage::{StageAction, StageResult};
|
||||
use iced::{Alignment, Length, widget};
|
||||
use log;
|
||||
use rust_i18n::t;
|
||||
use std::collections::HashMap;
|
||||
|
||||
@@ -124,6 +124,12 @@ pub struct KeyboardStage {
|
||||
// selected_kbd_layout_id: Option<usize>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct KeyboardStageResult {
|
||||
pub keyboard_model: KeyboarModel,
|
||||
pub keyboard_layout: KeyboarLayout,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Message {
|
||||
SelectKeyboardModel(KeyboarModel),
|
||||
@@ -274,16 +280,13 @@ impl KeyboardStage {
|
||||
}
|
||||
|
||||
fn gen_result(&self) -> StageResult {
|
||||
if let Some(model) = &self.model
|
||||
&& let Some(k_l) = &self.keyboard_layout
|
||||
{
|
||||
StageResult::new("keyboard")
|
||||
.add_val_string("model", model.model.clone())
|
||||
.add_val_string("layout", k_l.to_result())
|
||||
} else {
|
||||
StageResult::new("keyboard")
|
||||
.add_error("Something go terrible wrong, there is no keyboard layouts.".into())
|
||||
}
|
||||
StageResult::KeyboardStageResult(KeyboardStageResult {
|
||||
keyboard_model: self.model.clone().expect("Keyboard model must be choosed!"),
|
||||
keyboard_layout: self
|
||||
.keyboard_layout
|
||||
.clone()
|
||||
.expect("Keyboard layout must be choosed!"),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn update(&mut self, message: Message) -> StageAction {
|
||||
|
||||
@@ -43,8 +43,7 @@ pub enum Message {
|
||||
|
||||
impl LicenseStage {
|
||||
fn accepted() -> StageResult {
|
||||
StageResult::new("license")
|
||||
.add_val_bool("accepted", true)
|
||||
StageResult::None
|
||||
}
|
||||
|
||||
pub fn update(&mut self, message: Message) -> stage::StageAction {
|
||||
|
||||
+22
-12
@@ -20,7 +20,7 @@
|
||||
|
||||
use crate::{
|
||||
kira_theming,
|
||||
stage::{ConfigValue, KiraConfig, StageAction, StageResult},
|
||||
stage::{KiraConfig, StageAction, StageResult},
|
||||
};
|
||||
use iced::{Alignment, widget};
|
||||
use rust_i18n::t;
|
||||
@@ -138,6 +138,12 @@ pub struct LocaleStage {
|
||||
all_locale_text: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct LocaleStageResult {
|
||||
pub lang_locale: LocaleData,
|
||||
pub formats_locale: LocaleData,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Message {
|
||||
SelectLangLocale(LocaleData),
|
||||
@@ -149,9 +155,10 @@ pub enum Message {
|
||||
impl LocaleStage {
|
||||
pub fn new(kira_config: &KiraConfig) -> Self {
|
||||
// get seelctet language code from welcome stage
|
||||
let maybe_lang = kira_config
|
||||
.get_stage("welcome")
|
||||
.and_then(|v| v.config.and_then(|v| v.get("loc_code").cloned()));
|
||||
let maybe_lang = kira_config.config_trail.iter().find_map(|v| match v {
|
||||
StageResult::WelcomeStageResult(res) => Some(res.loc_code.clone()),
|
||||
_ => None,
|
||||
});
|
||||
|
||||
let raw_loc_codes = get_locales_codes_list_blocking().unwrap();
|
||||
let raw_loc_descr = get_locales_description_blocking().unwrap();
|
||||
@@ -174,7 +181,9 @@ impl LocaleStage {
|
||||
.collect();
|
||||
|
||||
// if we get lang code from wellcome stage, try to fing match with system locales
|
||||
let lang_match = if let Some(ConfigValue::String(lang)) = maybe_lang && lang != "en" {
|
||||
let lang_match = if let Some(lang) = maybe_lang
|
||||
&& lang != "en"
|
||||
{
|
||||
let lang = lang.replace("-", "_").to_lowercase();
|
||||
locales
|
||||
.iter()
|
||||
@@ -208,15 +217,16 @@ impl LocaleStage {
|
||||
if let Some(lang_locale) = &self.lang_locale
|
||||
&& let Some(formats_locale) = &self.formats_locale
|
||||
{
|
||||
StageResult::new("locale")
|
||||
.add_val_string("lang_locale", lang_locale.code.clone())
|
||||
.add_val_string("formats_locale", formats_locale.code.clone())
|
||||
|
||||
StageResult::LocaleStageResult(LocaleStageResult {
|
||||
lang_locale: lang_locale.clone(),
|
||||
formats_locale: formats_locale.clone(),
|
||||
})
|
||||
} else {
|
||||
let loc = LocaleData::default();
|
||||
StageResult::new("locale")
|
||||
.add_val_string("lang_locale", loc.code.clone())
|
||||
.add_val_string("formats_locale", loc.code)
|
||||
StageResult::LocaleStageResult(LocaleStageResult {
|
||||
lang_locale: loc.clone(),
|
||||
formats_locale: loc,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,3 +23,4 @@ pub mod locale;
|
||||
pub mod keyboard;
|
||||
pub mod partition;
|
||||
pub mod security;
|
||||
pub mod install;
|
||||
@@ -19,17 +19,16 @@
|
||||
it needed for installation to process.
|
||||
*/
|
||||
|
||||
use log;
|
||||
use iced::{Alignment, Task, widget};
|
||||
use iced_moving_picture::widget::apng;
|
||||
use log;
|
||||
use rust_i18n::t;
|
||||
use toml::Table;
|
||||
|
||||
use crate::stage;
|
||||
use crate::stage::StageResult;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(PartialEq, Eq)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum State {
|
||||
Cheking,
|
||||
Normal,
|
||||
@@ -53,6 +52,12 @@ pub struct NetworkStage {
|
||||
status_message: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct NetworkStageResult {
|
||||
pub internet_active: bool,
|
||||
pub use_net_settings: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Message {
|
||||
Next,
|
||||
@@ -127,9 +132,10 @@ impl NetworkStage {
|
||||
}
|
||||
|
||||
fn gen_result(&self) -> StageResult {
|
||||
StageResult::new("network")
|
||||
.add_val_bool("internet_active", self.internet_active)
|
||||
.add_val_bool("use_net_settings", self.use_net_settings)
|
||||
StageResult::NetworkStageResult(NetworkStageResult {
|
||||
internet_active: self.internet_active,
|
||||
use_net_settings: self.use_net_settings,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn update(&mut self, message: Message) -> UpdateResult {
|
||||
|
||||
+67
-33
@@ -68,6 +68,8 @@ fn part_type_to_color(t: &FSType) -> Color {
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts PartInfo into data for ColorBar widget
|
||||
///
|
||||
fn part_to_ct_params(part: &PartInfo, dev_size: KiraSize) -> (String, u16, Color) {
|
||||
let fill_ratio: u16 = ((part.size.b() as f32 / dev_size.b() as f32) * 11.0) as u16;
|
||||
let fill_ratio = fill_ratio.max(1);
|
||||
@@ -75,28 +77,50 @@ fn part_to_ct_params(part: &PartInfo, dev_size: KiraSize) -> (String, u16, Color
|
||||
(part.to_string(), fill_ratio, part_color)
|
||||
}
|
||||
|
||||
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct PartitionStageResult {
|
||||
pub swap_mode: SwapMode,
|
||||
pub swap_size: KiraSize,
|
||||
pub efi_size: KiraSize,
|
||||
pub use_zram: bool,
|
||||
pub secure_boot: bool,
|
||||
pub encrypt_drive: bool,
|
||||
pub password: Option<String>,
|
||||
pub part_layout: PartLayout,
|
||||
}
|
||||
|
||||
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct PartitionStage {
|
||||
device: Option<BlkDev>,
|
||||
devices: Vec<BlkDev>,
|
||||
swap_mode: Option<SwapMode>,
|
||||
efi_size: KiraSize,
|
||||
use_zram: bool,
|
||||
secure_boot: bool,
|
||||
encrypt_drive: bool,
|
||||
secure_boot_in_setup_mode: bool,
|
||||
custom_swap_size_mb: u32,
|
||||
custom_swap_size_str: String,
|
||||
selected_disk_parts: Option<Vec<(String, u16, Color)>>,
|
||||
generated_disk_parts: Option<Vec<(String, u16, Color)>>,
|
||||
generated_part_layout: Option<PartLayout>,
|
||||
system_ram_size: KiraSize,
|
||||
vram_of_all_gpus_size: KiraSize,
|
||||
}
|
||||
|
||||
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Message {
|
||||
SelectDevice(BlkDev),
|
||||
SelectSwapMode(SwapMode),
|
||||
ToggleZram(bool),
|
||||
ToggleSecureBoot(bool),
|
||||
ToggleEncrypDrive(bool),
|
||||
SwapSizeFieldChange(String),
|
||||
SwapSizeIncrement,
|
||||
SwapSizeDecrement,
|
||||
@@ -108,15 +132,24 @@ impl PartitionStage {
|
||||
pub fn new(toml_config: &Table) -> Result<Self, String> {
|
||||
let maybe_dev_list = BlkDev::list_sys_blk_dev();
|
||||
log::info!("hiii from partition");
|
||||
let min_disk_size_mb = toml_config
|
||||
let mut min_disk_size_mb = 8192;
|
||||
let mut efi_size_mb = 128;
|
||||
if let Some(part_table) = toml_config
|
||||
.get("partition")
|
||||
.and_then(|v| v.as_table())
|
||||
.and_then(|v| v.get("min_disk_size_mb"))
|
||||
.and_then(|v| v.as_table()) {
|
||||
|
||||
min_disk_size_mb = part_table.get("min_disk_size_mb")
|
||||
.and_then(|v| v.as_integer())
|
||||
.unwrap_or(8192);
|
||||
|
||||
let min_disk_size: KiraSize = KiraSize::new_mb(min_disk_size_mb.try_into().unwrap_or(8192));
|
||||
efi_size_mb = part_table.get("efi_size_mb")
|
||||
.and_then(|v| v.as_integer())
|
||||
.unwrap_or(128);
|
||||
|
||||
}
|
||||
|
||||
let min_disk_size: KiraSize = KiraSize::new_mb(min_disk_size_mb.try_into().unwrap_or(8192));
|
||||
let efi_size: KiraSize = KiraSize::new_mb(efi_size_mb.try_into().unwrap_or(128));
|
||||
|
||||
let sec_boot_setup = match kira_sysinfo::get_secure_boot_status() {
|
||||
Ok(sb_status) => sb_status.setup_mode,
|
||||
@@ -152,11 +185,14 @@ impl PartitionStage {
|
||||
swap_mode: Some(SwapMode::SwapNoHibernate),
|
||||
use_zram: true,
|
||||
secure_boot: false,
|
||||
encrypt_drive: false,
|
||||
secure_boot_in_setup_mode: sec_boot_setup,
|
||||
custom_swap_size_mb: 1024,
|
||||
custom_swap_size_str: "1024MB".into(),
|
||||
efi_size: efi_size,
|
||||
selected_disk_parts: None,
|
||||
generated_disk_parts: None,
|
||||
generated_part_layout:None,
|
||||
system_ram_size: system_ram_size,
|
||||
vram_of_all_gpus_size: vram_of_all_gpus_size,
|
||||
})
|
||||
@@ -204,35 +240,24 @@ impl PartitionStage {
|
||||
fn gen_layout(&mut self) {
|
||||
if let Some(dev) = self.device.clone() {
|
||||
let swap_size: KiraSize = self.get_swap_size();
|
||||
self.generated_disk_parts = Some(
|
||||
PartLayout::gen_classic_layout(dev.clone(), KiraSize::new_mb(512), swap_size)
|
||||
.part_list
|
||||
let patr_layout = PartLayout::gen_kira_layout(dev.clone(), self.efi_size, swap_size);
|
||||
self.generated_disk_parts = Some(patr_layout.part_list
|
||||
.iter()
|
||||
.map(|part_info| part_to_ct_params(part_info, dev.size))
|
||||
.collect(),
|
||||
);
|
||||
self.generated_part_layout = Some(patr_layout);
|
||||
}
|
||||
}
|
||||
|
||||
fn gen_result(&self) -> StageResult {
|
||||
let swap_size: KiraSize = self.get_swap_size();
|
||||
let dev_name = self
|
||||
.device
|
||||
.clone()
|
||||
.expect("Device should be selected!")
|
||||
.name;
|
||||
StageResult::new("partition")
|
||||
.add_val_string("device", dev_name)
|
||||
.add_val_string(
|
||||
"swap_mode",
|
||||
self.swap_mode
|
||||
.clone()
|
||||
.unwrap_or(SwapMode::NoSwap)
|
||||
.to_string(),
|
||||
)
|
||||
.add_val_u64("swap_size_mb", swap_size.mb())
|
||||
.add_val_bool("use_zram", self.use_zram)
|
||||
.add_val_bool("secure_boot", self.secure_boot)
|
||||
let disk_layout = self.generated_part_layout.clone().expect("Layout must be generated!");
|
||||
|
||||
StageResult::PartitionStageResult(PartitionStageResult { swap_mode: self.swap_mode.clone().unwrap(),
|
||||
swap_size: self.get_swap_size(), efi_size: self.efi_size,
|
||||
use_zram: self.use_zram, secure_boot: self.secure_boot, encrypt_drive: true,
|
||||
password: Some("123456".to_string()), part_layout: disk_layout })
|
||||
|
||||
}
|
||||
|
||||
pub fn update(&mut self, message: Message) -> StageAction {
|
||||
@@ -252,17 +277,18 @@ impl PartitionStage {
|
||||
}
|
||||
};
|
||||
|
||||
let swap_size: KiraSize = self.get_swap_size();
|
||||
// let swap_size: KiraSize = self.get_swap_size();
|
||||
|
||||
self.generated_disk_parts = Some(
|
||||
PartLayout::gen_classic_layout(dev.clone(), KiraSize::new_mb(512), swap_size)
|
||||
.part_list
|
||||
.iter()
|
||||
.map(|part_info| part_to_ct_params(part_info, dev.size))
|
||||
.collect(),
|
||||
);
|
||||
// self.generated_disk_parts = Some(
|
||||
// PartLayout::gen_kira_layout(dev.clone(), self.efi_size, swap_size)
|
||||
// .part_list
|
||||
// .iter()
|
||||
// .map(|part_info| part_to_ct_params(part_info, dev.size))
|
||||
// .collect(),
|
||||
// );
|
||||
|
||||
self.device = Some(dev);
|
||||
self.gen_layout();
|
||||
StageAction::None
|
||||
},
|
||||
Message::SelectSwapMode(sm) => {
|
||||
@@ -274,6 +300,10 @@ impl PartitionStage {
|
||||
self.secure_boot = t;
|
||||
StageAction::None
|
||||
},
|
||||
Message::ToggleEncrypDrive(t) => {
|
||||
self.encrypt_drive = t;
|
||||
StageAction::None
|
||||
},
|
||||
Message::ToggleZram(t) => {
|
||||
self.use_zram = t;
|
||||
self.gen_layout();
|
||||
@@ -376,6 +406,10 @@ impl PartitionStage {
|
||||
widget::rule::horizontal(2),
|
||||
use_sec_boot_checkbox,
|
||||
widget::rule::horizontal(2),
|
||||
widget::checkbox(self.encrypt_drive)
|
||||
.label(t!("partition.encrypt_drive"))
|
||||
.on_toggle(Message::ToggleEncrypDrive),
|
||||
widget::rule::horizontal(2),
|
||||
selected_dev_content,
|
||||
dev_parts_content,
|
||||
]
|
||||
|
||||
@@ -71,6 +71,14 @@ pub struct SecurityStage {
|
||||
root_password_strenght: PasswordStrenght,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct SecurityStageResult {
|
||||
pub user_name: String,
|
||||
pub user_full_name: String,
|
||||
pub user_password: String,
|
||||
pub root_password: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Message {
|
||||
ToggleReusePass(bool),
|
||||
@@ -108,12 +116,12 @@ impl SecurityStage {
|
||||
}
|
||||
|
||||
fn gen_result(&self) -> StageResult {
|
||||
StageResult::new("security")
|
||||
.add_val_string("user_name", self.user_name.clone())
|
||||
.add_val_string("user_full_name", self.user_full_name.clone())
|
||||
.add_val_string("user_full_name", self.user_full_name.clone())
|
||||
.add_val_string("user_password", self.user_password.clone())
|
||||
.add_val_string("root_password", self.root_password.clone())
|
||||
StageResult::SecurityStageResult(SecurityStageResult {
|
||||
user_name: self.user_name.clone(),
|
||||
user_full_name: self.user_full_name.clone(),
|
||||
user_password: self.user_password.clone(),
|
||||
root_password: self.root_password.clone(),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn update(&mut self, message: Message) -> StageAction {
|
||||
|
||||
+17
-10
@@ -18,9 +18,9 @@
|
||||
This is TimeZone stage, used to select timezone
|
||||
*/
|
||||
|
||||
use log;
|
||||
use crate::stage::{StageAction, StageResult};
|
||||
use iced::{Alignment, Length, widget};
|
||||
use log;
|
||||
use rust_i18n::t;
|
||||
use std::collections::HashMap;
|
||||
|
||||
@@ -60,6 +60,11 @@ pub struct TimeZoneStage {
|
||||
selected_zone_text: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct TimeZoneStageResult {
|
||||
pub time_zone: TimeZoneData,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Message {
|
||||
SelectRegion(kira_scroll_list::ListViewMessage),
|
||||
@@ -146,14 +151,12 @@ impl TimeZoneStage {
|
||||
}
|
||||
|
||||
fn gen_result(&self) -> StageResult {
|
||||
if let Some(time_zone) = &self.selected_zone {
|
||||
StageResult::new("time_zone")
|
||||
.add_val_string("name", time_zone.to_string())
|
||||
.add_val_string("region", time_zone.region.clone())
|
||||
.add_val_string("zone", time_zone.zone.clone())
|
||||
} else {
|
||||
StageResult::new("time_zone")
|
||||
}
|
||||
StageResult::TimeZoneStageResult(TimeZoneStageResult {
|
||||
time_zone: self
|
||||
.selected_zone
|
||||
.clone()
|
||||
.expect("Timezone must be selected!"),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn update(&mut self, message: Message) -> StageAction {
|
||||
@@ -201,7 +204,11 @@ impl TimeZoneStage {
|
||||
widget::row![
|
||||
kira_scroll_list::list_view(&self.regions, self.region_id, Length::Shrink)
|
||||
.map(Message::SelectRegion),
|
||||
kira_scroll_list::list_view(&self.zones, self.zone_id, Length::FillPortion(1))
|
||||
kira_scroll_list::list_view(
|
||||
&self.zones,
|
||||
self.zone_id,
|
||||
Length::FillPortion(1)
|
||||
)
|
||||
.map(Message::SelectZone),
|
||||
]
|
||||
.padding([0, 10])
|
||||
|
||||
+19
-12
@@ -14,13 +14,14 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
/*
|
||||
This is Welcome stage, used to greet used and allow user to choose program language
|
||||
*/
|
||||
|
||||
|
||||
use crate::{stage::{StageAction, StageResult}, kira_theming};
|
||||
use crate::{
|
||||
kira_theming,
|
||||
stage::{StageAction, StageResult},
|
||||
};
|
||||
use iced::{Alignment, widget};
|
||||
use rust_i18n::t;
|
||||
|
||||
@@ -42,6 +43,12 @@ pub struct WelcomeStage {
|
||||
locales: Vec<LocData>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct WelcomeStageResult {
|
||||
pub loc_code: String,
|
||||
pub loc_name: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Message {
|
||||
SelectLocale(LocData),
|
||||
@@ -51,7 +58,6 @@ pub enum Message {
|
||||
|
||||
impl WelcomeStage {
|
||||
pub fn new() -> Self {
|
||||
|
||||
Self {
|
||||
locale: Some(LocData {
|
||||
name: "English".into(),
|
||||
@@ -69,13 +75,15 @@ impl WelcomeStage {
|
||||
|
||||
fn gen_result(&self) -> StageResult {
|
||||
if let Some(loc) = &self.locale {
|
||||
StageResult::new("welcome")
|
||||
.add_val_string("loc_code", loc.code.clone())
|
||||
.add_val_string("loc_name", loc.name.clone())
|
||||
StageResult::WelcomeStageResult(WelcomeStageResult {
|
||||
loc_code: loc.code.clone(),
|
||||
loc_name: loc.name.clone(),
|
||||
})
|
||||
} else {
|
||||
StageResult::new("welcome")
|
||||
.add_val_string("loc_code", "en".to_string())
|
||||
.add_val_string("loc_name", "English".to_string())
|
||||
StageResult::WelcomeStageResult(WelcomeStageResult {
|
||||
loc_code: "en".to_string(),
|
||||
loc_name: "English".to_string(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,8 +104,7 @@ impl WelcomeStage {
|
||||
let exit_button = widget::button(widget::text(t!("button.exit"))).on_press(Message::Exit);
|
||||
|
||||
// Embed the image bytes into the executable
|
||||
let welcom_logo_handle =
|
||||
widget::image::Handle::from_bytes(kira_theming::get_logo_bytes());
|
||||
let welcom_logo_handle = widget::image::Handle::from_bytes(kira_theming::get_logo_bytes());
|
||||
|
||||
widget::column![
|
||||
widget::container(
|
||||
|
||||
Reference in New Issue
Block a user