SHA256
More work on installation stage
This commit is contained in:
Generated
+123
-513
File diff suppressed because it is too large
Load Diff
+4
-4
@@ -8,7 +8,7 @@ edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
blocking = "1.6"
|
||||
iced = { version = "0.14", default-features = false, features = ["crisp", "linux-theme-detection", "tiny-skia", "wgpu", "x11", "smol", "image"] }
|
||||
iced = { version = "0.14", default-features = false, features = ["crisp", "linux-theme-detection", "tiny-skia", "x11", "smol", "image"] }
|
||||
#iced = { git = "https://github.com/iced-rs/iced", branch = "vello_cpu", default-features = false, features = ["crisp", "linux-theme-detection", "vello-cpu", "x11", "smol", "image"]}
|
||||
iced_moving_picture = "0"
|
||||
log = "0.4"
|
||||
@@ -16,13 +16,12 @@ rust-i18n = "3"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
time-format = "1.2"
|
||||
toml = "1"
|
||||
|
||||
[dev-dependencies]
|
||||
rand = "0.10"
|
||||
|
||||
[profile.dev]
|
||||
opt-level = 2
|
||||
opt-level = 3
|
||||
codegen-units = 16
|
||||
|
||||
[profile.release]
|
||||
@@ -31,7 +30,8 @@ debug = false
|
||||
incremental = false
|
||||
codegen-units = 1
|
||||
# We need level 3 for tiny-skia otherwise render is lagging
|
||||
opt-level = "s"
|
||||
# opt-level = "s"
|
||||
opt-level = 3
|
||||
strip = true
|
||||
|
||||
|
||||
|
||||
@@ -283,9 +283,11 @@ fn get_dev_part_blocking(dev_name: &str) -> Result<Vec<PartInfo>, String> {
|
||||
|
||||
//"lsblk -o NAME,SIZE,FSTYPE -l -n /dev/nvme0n1"
|
||||
// lsblk -o NAME,SIZE,FSTYPE,TYPE,PARTLABEL,LABEL,PARTFLAGS -b -P
|
||||
|
||||
// -x NAME - sorting by name
|
||||
match Command::new("lsblk")
|
||||
.args([
|
||||
"-x",
|
||||
"NAME",
|
||||
"-o",
|
||||
"NAME,SIZE,FSTYPE,TYPE,PARTLABEL,LABEL,MOUNTPOINT,PARTFLAGS",
|
||||
"-b",
|
||||
@@ -383,9 +385,10 @@ pub struct PartLayout {
|
||||
}
|
||||
|
||||
///
|
||||
/// GPT requires 33x512 sectors at the very end of the disk (16,896 bytes = 16.5 KiB):
|
||||
/// 32 sectors — backup Partition Entry Array (128 entries × 128 bytes = 16,384 bytes)
|
||||
/// 1 sector — backup GPT header
|
||||
/// GPT requires 33x512 sectors at the very end of the disk (16896 bytes):
|
||||
/// 32 sectors - backup Partition Entry Array
|
||||
/// 1 sector - backup GPT header
|
||||
///
|
||||
impl PartLayout {
|
||||
pub fn new(dev: BlkDev) -> Self {
|
||||
// 16896 - reserved space at the dev end for gpt
|
||||
@@ -509,7 +512,7 @@ impl PartLayout {
|
||||
res = res.add_part(
|
||||
swap_size,
|
||||
FSType::SWAP,
|
||||
Some("swap".into()),
|
||||
Some("bee-swap".into()),
|
||||
None,
|
||||
Some("SWAP".into()),
|
||||
Some(PartRole::SWAP),
|
||||
|
||||
+11
-1
@@ -293,6 +293,16 @@ pub fn bcachefs_mount(dev_name: &str, mount_point: &str) -> Result<(), ExecComma
|
||||
exec_command("mount", &vec!["-t", "bcachefs", dev_name, mount_point])
|
||||
}
|
||||
|
||||
pub fn mount_fs(dev_name: &str, mount_point: &str) -> Result<(), ExecCommandError> {
|
||||
// sudo mount -t bcachefs /dev/loop0 /mnt/test
|
||||
exec_command("mount", &vec![dev_name, mount_point])
|
||||
}
|
||||
|
||||
pub fn swapon(dev_name: &str) -> Result<(), ExecCommandError> {
|
||||
exec_command("swapon", &vec![dev_name])
|
||||
}
|
||||
|
||||
|
||||
pub fn fatlabel(dev: &str, label: &str) -> Result<(), ExecCommandError> {
|
||||
//fatlabel /dev/sda1 ESP
|
||||
exec_command("fatlabel", &vec![dev, label])
|
||||
@@ -318,5 +328,5 @@ pub fn mkfs_esp(dev: &str) -> Result<(), ExecCommandError> {
|
||||
|
||||
pub fn mkswap(dev: &str) -> Result<(), ExecCommandError> {
|
||||
//mkswap -L SWAP /dev/sda4
|
||||
exec_command("mkswap", &vec!["L", "SWAP", dev])
|
||||
exec_command("mkswap", &vec!["-L", "bee-swap", dev])
|
||||
}
|
||||
|
||||
+1
-1
@@ -245,9 +245,9 @@ fn update(k_state: &mut KiraState, message: Message) -> Task<Message> {
|
||||
if let Views::Keyboard(keyboard_view) = &mut k_state.current_view {
|
||||
match keyboard_view.update(keyboard_msg) {
|
||||
StageAction::Next(keyboard_res) => {
|
||||
k_state.k_config = keyboard_res;
|
||||
match stages::partition::PartitionStage::new(k_state.k_config.clone()) {
|
||||
Ok(part_stage) => {
|
||||
k_state.k_config = keyboard_res;
|
||||
let s_state = std::mem::replace(
|
||||
&mut k_state.current_view,
|
||||
Views::Partition(part_stage),
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 251 KiB After Width: | Height: | Size: 9.1 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 56 KiB After Width: | Height: | Size: 9.1 KiB |
+2
-113
@@ -18,106 +18,9 @@
|
||||
This file contains basic enums and structs to be used with stages.
|
||||
*/
|
||||
|
||||
use iced::wgpu::naga::compact::KeepUnused::No;
|
||||
|
||||
use crate::stages;
|
||||
|
||||
|
||||
// #[derive(Debug, Clone)]
|
||||
// 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 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_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_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 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_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 res_welcome: Option<stages::welcome::WelcomeStageResult>,
|
||||
@@ -128,7 +31,7 @@ pub struct KiraConfig {
|
||||
pub res_keyboard: Option<stages::keyboard::KeyboardStageResult>,
|
||||
pub res_partition: Option<stages::partition::PartitionStageResult>,
|
||||
pub res_security: Option<stages::security::SecurityStageResult>,
|
||||
pub res_install: bool,
|
||||
pub res_install: Option<stages::install::InstallStageResult>,
|
||||
}
|
||||
|
||||
impl Default for KiraConfig {
|
||||
@@ -142,25 +45,11 @@ impl Default for KiraConfig {
|
||||
res_keyboard: None,
|
||||
res_partition: None,
|
||||
res_security: None,
|
||||
res_install: false,
|
||||
res_install: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// impl KiraConfig {
|
||||
// pub fn get_stage(&self, name: &str) -> Option<StageResult> {
|
||||
// self.config_trail
|
||||
// .iter()
|
||||
// .find(|v| v.name() == name)
|
||||
// .and_then(|v| Some(v.clone()))
|
||||
// }
|
||||
// pub fn pop_last(&mut self) -> Option<StageResult> {
|
||||
// self.config_trail.pop()
|
||||
// }
|
||||
// pub fn push(&mut self, stage_result: StageResult) {
|
||||
// self.config_trail.push(stage_result);
|
||||
// }
|
||||
// }
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum StageAction {
|
||||
|
||||
+57
-92
@@ -18,6 +18,8 @@
|
||||
Actual installation script.
|
||||
*/
|
||||
|
||||
use std::path::Path;
|
||||
|
||||
use crate::{
|
||||
kira_disk_layout::{self, BlkDev, FSType, PartLayout, PartRole},
|
||||
kira_size::KiraSize,
|
||||
@@ -37,6 +39,8 @@ use log;
|
||||
use rust_i18n::t;
|
||||
|
||||
const EFI_BOOT_MOUNT_POINT: &str = "/beefi";
|
||||
const MNT_DIR: &str = "/mnt/inst_root";
|
||||
const ROOT_PARTLABEL_DEV: &str = "/dev/disk/by-partlabel/bee-root";
|
||||
|
||||
/// Creates new GPT table and partitions from PartLayout
|
||||
pub fn create_partitions(part_layout: &PartLayout) -> Result<(), ExecCommandError> {
|
||||
@@ -59,11 +63,7 @@ pub fn bcachefs_init(
|
||||
dev_name: &str,
|
||||
mnt_dir: &str,
|
||||
password: Option<String>,
|
||||
comp_alg: Option<String>,
|
||||
) -> Result<(), ExecCommandError> {
|
||||
// format device
|
||||
kira_system::bcachefs_format(dev_name, comp_alg, password.clone())?;
|
||||
|
||||
// if encryption used - unlock drive
|
||||
if let Some(pass) = password {
|
||||
kira_system::bcachefs_unlock(dev_name, pass.as_str())?;
|
||||
@@ -88,6 +88,15 @@ pub fn bcachefs_init(
|
||||
}
|
||||
|
||||
pub fn init_disk(part_layout: &PartLayout, mnt_dir: &str) -> Result<(), ExecCommandError> {
|
||||
|
||||
|
||||
let mnt_path = Path::new(mnt_dir);
|
||||
log::info!("Cheking is MNT path exists: {}", mnt_dir);
|
||||
if !mnt_path.exists() {
|
||||
log::info!("MNT path do not exist, creating it...");
|
||||
std::fs::create_dir_all(mnt_path)?;
|
||||
}
|
||||
|
||||
// use parted to create partition gpt layout
|
||||
create_partitions(part_layout)?;
|
||||
|
||||
@@ -102,12 +111,11 @@ pub fn init_disk(part_layout: &PartLayout, mnt_dir: &str) -> Result<(), ExecComm
|
||||
Some(PartRole::ROOT) => {
|
||||
if let Some(part_l) = part.partlabel_dev() {
|
||||
if let FSType::BCACHEFS(bc_par) = &part.fs_type {
|
||||
bcachefs_init(
|
||||
&part_l,
|
||||
mnt_dir,
|
||||
bc_par.password.clone(),
|
||||
bc_par.comp_alg.clone(),
|
||||
)?;
|
||||
log::info!("Formating root pertition.");
|
||||
kira_system::bcachefs_format(&part_l, bc_par.password.clone(), bc_par.password.clone())?;
|
||||
// init root
|
||||
log::info!("Mount and init root partition.");
|
||||
bcachefs_init(ROOT_PARTLABEL_DEV, mnt_dir, bc_par.password.clone())?;
|
||||
} else {
|
||||
return Err(ExecCommandError::Other(
|
||||
"ROOT partition is not BCACHEFS type!".into(),
|
||||
@@ -135,12 +143,16 @@ enum InstallationState {
|
||||
Error,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct InstallStageResult {
|
||||
pub sucess: Result<(), String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct InstallStage {
|
||||
state: InstallationState,
|
||||
progress: f32,
|
||||
progress_message: String,
|
||||
part_config: PartitionStageResult,
|
||||
modal_backgroud: Color,
|
||||
k_config: KiraConfig,
|
||||
}
|
||||
@@ -167,95 +179,27 @@ async fn init_disk_async(part_layout: PartLayout, mnt_dir: String) -> Result<(),
|
||||
blocking::unblock(move || init_disk(&part_layout, &mnt_dir)).await
|
||||
}
|
||||
|
||||
fn partition_disk(
|
||||
disk_layout: PartLayout,
|
||||
password: Option<String>,
|
||||
compression: Option<String>,
|
||||
mnt_dir: String,
|
||||
fn do_install(
|
||||
k_config: KiraConfig,
|
||||
) -> impl futures::Stream<Item = Result<(f32, String), ExecCommandError>> {
|
||||
use blocking;
|
||||
|
||||
iced::stream::channel(
|
||||
100,
|
||||
|mut output: Sender<Result<(f32, String), ExecCommandError>>| async move {
|
||||
//sleep(Duration::from_millis(10)).await;
|
||||
let disk_layout_cloned = disk_layout.clone();
|
||||
let disk_layout = k_config.res_partition.unwrap().part_layout.clone();
|
||||
|
||||
// creating gpt partition table
|
||||
let res = init_disk_async(disk_layout_cloned, mnt_dir).await;
|
||||
let res = init_disk_async(disk_layout, MNT_DIR.into()).await;
|
||||
let res_err = res.is_err();
|
||||
output
|
||||
.send(res.map(|_| (1.1f32, "Formatting bcachefs".into())))
|
||||
.await
|
||||
.unwrap();
|
||||
if res.is_err() {
|
||||
return;
|
||||
}
|
||||
|
||||
let res = init_disk_async(disk_layout_cloned).await;
|
||||
output
|
||||
.send(res.map(|_| (1.1f32, "Formatting bcachefs".into())))
|
||||
.await
|
||||
.unwrap();
|
||||
if res.is_err() {
|
||||
if res_err {
|
||||
return;
|
||||
}
|
||||
|
||||
// creating partitions
|
||||
let dev = disk_layout.dev.clone();
|
||||
let part_list = disk_layout.part_list.clone();
|
||||
match output
|
||||
.send(
|
||||
blocking::unblock(move || {
|
||||
let mut res = Ok(());
|
||||
for part in part_list {
|
||||
match kira_system::parted_mkpart(&dev, &part) {
|
||||
Ok(_) => (),
|
||||
Err(ex) => {
|
||||
res = Err(ex);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
res
|
||||
})
|
||||
.await
|
||||
.and(Ok((5.0f32, "Creating partitions".into()))),
|
||||
)
|
||||
.await
|
||||
{
|
||||
Err(ex) => {
|
||||
log::error!("Error creating GPT partition table: {}", ex.to_string());
|
||||
return;
|
||||
}
|
||||
_ => (),
|
||||
};
|
||||
|
||||
// creating bcachefs filesystem
|
||||
// /dev/disk/by-partlabel/
|
||||
let compression_cloned = compression.clone();
|
||||
let password_cloned = password.clone();
|
||||
match output
|
||||
.send(
|
||||
blocking::unblock(move || {
|
||||
bcachefs_init(
|
||||
"/dev/disk/by-partlabel/bee-root",
|
||||
compression_cloned,
|
||||
password_cloned,
|
||||
"/mnt/bzzpss-install",
|
||||
)
|
||||
})
|
||||
.await
|
||||
.and(Ok((10.0f32, "Creating partition table".into()))),
|
||||
)
|
||||
.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
|
||||
@@ -267,6 +211,20 @@ fn partition_disk(
|
||||
)
|
||||
}
|
||||
|
||||
fn check_kconfig(k_config: &KiraConfig) -> Result<(), String> {
|
||||
if k_config.res_welcome.is_none(){ Err("Missing wellcome stage result!".into())}
|
||||
else if k_config.res_license == false { Err("License is NOT accepted!".into())}
|
||||
else if k_config.res_locale.is_none(){ Err("Missing locale stage result!".into())}
|
||||
else if k_config.res_network.is_none(){ Err("Missing network stage result!".into())}
|
||||
else if k_config.res_keyboard.is_none(){ Err("Missing keyboard stage result!".into())}
|
||||
else if k_config.res_timezone.is_none(){ Err("Missing timezone stage result!".into())}
|
||||
else if k_config.res_partition.is_none(){ Err("Missing partition stage result!".into())}
|
||||
else if k_config.res_security.is_none(){ Err("Missing security stage result!".into())}
|
||||
else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl InstallStage {
|
||||
pub fn new(k_config: KiraConfig) -> Self {
|
||||
let mut modal_backgroud = kira_theming::main_theme().palette().background;
|
||||
@@ -276,13 +234,12 @@ impl InstallStage {
|
||||
state: InstallationState::UserConfirmDialog,
|
||||
progress: 0.0,
|
||||
progress_message: String::new(),
|
||||
part_config: k_config.res_partition.clone().expect("Partition stage result should be present in KiraConfig!"),
|
||||
k_config: k_config,
|
||||
}
|
||||
}
|
||||
|
||||
fn gen_result(&mut self) -> KiraConfig {
|
||||
self.k_config.res_install = true;
|
||||
self.k_config.res_install = Some(InstallStageResult { sucess: Ok(()) });
|
||||
self.k_config.clone()
|
||||
}
|
||||
|
||||
@@ -290,16 +247,24 @@ impl InstallStage {
|
||||
match message {
|
||||
Message::UserDenies => Update::StgAct(StageAction::Back),
|
||||
Message::UserConfirms => {
|
||||
|
||||
log::info!("Cheking config...");
|
||||
match check_kconfig(&self.k_config) {
|
||||
Ok(()) => log::info!("Config looks good."),
|
||||
Err(ex) => {
|
||||
log::error!("{}", ex);
|
||||
self.state = InstallationState::Error;
|
||||
return Update::StgAct(StageAction::None);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// starting installation process here
|
||||
log::info!("Starting disk partitioning.");
|
||||
|
||||
self.state = InstallationState::Installing;
|
||||
let disk_layout = self.part_config.part_layout.clone();
|
||||
let disk_password = self.part_config.password.clone();
|
||||
let disk_compression = Some("lz4".to_string());
|
||||
Update::Task(Task::run(
|
||||
partition_disk(disk_layout, disk_password, disk_compression)
|
||||
.map_err(|ex| ex.to_string()),
|
||||
do_install(self.k_config.clone()).map_err(|ex| ex.to_string()),
|
||||
Message::UpdateProgress,
|
||||
))
|
||||
//Update::Task(Task::perform(, Message::PartitioningFinish))
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
This is Security stage, setup users logins and such
|
||||
*/
|
||||
|
||||
use crate::stage::{StageAction, KiraConfig};
|
||||
use crate::stage::{KiraConfig, StageAction};
|
||||
use iced::{Alignment, Color, widget};
|
||||
use rust_i18n::t;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user