SHA256
Compare commits
64
Commits
| Author | SHA256 | Date | |
|---|---|---|---|
|
|
c80ffc897c | ||
|
|
2321d06af1 | ||
|
|
1186932625 | ||
|
|
740bbdb4d8 | ||
|
|
7c57193bf1 | ||
|
|
5597b56538 | ||
|
|
ecc87066ad | ||
|
|
eee7fd17d6 | ||
|
|
9d68343219 | ||
|
|
d494dbe3c8 | ||
|
|
7e72abb528 | ||
|
|
841090d3d6 | ||
|
|
d68ee36afa | ||
|
|
1399c56135 | ||
|
|
029df21d3e | ||
|
|
279bd30463 | ||
|
|
1bdc4547d3 | ||
|
|
e40fa95cc8 | ||
|
|
3899af1c79 | ||
|
|
fb90bc3092 | ||
|
|
6f921f3ff0 | ||
|
|
b5b5bd764a | ||
|
|
3b086605cf | ||
|
|
fa5c3d3aec | ||
|
|
dda9288e23 | ||
|
|
f404ff385a | ||
|
|
c56da21eab | ||
|
|
ed6ffcdee1 | ||
|
|
4d8c9540d0 | ||
|
|
56e87a62cf | ||
|
|
9769ae409e | ||
|
|
3abbbe9abd | ||
|
|
b2f510e679 | ||
|
|
a503b2a36f | ||
|
|
f0a8e704c0 | ||
|
|
187129d314 | ||
|
|
b0ea2e0ee3 | ||
|
|
4fb49797cb | ||
|
|
bb3f5ed1f0 | ||
|
|
078589332c | ||
|
|
6b4550dc8e | ||
|
|
e0c6112422 | ||
|
|
66f7851574 | ||
|
|
b1f3644092 | ||
|
|
302423d98f | ||
|
|
9743b010d1 | ||
|
|
c6e7fa6069 | ||
|
|
c0ae014eef | ||
|
|
edfd57d5d5 | ||
|
|
cf916eb508 | ||
|
|
4000e0cfac | ||
|
|
f851c6fef0 | ||
|
|
2684c12e73 | ||
|
|
75ef50bed1 | ||
|
|
9081e301d4 | ||
|
|
8b3f22909e | ||
|
|
7365f95d20 | ||
|
|
d4c7e59cd6 | ||
|
|
cf7b9ace08 | ||
|
|
a1263e7056 | ||
|
|
0de2f1ce10 | ||
|
|
b8c2630d3e | ||
|
|
bc46f042dc | ||
|
|
dae1586636 |
No files matched your search
Generated
+774
-1707
File diff suppressed because it is too large.
Load diff
+33
-5
@@ -3,15 +3,43 @@ name = "kira-installer"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
# Reference the build script
|
||||
# build = "build.rs"
|
||||
|
||||
[dependencies]
|
||||
blocking = "1.6"
|
||||
iced = { version = "0.14", features = ["smol", "image"] }
|
||||
# smol = "2"
|
||||
unicode-segmentation = "1"
|
||||
iced = { version = "0.14", default-features = false, features = ["crisp", "linux-theme-detection", "tiny-skia", "x11", "smol", "image", "advanced"] }
|
||||
#iced = { git = "https://github.com/iced-rs/iced", branch = "vello_cpu", default-features = false, features = ["crisp", "linux-theme-detection", "vello-cpu", "x11", "smol", "image"]}
|
||||
# zbus = { version = "6", default-features = false, features = ["default-rt", "comms"] }
|
||||
iced_moving_picture = "0"
|
||||
rust-i18n = "3"
|
||||
toml = "1"
|
||||
log = "0.4"
|
||||
rust-i18n = "4"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
time-format = "1.2"
|
||||
regex-lite = "0.1"
|
||||
xkbcommon = { version = "0.9.0" }
|
||||
|
||||
|
||||
[dev-dependencies]
|
||||
rand = "0.10"
|
||||
|
||||
[profile.dev]
|
||||
opt-level = 3
|
||||
codegen-units = 16
|
||||
|
||||
[profile.release]
|
||||
#lto = true
|
||||
codegen-units = 16
|
||||
lto = true
|
||||
debug = false
|
||||
incremental = false
|
||||
codegen-units = 1
|
||||
# We need level 3 for tiny-skia otherwise render is lagging
|
||||
# opt-level = "s"
|
||||
opt-level = 3
|
||||
strip = true
|
||||
|
||||
|
||||
[registry]
|
||||
global-min-publish-age = "14 days"
|
||||
@@ -1,3 +1,8 @@
|
||||
# kira-installer
|
||||
|
||||
Universal GNU Linux installer.
|
||||
Universal GNU Linux installer.
|
||||
It supposed to be simple, self contained, and reqire only minimal base system.
|
||||
|
||||
|
||||
In order to test you need to have kira_config.toml in the same directory as executable file.
|
||||
In order to make debug biuld just run ```cargo build```
|
||||
@@ -0,0 +1,23 @@
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
|
||||
fn main() {
|
||||
let profile = env::var("PROFILE").unwrap();
|
||||
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
|
||||
let target_dir = PathBuf::from(&manifest_dir).join("target").join(&profile);
|
||||
|
||||
// Ensure target directory exists
|
||||
if !target_dir.exists() {
|
||||
fs::create_dir_all(&target_dir).ok();
|
||||
}
|
||||
|
||||
// Copy the file (e.g., config.json) to the target directory
|
||||
let source = PathBuf::from(&manifest_dir).join("src").join("kira_config.toml");
|
||||
let dest = target_dir.join("kira_config.toml");
|
||||
|
||||
fs::copy(&source, &dest).expect("Failed to copy kira_config.toml");
|
||||
|
||||
// Optional: Tell Cargo to re-run this script if the source file changes
|
||||
println!("cargo:rerun-if-changed=src/kira_config.toml");
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
#
|
||||
# /etc/pacman.conf
|
||||
#
|
||||
# See the pacman.conf(5) manpage for option and repository directives
|
||||
|
||||
#
|
||||
# GENERAL OPTIONS
|
||||
#
|
||||
[options]
|
||||
# The following paths are commented out with their default values listed.
|
||||
# If you wish to use different paths, uncomment and update the paths.
|
||||
#RootDir = /
|
||||
#DBPath = /var/lib/pacman/
|
||||
#CacheDir = /var/cache/pacman/pkg/
|
||||
#LogFile = /var/log/pacman.log
|
||||
#GPGDir = /etc/pacman.d/gnupg/
|
||||
#HookDir = /etc/pacman.d/hooks/
|
||||
HoldPkg = pacman glibc
|
||||
#XferCommand = /usr/bin/curl -L -C - -f -o %o %u
|
||||
#XferCommand = /usr/bin/wget --passive-ftp -c -O %o %u
|
||||
#CleanMethod = KeepInstalled
|
||||
Architecture = auto
|
||||
|
||||
# Pacman won't upgrade packages listed in IgnorePkg and members of IgnoreGroup
|
||||
#IgnorePkg =
|
||||
#IgnoreGroup =
|
||||
|
||||
#NoUpgrade =
|
||||
#NoExtract =
|
||||
|
||||
# Misc options
|
||||
#UseSyslog
|
||||
Color
|
||||
ILoveCandy
|
||||
#NoProgressBar
|
||||
CheckSpace
|
||||
#VerbosePkgLists
|
||||
ParallelDownloads = 5
|
||||
DownloadUser = alpm
|
||||
#DisableSandboxFilesystem
|
||||
#DisableSandboxSyscalls
|
||||
|
||||
# By default, pacman accepts packages signed by keys that its local keyring
|
||||
# trusts (see pacman-key and its man page), as well as unsigned packages.
|
||||
SigLevel = Required DatabaseOptional
|
||||
LocalFileSigLevel = Optional
|
||||
#RemoteFileSigLevel = Required
|
||||
|
||||
# NOTE: You must run `pacman-key --init` before first using pacman; the local
|
||||
# keyring can then be populated with the keys of all official Artix Linux
|
||||
# packagers with `pacman-key --populate artix`.
|
||||
|
||||
#
|
||||
# REPOSITORIES
|
||||
# - can be defined here or included from another file
|
||||
# - pacman will search repositories in the order defined here
|
||||
# - local/custom mirrors can be added here or in separate files
|
||||
# - repositories listed first will take precedence when packages
|
||||
# have identical names, regardless of version number
|
||||
# - URLs will have $repo replaced by the name of the current repo
|
||||
# - URLs will have $arch replaced by the name of the architecture
|
||||
#
|
||||
# Repository entries are of the format:
|
||||
# [repo-name]
|
||||
# Server = ServerName
|
||||
# Include = IncludePath
|
||||
#
|
||||
# The header [repo-name] is crucial - it must be present and
|
||||
# uncommented to enable the repo.
|
||||
#
|
||||
|
||||
# kira linux base repository
|
||||
[kira-base]
|
||||
SigLevel = Required TrustedOnly
|
||||
Include = /etc/pacman.d/kira-mirrorlist
|
||||
|
||||
# The gremlins repositories are disabled by default. To enable, uncomment the
|
||||
# repo name header and Include lines. You can add preferred servers immediately
|
||||
# after the header, and they will be used before the default mirrors.
|
||||
|
||||
#[system-gremlins]
|
||||
#Include = /etc/pacman.d/mirrorlist
|
||||
|
||||
[system]
|
||||
Include = /etc/pacman.d/mirrorlist
|
||||
|
||||
#[world-gremlins]
|
||||
#Include = /etc/pacman.d/mirrorlist
|
||||
|
||||
[world]
|
||||
Include = /etc/pacman.d/mirrorlist
|
||||
|
||||
#[galaxy-gremlins]
|
||||
#Include = /etc/pacman.d/mirrorlist
|
||||
|
||||
[galaxy]
|
||||
Include = /etc/pacman.d/mirrorlist
|
||||
|
||||
# If you want to run 32 bit applications on your x86_64 system,
|
||||
# enable the lib32 repositories as required here.
|
||||
|
||||
#[lib32-gremlins]
|
||||
#Include = /etc/pacman.d/mirrorlist
|
||||
|
||||
#[lib32]
|
||||
#Include = /etc/pacman.d/mirrorlist
|
||||
|
||||
# An example of a custom package repository. See the pacman manpage for
|
||||
# tips on creating your own repositories.
|
||||
#[custom]
|
||||
#SigLevel = Optional TrustAll
|
||||
#Server = file:///home/custompkgs
|
||||
@@ -0,0 +1,36 @@
|
||||
use iced::widget::{self, Row, container, text};
|
||||
use iced::{Alignment, Color, Element, Length};
|
||||
|
||||
// Assuming your Item struct or type implements Display or has a text representation
|
||||
pub fn color_bar<Message: 'static>(
|
||||
maybe_items: Option<Vec<(String, u16, Color)>>,
|
||||
bar_height: u32,
|
||||
) -> Element<'static, Message> {
|
||||
|
||||
if let Some(items) = maybe_items {
|
||||
let mut c_b = Row::new().height(Length::Fill);
|
||||
for (bar_text, bar_fill, bar_color) in items {
|
||||
c_b = c_b.push(
|
||||
container(text(bar_text).color(Color::BLACK).size(iced::Pixels(14.0)))
|
||||
.height(Length::Fill)
|
||||
.width(Length::FillPortion(bar_fill))
|
||||
.style(move |_| container::background(bar_color))
|
||||
.align_x(Alignment::Center)
|
||||
.align_y(Alignment::Center)
|
||||
.padding(2),
|
||||
);
|
||||
}
|
||||
container(c_b.spacing(2))
|
||||
.style(container::rounded_box)
|
||||
.padding(3)
|
||||
.height(bar_height)
|
||||
.into()
|
||||
}
|
||||
else {
|
||||
widget::container(widget::space())
|
||||
.height(bar_height)
|
||||
.width(Length::Fill)
|
||||
.into()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,3 +1,7 @@
|
||||
|
||||
[network]
|
||||
reqire_network = true
|
||||
|
||||
[partition]
|
||||
min_disk_size_mb = 8192
|
||||
efi_size_mb = 128
|
||||
@@ -0,0 +1,589 @@
|
||||
// <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/>.
|
||||
|
||||
/*
|
||||
Functions for working with disk layout
|
||||
*/
|
||||
|
||||
use crate::kira_size::KiraSize;
|
||||
use log;
|
||||
use std::collections::HashMap;
|
||||
///
|
||||
/// size - device size in bytes
|
||||
/// sector size - default 4096
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct BlkDev {
|
||||
pub name: String,
|
||||
pub size: KiraSize,
|
||||
pub sector_size: KiraSize,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for BlkDev {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{} ({})", &self.name, self.size)
|
||||
}
|
||||
}
|
||||
|
||||
impl BlkDev {
|
||||
/// Create new BlkDev struct with specifyed name and size
|
||||
pub fn new(name: String, size: KiraSize) -> Self {
|
||||
Self {
|
||||
name: name,
|
||||
size: size,
|
||||
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(),
|
||||
size: KiraSize::from_str_bytes(data.get("SIZE")?)?,
|
||||
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;
|
||||
|
||||
// lsblk -d -b -P -o NAME,SIZE,FSTYPE,LABEL,MOUNTPOINT
|
||||
match Command::new("lsblk")
|
||||
.args(["-d", "-b", "-P", "-o", "NAME,SIZE,FSTYPE,LABEL,MOUNTPOINT"])
|
||||
.output()
|
||||
{
|
||||
Ok(cmd_output) => {
|
||||
if cmd_output.status.success() {
|
||||
match String::from_utf8(cmd_output.stdout) {
|
||||
Ok(raw_str_list) => Ok(raw_str_list
|
||||
.lines()
|
||||
.map(|l| {
|
||||
l.split_whitespace()
|
||||
.filter_map(|pair| {
|
||||
pair.split_once("=").and_then(|kv| {
|
||||
Some((
|
||||
kv.0.trim_matches('"').to_string(),
|
||||
kv.1.trim_matches('"').to_string(),
|
||||
))
|
||||
})
|
||||
})
|
||||
.collect::<HashMap<String, String>>()
|
||||
})
|
||||
.filter(|mp| mp.get("MOUNTPOINT").is_some_and(|v| v.is_empty()))
|
||||
.filter_map(|mp| Self::from_hash_map(&mp))
|
||||
.collect()),
|
||||
Err(ex) => Err(format!(
|
||||
"Exception while converting disks info to UTF8 {}",
|
||||
ex
|
||||
)),
|
||||
}
|
||||
} else {
|
||||
Err(format!(
|
||||
"Error getting disk devices list: {}",
|
||||
String::from_utf8(cmd_output.stderr).unwrap_or("UNKNOWN".into())
|
||||
))
|
||||
}
|
||||
}
|
||||
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)]
|
||||
pub struct BcachefsProp {
|
||||
pub password: Option<String>,
|
||||
pub comp_alg: Option<String>,
|
||||
}
|
||||
|
||||
impl BcachefsProp {
|
||||
pub fn new(password: Option<String>, comp_alg: Option<String>) -> Self {
|
||||
Self {
|
||||
password: password,
|
||||
comp_alg: comp_alg,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn default() -> Self {
|
||||
Self {
|
||||
password: None,
|
||||
comp_alg: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum FSType {
|
||||
VFAT,
|
||||
XFS,
|
||||
LUKS,
|
||||
SWAP,
|
||||
EXT4,
|
||||
BTRFS,
|
||||
BCACHEFS(BcachefsProp),
|
||||
UNKNOWN,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for FSType {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::VFAT => write!(f, "vfat"),
|
||||
Self::XFS => write!(f, "xfs"),
|
||||
Self::LUKS => write!(f, "luks"),
|
||||
Self::SWAP => write!(f, "swap"),
|
||||
Self::EXT4 => write!(f, "ext4"),
|
||||
Self::BTRFS => write!(f, "btrfs"),
|
||||
Self::BCACHEFS(_) => write!(f, "bcachefs"),
|
||||
Self::UNKNOWN => write!(f, "unknown"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl FSType {
|
||||
pub fn from_str(s: &str) -> Self {
|
||||
let s_low = s.to_lowercase();
|
||||
match s_low.as_str() {
|
||||
"vfat" => Self::VFAT,
|
||||
"xfs" => Self::XFS,
|
||||
"crypto_luks" => Self::LUKS,
|
||||
"swap" => Self::SWAP,
|
||||
"ext4" => Self::EXT4,
|
||||
"btrfs" => Self::BTRFS,
|
||||
"bcachefs" => Self::BCACHEFS(BcachefsProp::default()),
|
||||
_ => 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(_) => "xfs",
|
||||
// lets do something generic here instead of panic
|
||||
Self::UNKNOWN => "linux-swap",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// fn part_type_to_color(t: &str) -> Color {
|
||||
// match t {
|
||||
// "vfat" => Color::from_rgb8(204, 121, 167),
|
||||
// "xfs" => Color::from_rgb8(0, 158, 115),
|
||||
// "crypto_LUKS" => Color::from_rgb8(240, 228, 66),
|
||||
// "swap" => Color::from_rgb8(213, 94, 0),
|
||||
// "ext4" => Color::from_rgb8(0, 114, 178),
|
||||
// "btrfs" => Color::from_rgb8(86, 180, 233),
|
||||
// _ => Color::from_rgb8(230, 159, 0),
|
||||
// }
|
||||
// }
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum PartRole {
|
||||
EFI,
|
||||
ROOT,
|
||||
SWAP,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct PartInfo {
|
||||
pub name: String,
|
||||
pub size: KiraSize,
|
||||
pub start: KiraSize,
|
||||
pub fs_type: FSType,
|
||||
pub gpt_label: Option<String>,
|
||||
pub fs_label: Option<String>,
|
||||
pub mount_point: Option<String>,
|
||||
pub role: Option<PartRole>,
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
impl PartInfo {
|
||||
///
|
||||
/// calculate par end byte as 0 starting bytes index (for parted and such)
|
||||
///
|
||||
pub fn part_end(&self) -> KiraSize {
|
||||
// important to shift here by 1 because disk index is starting from 0, and part end pointing to last byte of the partition.
|
||||
(self.start + self.size) - KiraSize::new_b(1)
|
||||
}
|
||||
|
||||
///
|
||||
/// Returns zero based byte index of start of next (right after this one) partition
|
||||
///
|
||||
pub fn next_part_start(&self) -> KiraSize {
|
||||
// important to shift here by 1 because disk index is starting from 0, and part end pointing to last byte of the partition.
|
||||
self.start + self.size
|
||||
}
|
||||
|
||||
pub fn from_hash_map(data: &HashMap<String, String>) -> Option<Self> {
|
||||
Some(Self {
|
||||
name: data.get("NAME")?.clone(),
|
||||
size: KiraSize::from_str_bytes(data.get("SIZE")?)?,
|
||||
start: KiraSize::new_b(0),
|
||||
fs_type: FSType::from_str(data.get("FSTYPE")?),
|
||||
gpt_label: data
|
||||
.get("PARTLABEL")
|
||||
.and_then(|v| if v.is_empty() { None } else { Some(v.clone()) }),
|
||||
fs_label: data
|
||||
.get("LABEL")
|
||||
.and_then(|v| if v.is_empty() { None } else { Some(v.clone()) }),
|
||||
mount_point: data
|
||||
.get("MOUNTPOINT")
|
||||
.and_then(|v| if v.is_empty() { None } else { Some(v.clone()) }),
|
||||
role: None,
|
||||
})
|
||||
}
|
||||
|
||||
///
|
||||
/// Returns partition full path by partlabel "/dev/disk/by-partlabel/{partlabel}"
|
||||
/// Returns None if partition do not have partlabel
|
||||
///
|
||||
pub fn partlabel_dev(&self) -> Option<String> {
|
||||
self.gpt_label
|
||||
.as_ref()
|
||||
.and_then(|l| Some(format!("/dev/disk/by-partlabel/{}", l)))
|
||||
}
|
||||
}
|
||||
|
||||
/// getting list of device partitions
|
||||
fn get_dev_part_blocking(dev_name: &str) -> Result<Vec<PartInfo>, String> {
|
||||
use std::process::Command;
|
||||
|
||||
//"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",
|
||||
"-P",
|
||||
format!("/dev/{}", dev_name).as_str(),
|
||||
])
|
||||
.output()
|
||||
{
|
||||
Ok(cmd_output) => {
|
||||
if cmd_output.status.success() {
|
||||
match String::from_utf8(cmd_output.stdout) {
|
||||
Ok(raw_str_list) => Ok(raw_str_list
|
||||
.lines()
|
||||
.map(|l| {
|
||||
l.split_whitespace()
|
||||
.filter_map(|pair| {
|
||||
pair.split_once("=").and_then(|kv| {
|
||||
Some((
|
||||
kv.0.trim_matches('"').to_string(),
|
||||
kv.1.trim_matches('"').to_string(),
|
||||
))
|
||||
})
|
||||
})
|
||||
.collect::<HashMap<String, String>>()
|
||||
})
|
||||
.filter(|mp| mp.get("TYPE").is_some_and(|v| v == "part"))
|
||||
.filter_map(|mp| PartInfo::from_hash_map(&mp))
|
||||
.collect()),
|
||||
Err(ex) => Err(format!(
|
||||
"Exception while converting partition info to UTF8 {}",
|
||||
ex
|
||||
)),
|
||||
}
|
||||
} else {
|
||||
Err(format!(
|
||||
"Error getting device partitions list: {}",
|
||||
String::from_utf8(cmd_output.stderr).unwrap_or("UNKNOWN".into())
|
||||
))
|
||||
}
|
||||
}
|
||||
Err(ex) => Err(ex.to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
/// size - size in bytes
|
||||
/// start - start byte of partition, inclusive index.
|
||||
/// returns tuple of aligned size, start index, and end index
|
||||
/// return none if aligment is not possibe (size of partition is less than align)
|
||||
pub fn align_part(size: u64, start: u64, align: u64) -> Option<(u64, u64, u64)> {
|
||||
if size < align {
|
||||
log::debug!("if size < align !!!!!!!");
|
||||
return None;
|
||||
}
|
||||
|
||||
let start_mod = start % align;
|
||||
// increasing start if not align
|
||||
let align_start = if start_mod > 0 {
|
||||
start + (align - start_mod)
|
||||
} else {
|
||||
start
|
||||
};
|
||||
|
||||
// decreasing end if not align
|
||||
let part_end = align_start + size;
|
||||
let end_mod = part_end % align;
|
||||
|
||||
let align_end = part_end - end_mod - 1;
|
||||
|
||||
let align_size = align_end - align_start + 1;
|
||||
|
||||
if align_size < align {
|
||||
log::warn!(
|
||||
"!!! align_size < align !!! align_size: {} align: {}",
|
||||
align_size,
|
||||
align
|
||||
);
|
||||
return None;
|
||||
}
|
||||
log::debug!(
|
||||
"align_size: {}, align_start:{}, align_end: {} end_mod: {}",
|
||||
align_size,
|
||||
align_start,
|
||||
align_end,
|
||||
end_mod
|
||||
);
|
||||
Some((align_size, align_start, align_end))
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct PartLayout {
|
||||
pub dev: BlkDev,
|
||||
pub empty_space: KiraSize,
|
||||
pub part_list: Vec<PartInfo>,
|
||||
}
|
||||
|
||||
///
|
||||
/// 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
|
||||
let usable_space = dev.size - KiraSize::new_b(16896);
|
||||
Self {
|
||||
empty_space: usable_space,
|
||||
dev: dev,
|
||||
part_list: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_part(&self, part_role: PartRole) -> Option<PartInfo> {
|
||||
for part in &self.part_list {
|
||||
if let Some(role) = &part.role && role.eq(&part_role) {
|
||||
return Some(part.clone());
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
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);
|
||||
Ok(Self {
|
||||
dev: dev.clone(),
|
||||
empty_space: dev.size - parts_size,
|
||||
part_list: part_list,
|
||||
})
|
||||
}
|
||||
|
||||
// pub fn new_table(mut self) -> Self {
|
||||
// self.empty_space = self.dev.size;
|
||||
// self.part_list = Vec::new();
|
||||
// self
|
||||
// }
|
||||
|
||||
pub fn add_part(
|
||||
mut self,
|
||||
part_size: KiraSize,
|
||||
fs_type: FSType,
|
||||
gpt_label: Option<String>,
|
||||
fs_label: Option<String>,
|
||||
mount_point: Option<String>,
|
||||
role: Option<PartRole>,
|
||||
) -> Self {
|
||||
let part_start = if self.part_list.is_empty() {
|
||||
// need to substract 2 mb offset from disk start.
|
||||
self.empty_space = self.empty_space - KiraSize::new_mb(2);
|
||||
KiraSize::new_mb(2)
|
||||
} else {
|
||||
// last part end + 1
|
||||
self.part_list.last().unwrap().next_part_start()
|
||||
};
|
||||
|
||||
let (a_size, a_start, _) =
|
||||
align_part(part_size.b(), part_start.b(), self.dev.sector_size.b()).unwrap();
|
||||
|
||||
log::debug!(
|
||||
"PartLayout.add_part gpt_label{:?}, size_asked:{}, size_al:{}",
|
||||
gpt_label,
|
||||
part_size,
|
||||
a_size
|
||||
);
|
||||
|
||||
let part_name = format!("{}p{}", self.dev.name, self.part_list.len() + 1);
|
||||
self.part_list.push(PartInfo {
|
||||
name: part_name,
|
||||
size: KiraSize::new_b(a_size),
|
||||
start: KiraSize::new_b(a_start),
|
||||
fs_type: fs_type,
|
||||
gpt_label: gpt_label,
|
||||
fs_label: fs_label,
|
||||
mount_point: mount_point,
|
||||
role: role,
|
||||
});
|
||||
|
||||
self.empty_space = self.empty_space - KiraSize::new_b(a_size);
|
||||
|
||||
self
|
||||
}
|
||||
///
|
||||
/// Use this to add partition of (disk_empty_space - reserve_space)
|
||||
/// Specifically to leave some space at the end for SWAP and such
|
||||
///
|
||||
pub fn add_part_reserve(
|
||||
self,
|
||||
reserve_space: KiraSize,
|
||||
fs_type: FSType,
|
||||
gpt_label: Option<String>,
|
||||
fs_label: Option<String>,
|
||||
mount_point: Option<String>,
|
||||
role: Option<PartRole>,
|
||||
) -> Self {
|
||||
let p_size = self.empty_space - reserve_space;
|
||||
self.add_part(p_size, fs_type, gpt_label, fs_label, mount_point, role)
|
||||
}
|
||||
|
||||
pub fn gen_kira_layout(
|
||||
dev: BlkDev,
|
||||
efi_size: KiraSize,
|
||||
swap_size: KiraSize,
|
||||
maybe_password: Option<String>,
|
||||
maybe_compr: Option<String>,
|
||||
) -> Self {
|
||||
let mut res: PartLayout = PartLayout::new(dev);
|
||||
|
||||
// UEFI partition
|
||||
res = res
|
||||
.add_part(
|
||||
efi_size,
|
||||
FSType::VFAT,
|
||||
Some("bee-efi".into()),
|
||||
Some("EFI".into()),
|
||||
Some("/beefi".into()),
|
||||
Some(PartRole::EFI),
|
||||
)
|
||||
.add_part_reserve(
|
||||
swap_size,
|
||||
FSType::BCACHEFS(BcachefsProp::new(maybe_password, maybe_compr)),
|
||||
Some("bee-root".into()),
|
||||
None,
|
||||
Some("/".into()),
|
||||
Some(PartRole::ROOT),
|
||||
);
|
||||
|
||||
// swap
|
||||
if swap_size.b() > 0 {
|
||||
res = res.add_part(
|
||||
swap_size,
|
||||
FSType::SWAP,
|
||||
Some("bee-swap".into()),
|
||||
None,
|
||||
Some("SWAP".into()),
|
||||
Some(PartRole::SWAP),
|
||||
);
|
||||
}
|
||||
|
||||
res
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use rand::RngExt;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_align_part_fn_joe() {
|
||||
//START (S),SIZE (Z),ALIGNMENT (A),ALIGNED_START (Salign),ALIGNED_END (Ealign),Effektive Größe (Zalign)
|
||||
let joes_test_data: Vec<(u64, u64, u64, u64, u64, u64)> = vec![
|
||||
(0, 10000, 4096, 0, 8191, 8192),
|
||||
(5000, 20000, 4096, 8192, 24575, 16384),
|
||||
(4096, 4096, 4096, 4096, 8191, 4096),
|
||||
(1000000, 5000000, 1048576, 1048576, 5242879, 4194304),
|
||||
(2097152, 1050000, 1048576, 2097152, 3145727, 1048576),
|
||||
];
|
||||
for test_data in joes_test_data {
|
||||
let res = align_part(test_data.1, test_data.0, test_data.2).unwrap();
|
||||
let test_res = (test_data.5, test_data.3, test_data.4);
|
||||
assert_eq!(res, test_res);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_align_part_fn_rand() {
|
||||
for ((size, start, align), test_res) in rand::rng()
|
||||
.random_iter::<u32>()
|
||||
.filter(|n| *n > 0)
|
||||
.take(100)
|
||||
.flat_map(|align| {
|
||||
(0..u64::MAX)
|
||||
.step_by(align as usize)
|
||||
.take(1000)
|
||||
.map(move |start_align| {
|
||||
let mut rng = rand::rng();
|
||||
let size_align = align as u64 * rng.random_range(1..u16::MAX) as u64;
|
||||
let end_align = start_align + size_align - 1;
|
||||
let start = start_align.saturating_sub(rng.random_range(0..align) as u64);
|
||||
let size = size_align.saturating_add(rng.random_range(0..align) as u64);
|
||||
(
|
||||
(size, start, align as u64),
|
||||
(size_align, start_align.clone(), end_align),
|
||||
)
|
||||
})
|
||||
})
|
||||
{
|
||||
let res = align_part(size, start, align).unwrap();
|
||||
assert_eq!(res, test_res);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
|
||||
|
||||
|
||||
const PACMAN_CONF: &str = include_str!("files/etc/pacman.conf");
|
||||
@@ -0,0 +1,253 @@
|
||||
// <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/>.
|
||||
|
||||
/*
|
||||
Different functions to help with localization, land locales timexone etc
|
||||
*/
|
||||
|
||||
use crate::kira_system::{self, ExecCommandError};
|
||||
use regex_lite::Regex;
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct LocaleData {
|
||||
pub code: String,
|
||||
pub charset: String,
|
||||
pub description: Option<String>,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for LocaleData {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
if let Some(descr) = &self.description {
|
||||
write!(f, "{} ({})", self.code, descr)
|
||||
} else {
|
||||
write!(f, "{}", self.code)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl LocaleData {
|
||||
pub fn default() -> Self {
|
||||
Self {
|
||||
code: "C.UTF-8".into(),
|
||||
charset: "UTF-8".into(),
|
||||
description: Some("C locale".into()),
|
||||
}
|
||||
}
|
||||
|
||||
// creates text to be appended to locale.gen file
|
||||
// in case of C locale outputs empty string
|
||||
pub fn locale_gen_line(&self) -> String {
|
||||
format!("{} {}", &self.code, &self.charset)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct TimeZoneData {
|
||||
pub region: String,
|
||||
pub zone: String,
|
||||
}
|
||||
|
||||
impl TimeZoneData {
|
||||
fn from_str(s: &str) -> Option<Self> {
|
||||
let idx = s.find('/')?;
|
||||
let (region, zone) = s.split_at(idx);
|
||||
Some(Self {
|
||||
region: region.into(),
|
||||
zone: zone.trim_start_matches('/').into(),
|
||||
})
|
||||
}
|
||||
|
||||
///
|
||||
/// Returns full path to timezone file
|
||||
/// Example: "/usr/share/zoneinfo/Region/City"
|
||||
///
|
||||
pub fn tz_file_name(&self) -> String {
|
||||
format!("/usr/share/zoneinfo/{}/{}", &self.region, &self.zone)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for TimeZoneData {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{}/{}", self.region, self.zone)
|
||||
}
|
||||
}
|
||||
|
||||
const LOCALES_GEN_FILE_NAME: &str = "/etc/locale.gen";
|
||||
|
||||
/// gets locales list from system "/etc/locale.gen" file
|
||||
/// Filters result by filter_charset cahrset Some("UTF-8") to get only UTF-8 locales
|
||||
pub fn get_locales_blocking(
|
||||
filter_charset: Option<&str>,
|
||||
) -> Result<Vec<LocaleData>, ExecCommandError> {
|
||||
use std::fs::File;
|
||||
use std::io::{BufReader, Read};
|
||||
|
||||
//pt_PT@euro ISO-8859-15
|
||||
//ru_UA.UTF-8 UTF-8
|
||||
//#ru_UA KOI8-U
|
||||
//
|
||||
// Example ru_UA.UTF-8 UTF-8
|
||||
// Groups:
|
||||
// 1: code, like ru_UA.UTF-8
|
||||
// 3 charser: UTF-8
|
||||
let key_re = Regex::new(r"^[[:word:]@]+").unwrap();
|
||||
let loc_re = Regex::new(r"^#?([[:word:].@-]+) ([0-9A-Z-]+)$").unwrap();
|
||||
|
||||
let loc_desc = get_loc_descr_blocking()?;
|
||||
|
||||
let mut res: Vec<LocaleData> = Vec::new();
|
||||
let mut file_content = String::new();
|
||||
{
|
||||
let locgen_file = File::open(LOCALES_GEN_FILE_NAME)?;
|
||||
let mut reader = BufReader::new(locgen_file);
|
||||
reader.read_to_string(&mut file_content)?;
|
||||
}
|
||||
for loc_line in file_content.lines() {
|
||||
if let Some(captured) = loc_re.captures(loc_line.trim_end()) {
|
||||
let code = captured[1].to_string();
|
||||
let charset = captured[2].to_string();
|
||||
// filters charset
|
||||
if let Some(flt) = filter_charset
|
||||
&& charset != flt
|
||||
{
|
||||
continue;
|
||||
}
|
||||
let description = key_re
|
||||
.find(&code)
|
||||
.and_then(|m| loc_desc.get(m.as_str()).cloned());
|
||||
|
||||
res.push(LocaleData {
|
||||
code: code,
|
||||
charset: charset,
|
||||
description: description,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
res.push(LocaleData::default());
|
||||
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
/// Gets locales description from "/usr/share/i18n/locales/" directory.
|
||||
fn get_loc_descr_blocking() -> Result<HashMap<String, String>, ExecCommandError> {
|
||||
// use std::process::Command;
|
||||
|
||||
// /usr/share/i18n/locales/uz_UZ:title "Uzbek (latin) locale for Uzbekistan"
|
||||
// /usr/share/i18n/locales/uz_UZ@cyrillic:title "Uzbek (cyrillic) locale for Uzbekistan"
|
||||
// 1 group - key code
|
||||
// 2 group - description
|
||||
let descr_re = Regex::new(r#"^/usr/share/i18n/locales/(.+):title[[:space:]]+"(.+)"$"#).unwrap();
|
||||
|
||||
let mut res: HashMap<String, String> = HashMap::new();
|
||||
|
||||
let raw_list =
|
||||
kira_system::exec_command_out("grep", &vec!["-r", "title ", "/usr/share/i18n/locales/"])?;
|
||||
|
||||
for descr_line in raw_list.lines() {
|
||||
if let Some(captured) = descr_re.captures(descr_line.trim_end()) {
|
||||
res.insert(captured[1].to_string(), captured[2].to_string());
|
||||
}
|
||||
}
|
||||
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
/// Getting list of awailable timezones from system.
|
||||
pub fn get_timezones_blocking() -> Result<Vec<TimeZoneData>, kira_system::ExecCommandError> {
|
||||
use std::path::Path;
|
||||
let loc_path: &Path = Path::new("/usr/share/zoneinfo");
|
||||
|
||||
let tz_list = kira_system::ls_dir_rec(loc_path)?;
|
||||
|
||||
Ok(tz_list
|
||||
.iter()
|
||||
.filter(|sb| sb.contains('/'))
|
||||
.filter(|sb| !sb.starts_with("posix")) //filter out posix dir that contains copies
|
||||
.filter_map(|str_t_zone| TimeZoneData::from_str(str_t_zone.trim()))
|
||||
.collect::<Vec<TimeZoneData>>())
|
||||
}
|
||||
|
||||
///
|
||||
/// Function for making wild guess of locale by landguage code and timezone(if provided)
|
||||
/// Ugly, needs some cleanups
|
||||
///
|
||||
pub fn guess_locale(
|
||||
locales: &Vec<LocaleData>,
|
||||
lang_code: &str,
|
||||
maybe_tz: Option<TimeZoneData>,
|
||||
) -> Option<LocaleData> {
|
||||
use crate::tz_to_cc::get_cc;
|
||||
// if we get lang code from wellcome stage, try to fing match with system locales
|
||||
|
||||
let lang = lang_code.replace("-", "_").to_lowercase();
|
||||
|
||||
let locales_filtered: Vec<LocaleData> = locales
|
||||
.iter()
|
||||
.filter(|l| l.code.to_lowercase().starts_with(&lang))
|
||||
.cloned()
|
||||
.collect();
|
||||
|
||||
if locales_filtered.len() == 0 {
|
||||
None
|
||||
}
|
||||
// return locale if ve found exactly one
|
||||
else if locales_filtered.len() == 1 {
|
||||
locales_filtered.first().cloned()
|
||||
}
|
||||
// else do search
|
||||
else {
|
||||
// try to use country guessed from timezone
|
||||
let loc_country_guess = maybe_tz
|
||||
.and_then(|tz| get_cc(&tz.region, &tz.zone))
|
||||
.and_then(|cc| {
|
||||
// try to search for lang_contry in locales
|
||||
let lang_search = if lang.contains('_') {
|
||||
lang.clone()
|
||||
} else {
|
||||
format!("{}_{}", lang, cc.to_lowercase())
|
||||
};
|
||||
|
||||
locales_filtered
|
||||
.iter()
|
||||
.find(|l| l.code.to_lowercase().starts_with(&lang_search))
|
||||
.cloned()
|
||||
});
|
||||
|
||||
// if we guessed locale by country return it
|
||||
if loc_country_guess.is_some() {
|
||||
loc_country_guess
|
||||
// if language is en - return C locale
|
||||
} else if lang == "en" {
|
||||
Some(LocaleData::default())
|
||||
// else try to gess purely by language code
|
||||
} else {
|
||||
if lang.contains('_') {
|
||||
locales_filtered
|
||||
.iter()
|
||||
.find(|l| l.code.to_lowercase().starts_with(&lang))
|
||||
.cloned()
|
||||
} else {
|
||||
let lang_search = format!("{}_{}", lang, lang);
|
||||
locales_filtered
|
||||
.iter()
|
||||
.find(|l| l.code.to_lowercase().starts_with(&lang_search))
|
||||
.cloned()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
use log::{Level, Metadata, Record, SetLoggerError, LevelFilter};
|
||||
use std::fs::{File, OpenOptions};
|
||||
use std::io::Write;
|
||||
use std::sync::Mutex;
|
||||
use std::sync::LazyLock;
|
||||
use time_format;
|
||||
|
||||
struct KiraLogger {
|
||||
file: Option<Mutex<File>>,
|
||||
}
|
||||
|
||||
impl KiraLogger {
|
||||
pub fn open(file_name: Option<&str>) -> std::io::Result<Self> {
|
||||
match file_name {
|
||||
Some(f_n) => Ok(Self {
|
||||
file: Some(Mutex::new(
|
||||
OpenOptions::new().append(true).create(true).open(f_n)?,
|
||||
)),
|
||||
}),
|
||||
None => Ok(Self {
|
||||
file: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl log::Log for KiraLogger {
|
||||
fn enabled(&self, metadata: &Metadata) -> bool {
|
||||
(metadata.target().starts_with("kira_installer") && metadata.level() <= Level::Debug) || (metadata.level() <= Level::Error)
|
||||
}
|
||||
|
||||
fn log(&self, record: &Record) {
|
||||
if self.enabled(record.metadata()) {
|
||||
let ts = time_format::now().unwrap();
|
||||
let local_time = time_format::strftime_local("%Y-%m-%dT%H:%M:%S", ts).unwrap();
|
||||
if let Some(m_file) = &self.file {
|
||||
|
||||
let mut write_lock = m_file.lock().unwrap();
|
||||
let _ = writeln!(&mut *write_lock, "{} {}: {}", local_time, record.level(), record.args());
|
||||
}
|
||||
println!("{} {} {}: {}", local_time,record.metadata().target(), record.level(), record.args());
|
||||
}
|
||||
}
|
||||
|
||||
fn flush(&self) {
|
||||
if let Some(m_file) = &self.file {
|
||||
let mut write_lock = m_file.lock().unwrap();
|
||||
let _ = (&mut *write_lock).flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static LOGGER: LazyLock<KiraLogger> = LazyLock::new(|| {
|
||||
let ts = time_format::now().unwrap();
|
||||
// Local time with timezone name
|
||||
let local_time = time_format::strftime_local("%Y-%m-%d_%H-%M-%S", ts).unwrap();
|
||||
KiraLogger::open(Some(format!("installation_{}.log", local_time).as_str())).unwrap()
|
||||
});
|
||||
|
||||
pub fn init() -> Result<(), SetLoggerError> {
|
||||
log::set_logger(&*LOGGER)
|
||||
.map(|()| log::set_max_level(LevelFilter::Debug))
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
// <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/>.
|
||||
|
||||
/*
|
||||
Scroll List iced widget implementation
|
||||
*/
|
||||
|
||||
use std::fmt::Display;
|
||||
|
||||
use iced::widget::{Column, button, container, scrollable, text};
|
||||
use iced::{Alignment, Color, Element, Length, Theme};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum ListViewMessage {
|
||||
Select(usize),
|
||||
}
|
||||
|
||||
fn unselected_button_style(theme: &Theme, status: button::Status) -> button::Style {
|
||||
use iced::{Border, border::Radius};
|
||||
|
||||
let palette = theme.palette();
|
||||
|
||||
let mut res_stile = button::Style {
|
||||
background: Some(iced::Background::Color(Color::TRANSPARENT)),
|
||||
text_color: palette.text,
|
||||
..button::primary(theme, button::Status::Active)
|
||||
};
|
||||
|
||||
match status {
|
||||
button::Status::Hovered => {
|
||||
res_stile.border = Border {
|
||||
color: Color::from_rgb(0.8, 0.3, 0.3),
|
||||
width: 1.0,
|
||||
radius: Radius::new(5.0),
|
||||
};
|
||||
},
|
||||
_ => (),
|
||||
}
|
||||
|
||||
return res_stile;
|
||||
}
|
||||
|
||||
fn selected_button_style(theme: &Theme, status: button::Status) -> button::Style {
|
||||
use iced::{Border, border::Radius};
|
||||
|
||||
//let palette = theme.palette();
|
||||
|
||||
let mut res_stile = button::primary(theme, button::Status::Active);
|
||||
|
||||
|
||||
match status {
|
||||
button::Status::Hovered => {
|
||||
res_stile.border = Border {
|
||||
color: Color::from_rgb(0.8, 0.3, 0.3),
|
||||
width: 1.0,
|
||||
radius: Radius::new(5.0),
|
||||
};
|
||||
},
|
||||
_ => (),
|
||||
}
|
||||
|
||||
return res_stile;
|
||||
}
|
||||
|
||||
|
||||
// Assuming your Item struct or type implements Display or has a text representation
|
||||
pub fn list_view<T: Display>(
|
||||
items: &Vec<T>,
|
||||
selected_id: Option<usize>,
|
||||
container_height: Length,
|
||||
) -> Element<'_, ListViewMessage> {
|
||||
let mut column = Column::new()
|
||||
.spacing(2)
|
||||
.align_x(Alignment::Center)
|
||||
.width(Length::Fill);
|
||||
|
||||
for (index, value) in items.iter().enumerate() {
|
||||
// Create a row for each item, possibly with buttons or other controls
|
||||
let list_item = if let Some(id) = selected_id
|
||||
&& id == index
|
||||
{
|
||||
button(text(value.to_string())).style(selected_button_style)
|
||||
} else {
|
||||
button(text(value.to_string())).style(unselected_button_style)
|
||||
};
|
||||
let list_item = list_item
|
||||
.width(Length::Fill)
|
||||
.on_press(ListViewMessage::Select(index));
|
||||
|
||||
column = column.push(list_item);
|
||||
}
|
||||
|
||||
// Wrap the column in a scrollable widget
|
||||
container(scrollable(column).width(Length::Fill).spacing(5))
|
||||
.style(container::bordered_box)
|
||||
.height(container_height)
|
||||
.padding(5)
|
||||
.into()
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
// <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/>.
|
||||
|
||||
/*
|
||||
KiraSize struct implementation for work with base2 sizes.
|
||||
*/
|
||||
|
||||
use std::ops::{Add, Sub};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct KiraSize {
|
||||
size_bytes: u64,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for KiraSize {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
if self.size_bytes < 1000 {
|
||||
write!(f, "{}B", self.size_bytes)
|
||||
} else {
|
||||
let mut s = self.size_bytes as f64;
|
||||
let mut idx = 0;
|
||||
for i in 0..5 {
|
||||
s = s / 1024.0;
|
||||
idx = i;
|
||||
if s < 1000.0 {
|
||||
break;
|
||||
}
|
||||
}
|
||||
write!(f, "{:.2}{}", s, Self::SUFFIXS[idx])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 }
|
||||
}
|
||||
pub fn new_kb(size:u64) -> Self {
|
||||
Self { size_bytes: size * 1024 }
|
||||
}
|
||||
pub fn new_mb(size:u64) -> Self {
|
||||
Self { size_bytes: size * 1024u64.pow(2) }
|
||||
}
|
||||
pub fn new_gb(size:u64) -> Self {
|
||||
Self { size_bytes: size * 1024u64.pow(3) }
|
||||
}
|
||||
pub fn new_tb(size:u64) -> Self {
|
||||
Self { size_bytes: size * 1024u64.pow(4) }
|
||||
}
|
||||
pub fn new_pb(size:u64) -> Self {
|
||||
Self { size_bytes: size * 1024u64.pow(5) }
|
||||
}
|
||||
|
||||
pub fn b(&self) -> u64 {
|
||||
self.size_bytes
|
||||
}
|
||||
pub fn kb(&self) -> u64 {
|
||||
self.size_bytes / 1024u64
|
||||
}
|
||||
pub fn mb(&self) -> u64 {
|
||||
self.size_bytes / 1024u64.pow(2)
|
||||
}
|
||||
pub fn gb(&self) -> u64 {
|
||||
self.size_bytes / 1024u64.pow(3)
|
||||
}
|
||||
pub fn tb(&self) -> u64 {
|
||||
self.size_bytes / 1024u64.pow(4)
|
||||
}
|
||||
pub fn pb(&self) -> u64 {
|
||||
self.size_bytes / 1024u64.pow(5)
|
||||
}
|
||||
|
||||
pub fn from_str_bytes(s: &str) -> Option<Self> {
|
||||
Some(Self::new_b(u64::from_str_radix(s, 10).ok()?))
|
||||
}
|
||||
|
||||
pub fn div_c(self, other: u64) -> Self {
|
||||
Self { size_bytes: self.size_bytes / other }
|
||||
}
|
||||
|
||||
///
|
||||
/// Panics if overflow accurs.
|
||||
///
|
||||
pub fn mul_c(self, other: u64) -> Self {
|
||||
Self { size_bytes: self.size_bytes.strict_mul(other) }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl Add for KiraSize {
|
||||
type Output = KiraSize;
|
||||
|
||||
fn add(self, other: KiraSize) -> Self::Output {
|
||||
KiraSize {
|
||||
size_bytes: self.size_bytes + other.size_bytes,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Sub for KiraSize {
|
||||
type Output = KiraSize;
|
||||
|
||||
/// Panics if overflow accors.
|
||||
fn sub(self, other: KiraSize) -> Self::Output {
|
||||
KiraSize {
|
||||
size_bytes: self.size_bytes.strict_sub(other.size_bytes),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
// <Kira Installer - universal Linux installer.>
|
||||
// Copyright (C) <2026> <Kira Foundation> <Kira>
|
||||
|
||||
// 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/>.
|
||||
|
||||
/*
|
||||
This file contains functions to query system information.
|
||||
*/
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::fs;
|
||||
|
||||
///
|
||||
/// vis_vram_total - size of vram in bytes
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct GpuInfo {
|
||||
pub id: u8,
|
||||
pub name: String,
|
||||
pub vis_vram_total: u64,
|
||||
}
|
||||
|
||||
/// See /proc/meminfo output format and units (kB)
|
||||
pub fn get_meminfo() -> HashMap<String, u64> {
|
||||
let mem_info_str = fs::read_to_string("/proc/meminfo").unwrap();
|
||||
|
||||
mem_info_str
|
||||
.lines()
|
||||
.filter_map(|l| {
|
||||
l.split_once(':').and_then(|(k, v)| {
|
||||
u64::from_str_radix(v.trim_end_matches("kB").trim(), 10)
|
||||
.ok()
|
||||
.and_then(|v_num| Some((k.to_string(), v_num)))
|
||||
})
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
// cat /sys/class/drm/card1/device/mem_info_vis_vram_total
|
||||
pub fn get_gpus_list() -> Vec<GpuInfo> {
|
||||
let drm_devs_dirs: Vec<(String, u8)> = fs::read_dir("/sys/class/drm/")
|
||||
.unwrap()
|
||||
.filter_map(|maybe_entry| {
|
||||
maybe_entry.ok().and_then(|entry| {
|
||||
entry.file_type().ok().and_then(|ft| {
|
||||
if ft.is_symlink() || ft.is_dir() {
|
||||
entry.file_name().into_string().ok()
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
.filter(|f_name| f_name.len() == 5 && f_name.starts_with("card"))
|
||||
.filter_map(|dir_name| {
|
||||
dir_name.split_once("card").and_then(|name_touple| {
|
||||
u8::from_str_radix(name_touple.1, 10)
|
||||
.ok()
|
||||
.and_then(|gpu_id| Some((dir_name.clone(), gpu_id)))
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
|
||||
let res: Vec<GpuInfo> = drm_devs_dirs
|
||||
.iter()
|
||||
.filter_map(|(d, id)| {
|
||||
fs::read_to_string(format!(
|
||||
"/sys/class/drm/{}/device/mem_info_vis_vram_total",
|
||||
d
|
||||
))
|
||||
.ok()
|
||||
.and_then(|mem_str| {
|
||||
u64::from_str_radix(mem_str.trim(), 10)
|
||||
.ok()
|
||||
.and_then(|mem_size| {
|
||||
Some(GpuInfo {
|
||||
id: *id,
|
||||
name: d.clone(),
|
||||
vis_vram_total: mem_size,
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
|
||||
res
|
||||
}
|
||||
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct SecureBootStatus {
|
||||
pub installed: bool,
|
||||
pub guid: String,
|
||||
pub setup_mode: bool,
|
||||
pub secure_boot: bool,
|
||||
pub vendors: Vec<String>,
|
||||
pub firmware_quirks: Vec<String>,
|
||||
}
|
||||
|
||||
pub fn get_secure_boot_status() -> Result<SecureBootStatus, String> {
|
||||
use std::process::Command;
|
||||
|
||||
//sbctl --json status
|
||||
match Command::new("sbctl").args(["--json", "status"]).output() {
|
||||
Ok(cmd_output) => {
|
||||
if cmd_output.status.success() {
|
||||
match serde_json::from_slice(&cmd_output.stdout) {
|
||||
Ok(res) => Ok(res),
|
||||
Err(ex) => Err(ex.to_string()),
|
||||
}
|
||||
} else {
|
||||
Err(format!(
|
||||
"Error getting disk devices list: {}",
|
||||
String::from_utf8(cmd_output.stderr).unwrap_or("UNKNOWN".into())
|
||||
))
|
||||
}
|
||||
}
|
||||
Err(ex) => Err(ex.to_string()),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,562 @@
|
||||
// <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/>.
|
||||
|
||||
/*
|
||||
Different functions for interacting with Linux system
|
||||
*/
|
||||
|
||||
use crate::kira_disk_layout::*;
|
||||
use crate::kira_size::KiraSize;
|
||||
use std::fmt::format;
|
||||
use std::fs;
|
||||
use std::io::Read;
|
||||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct CommandFailed {
|
||||
stderr: Vec<u8>,
|
||||
cmd: String,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for CommandFailed {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"Command failed! Command: {}; Stderr: {}",
|
||||
self.cmd,
|
||||
String::from_utf8(self.stderr.clone())
|
||||
.unwrap_or_else(|_| { "STDEER IS NOT VALID UTF-8".to_string() })
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl CommandFailed {
|
||||
pub fn new(cmd: &str, args: &Vec<&str>, stderr: Vec<u8>) -> Self {
|
||||
Self {
|
||||
stderr: stderr,
|
||||
cmd: format!("{} {}", cmd, args.join(" ")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum ExecCommandError {
|
||||
IoError(std::io::Error),
|
||||
FromUtf8Error(std::string::FromUtf8Error),
|
||||
CommandFailed(CommandFailed),
|
||||
Other(String),
|
||||
}
|
||||
|
||||
// 2. Implement From for each wrapped error type
|
||||
impl From<std::io::Error> for ExecCommandError {
|
||||
fn from(err: std::io::Error) -> Self {
|
||||
ExecCommandError::IoError(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<std::string::FromUtf8Error> for ExecCommandError {
|
||||
fn from(err: std::string::FromUtf8Error) -> Self {
|
||||
ExecCommandError::FromUtf8Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CommandFailed> for ExecCommandError {
|
||||
fn from(err: CommandFailed) -> Self {
|
||||
ExecCommandError::CommandFailed(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<String> for ExecCommandError {
|
||||
fn from(err: String) -> Self {
|
||||
ExecCommandError::Other(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for ExecCommandError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
match self {
|
||||
ExecCommandError::IoError(e) => write!(f, "IO Error: {}", e),
|
||||
ExecCommandError::FromUtf8Error(e) => {
|
||||
write!(f, "IO streem to String parse Error: {}", e)
|
||||
}
|
||||
ExecCommandError::CommandFailed(ex) => {
|
||||
write!(f, "{}", ex)
|
||||
}
|
||||
ExecCommandError::Other(msg) => write!(f, "Error: {}", msg),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Implement std::error::Error
|
||||
impl std::error::Error for ExecCommandError {}
|
||||
|
||||
/// exec given sommand with arguments, capturing stderr in case or failure
|
||||
pub fn exec_command_stdin(
|
||||
cmd: &str,
|
||||
args: &Vec<&str>,
|
||||
stdin_data: &str,
|
||||
) -> Result<(), ExecCommandError> {
|
||||
use std::io::Write;
|
||||
use std::process::{Command, Stdio};
|
||||
use std::thread;
|
||||
|
||||
let mut child = Command::new(cmd)
|
||||
.args(args)
|
||||
.stdin(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
.spawn()?;
|
||||
|
||||
let mut stdin = child
|
||||
.stdin
|
||||
.take()
|
||||
.ok_or("Failed to capture stdin".to_string())?;
|
||||
|
||||
let mut stderr = child
|
||||
.stderr
|
||||
.take()
|
||||
.ok_or("Failed to capture stderr".to_string())?;
|
||||
|
||||
let stderr_handle = thread::spawn(move || {
|
||||
let mut buf = Vec::new();
|
||||
use std::io::Read;
|
||||
let _ = stderr.read_to_end(&mut buf);
|
||||
buf
|
||||
});
|
||||
|
||||
stdin.write_all(stdin_data.as_bytes())?;
|
||||
|
||||
let status = child.wait()?;
|
||||
let stderr_output = stderr_handle.join().unwrap();
|
||||
|
||||
if status.success() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(CommandFailed::new(cmd, args, stderr_output).into())
|
||||
}
|
||||
}
|
||||
|
||||
/// exec given sommand with arguments, capturing stderr in case or failure
|
||||
pub fn exec_command(cmd: &str, args: &Vec<&str>) -> Result<(), ExecCommandError> {
|
||||
let out = Command::new(cmd).args(args).output()?;
|
||||
if out.status.success() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(CommandFailed::new(cmd, args, out.stderr).into())
|
||||
}
|
||||
}
|
||||
|
||||
/// exec given sommand with arguments, returning stdout parsed to UTF-8 string
|
||||
/// capturing stderr in case or failure
|
||||
pub fn exec_command_out(cmd: &str, args: &Vec<&str>) -> Result<String, ExecCommandError> {
|
||||
let out = Command::new(cmd).args(args).output()?;
|
||||
if out.status.success() {
|
||||
Ok(String::from_utf8(out.stdout)?)
|
||||
} else {
|
||||
Err(CommandFailed::new(cmd, args, out.stderr).into())
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
/// Exec command and logs its output via log::info! in real time
|
||||
///
|
||||
fn exec_command_log(cmd: &str, args: &Vec<&str>) -> Result<(), ExecCommandError> {
|
||||
use std::io::{BufRead, BufReader};
|
||||
use std::process::{Command, Stdio};
|
||||
use std::thread;
|
||||
|
||||
log::debug!("Executing command {} {:?}", cmd, args);
|
||||
|
||||
// Configure the command to pipe stdout
|
||||
let mut child = Command::new(cmd)
|
||||
.args(args)
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
.spawn()?;
|
||||
|
||||
// Take ownership of the stdout handle
|
||||
let stdout = child
|
||||
.stdout
|
||||
.take()
|
||||
.ok_or("Failed to capture stdout".to_string())?;
|
||||
let mut stderr = child
|
||||
.stderr
|
||||
.take()
|
||||
.ok_or("Failed to capture stderr".to_string())?;
|
||||
|
||||
let stderr_handle = thread::spawn(move || {
|
||||
let mut buf = Vec::new();
|
||||
use std::io::Read;
|
||||
let _ = stderr.read_to_end(&mut buf);
|
||||
buf
|
||||
});
|
||||
|
||||
// Wrap in BufReader for efficient line-by-line reading
|
||||
let reader = BufReader::new(stdout);
|
||||
|
||||
// Iterate and log each line in real time
|
||||
for line in reader.lines() {
|
||||
match line {
|
||||
Ok(text) => log::info!("{}: {}", cmd, text),
|
||||
Err(e) => log::error!("Read error: {}", e),
|
||||
}
|
||||
}
|
||||
|
||||
// Wait for the process to finish to prevent zombies and check status
|
||||
let status = child.wait()?;
|
||||
let stderr_output = stderr_handle.join().unwrap();
|
||||
|
||||
if status.success() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(CommandFailed::new(cmd, args, stderr_output).into())
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
/// Chroot to chroot_dir and executes specified command there
|
||||
///
|
||||
pub fn exec_cmd_chroot(
|
||||
chroot_dir: &str,
|
||||
cmd: &str,
|
||||
args: &Vec<&str>,
|
||||
) -> Result<(), ExecCommandError> {
|
||||
let mut cmd_args: Vec<&str> = Vec::new();
|
||||
cmd_args.push(chroot_dir);
|
||||
cmd_args.push(cmd);
|
||||
cmd_args.extend(args);
|
||||
exec_command("artix-chroot", &cmd_args)
|
||||
}
|
||||
|
||||
/// sync system time with chrony
|
||||
/// dinitctl start chrony
|
||||
pub fn dinit_sync_time_chrony() -> Result<(), ExecCommandError> {
|
||||
exec_command("dinitctl", &vec!["start", "chrony"])
|
||||
}
|
||||
|
||||
/// Install base system
|
||||
/// basestrap /mnt base base-devel dinit elogind-dinit
|
||||
pub fn basestrap_dinit(root_dir: &str) -> Result<(), ExecCommandError> {
|
||||
exec_command_log(
|
||||
"basestrap",
|
||||
&vec![root_dir, "base", "base-devel", "dinit", "elogind-dinit"],
|
||||
)
|
||||
}
|
||||
|
||||
pub fn basestrap(root_dir: &str, pkg_list: &[&str]) -> Result<(), ExecCommandError> {
|
||||
let mut args: Vec<&str> = vec![root_dir];
|
||||
args.extend(pkg_list);
|
||||
exec_command_log("basestrap", &args)
|
||||
}
|
||||
|
||||
/// Executes parted command with given arguments
|
||||
fn exec_parted(args: &Vec<&str>) -> Result<String, ExecCommandError> {
|
||||
exec_command_out("parted", args)
|
||||
}
|
||||
|
||||
fn parted_get_last_part_num(dev: &BlkDev) -> Result<u32, ExecCommandError> {
|
||||
// parted -m /dev/loop0 print
|
||||
let res = exec_parted(&vec!["-m", dev.full_name().as_str(), "print"])?;
|
||||
|
||||
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().into()),
|
||||
}
|
||||
}
|
||||
|
||||
/// init gpt partition table
|
||||
/// parted --script $install_device mklabel gpt
|
||||
/// Its blocking function
|
||||
pub fn parted_init_gpt_part_table(dev: &BlkDev) -> Result<(), ExecCommandError> {
|
||||
let dev_full_name = dev.full_name();
|
||||
let args = vec!["--script", &dev_full_name, "mklabel", "gpt"];
|
||||
exec_command("parted", &args)
|
||||
}
|
||||
|
||||
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<(), ExecCommandError> {
|
||||
// important to shift here by 1 because disk index is starting from 0, and part end pointing to last byte of the partition.
|
||||
let part_end = part.part_end();
|
||||
|
||||
// gpt label should be in double qutes
|
||||
let gpt_label = if let Some(s) = &part.gpt_label {
|
||||
format!("\"{}\"", s)
|
||||
} else {
|
||||
"\"\"".to_string()
|
||||
};
|
||||
log::debug!(
|
||||
"Creatin partition dev:{}, label:{}, fs_type:{}, start:{}, end:{}",
|
||||
dev.full_name(),
|
||||
gpt_label,
|
||||
part.fs_type.to_parted_str(),
|
||||
part.start.to_parted_bytes_str(),
|
||||
part_end.to_parted_bytes_str()
|
||||
);
|
||||
// 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
|
||||
/// compression: lz4, zstd
|
||||
pub fn bcachefs_format(
|
||||
dev_name: &str,
|
||||
compression: Option<String>,
|
||||
password: Option<String>,
|
||||
) -> Result<(), ExecCommandError> {
|
||||
// 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
|
||||
|
||||
let mut arg = vec!["format", "--force"];
|
||||
// if compression algorythm specified
|
||||
let maybe_comp_cmd = compression.and_then(|alg| Some(format!("--compression={}", alg)));
|
||||
if let Some(comp_cmd) = &maybe_comp_cmd {
|
||||
arg.push(comp_cmd);
|
||||
}
|
||||
// if we want encrypted volume
|
||||
if let Some(passw) = password {
|
||||
// creating tmp file with password
|
||||
fs::write("/tmp/bzzpsspass.txt", &passw)?;
|
||||
arg.push("--encrypted");
|
||||
arg.push("--passphrase_file=/tmp/bzzpsspass.txt");
|
||||
}
|
||||
|
||||
// add dev name at the end
|
||||
arg.push(dev_name);
|
||||
|
||||
let out = exec_command("bcachefs", &arg);
|
||||
|
||||
// ignore any errors while deleting pass tmp file
|
||||
let _ = fs::remove_file("/tmp/bzzpsspass.txt");
|
||||
|
||||
out
|
||||
}
|
||||
|
||||
/// unlok encrypted bcache volume
|
||||
pub fn bcachefs_unlock(dev_name: &str, pass: &str) -> Result<(), ExecCommandError> {
|
||||
// bcachefs unlock --file=/tmp/bzzpsspass.txt /dev/loop0
|
||||
let arg = vec!["unlock", "--file=/tmp/bzzpsspass.txt ", dev_name];
|
||||
// creating tmp file with password
|
||||
fs::write("/tmp/bzzpsspass.txt", &pass)?;
|
||||
|
||||
let out = exec_command("bcachefs", &arg);
|
||||
// ignore any errors while deleting pass tmp file
|
||||
let _ = fs::remove_file("/tmp/bzzpsspass.txt");
|
||||
|
||||
out
|
||||
}
|
||||
|
||||
/// create subvolume
|
||||
pub fn bcachefs_create_subvolume(vol_path: &str) -> Result<(), ExecCommandError> {
|
||||
// sudo bcachefs subvolume create /mnt/test/nyan
|
||||
exec_command("bcachefs", &vec!["subvolume", "create", vol_path])
|
||||
}
|
||||
|
||||
/// mount bcachefs
|
||||
pub fn bcachefs_mount(dev_name: &str, mount_point: &str) -> Result<(), ExecCommandError> {
|
||||
// sudo mount -t bcachefs /dev/loop0 /mnt/test
|
||||
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])
|
||||
}
|
||||
|
||||
pub fn mkfs_fat32(dev: &str, maybe_label: Option<&str>) -> Result<(), ExecCommandError> {
|
||||
//mkfs.fat -F 32 /dev/sda1
|
||||
exec_command("mkfs.fat", &vec!["-F", "32", dev])?;
|
||||
|
||||
// if need to set label
|
||||
if let Some(label) = maybe_label {
|
||||
fatlabel(dev, label)
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// mkfs.fat -F 32 /dev/sda1
|
||||
/// fatlabel /dev/sda1 ESP
|
||||
pub fn mkfs_esp(dev: &str) -> Result<(), ExecCommandError> {
|
||||
mkfs_fat32(dev, Some("ESP"))
|
||||
}
|
||||
|
||||
pub fn mkswap(dev: &str) -> Result<(), ExecCommandError> {
|
||||
//mkswap -L SWAP /dev/sda4
|
||||
exec_command("mkswap", &vec!["-L", "bee-swap", dev])
|
||||
}
|
||||
|
||||
///
|
||||
/// Returns list of files in directory and all subdirectories.
|
||||
/// Files in subdirectories listed with path related to specified dir.
|
||||
/// For example subdir1/subdir2/file.
|
||||
/// Function do not traverse symlinks and ignores them in output.
|
||||
///
|
||||
pub fn ls_dir_rec(dir_part: &Path) -> Result<Vec<String>, std::io::Error> {
|
||||
///
|
||||
/// root_path should point to dir
|
||||
///
|
||||
fn ls_subdir_rec(
|
||||
root_path: &Path,
|
||||
prefix: String,
|
||||
mut res: Vec<String>,
|
||||
) -> Result<Vec<String>, std::io::Error> {
|
||||
for dir_entry in fs::read_dir(root_path)? {
|
||||
let dir_entry = dir_entry?;
|
||||
let dir_entry_ft = dir_entry.file_type()?;
|
||||
let next_prefix = format!("{}/{}", prefix, dir_entry.file_name().to_string_lossy());
|
||||
if dir_entry_ft.is_dir() {
|
||||
res = ls_subdir_rec(&dir_entry.path(), next_prefix, res)?;
|
||||
} else if dir_entry_ft.is_file() {
|
||||
res.push(next_prefix);
|
||||
}
|
||||
}
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
let mut res: Vec<String> = Vec::new();
|
||||
//let loc_path: &Path = Path::new("/usr/share/zoneinfo");
|
||||
|
||||
if dir_part.is_dir() {
|
||||
for d_entry in fs::read_dir(dir_part)? {
|
||||
let d_entry = d_entry?;
|
||||
let d_entry_ft = d_entry.file_type()?;
|
||||
let d_entry_name = d_entry.file_name().to_string_lossy().to_string();
|
||||
if d_entry_ft.is_dir() {
|
||||
res = ls_subdir_rec(&d_entry.path(), d_entry_name, res)?;
|
||||
} else if d_entry_ft.is_file() {
|
||||
// Add file to list
|
||||
res.push(d_entry_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
///
|
||||
/// Generates fstab file similar to
|
||||
/// fstabgen -t PARTLABEL mnt_dir >> mnt_dir/etc/fstab
|
||||
///
|
||||
pub fn fstabgen(mnt_dir: &str) -> Result<(), ExecCommandError> {
|
||||
let fstab_file_name = format!("{}/etc/fstab", mnt_dir);
|
||||
let fstab = exec_command_out("fstabgen", &vec!["-t", "PARTLABEL", mnt_dir])?;
|
||||
fs::write(&fstab_file_name, fstab)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
///
|
||||
/// Executes passwd --stdin --root chroot_dir root
|
||||
/// To set new root password in specified chroot env
|
||||
///
|
||||
pub fn set_root_passwd(chroot_dir: &str, root_passwd: &str) -> Result<(), ExecCommandError> {
|
||||
exec_command_stdin(
|
||||
"passwd",
|
||||
&vec!["--stdin", "--root", chroot_dir, "root"],
|
||||
root_passwd,
|
||||
)
|
||||
}
|
||||
|
||||
// /
|
||||
// / Sends Dbus message locale1 to change input method
|
||||
// / SetX11Keyboard(layout: s, model: s, variant: s, options: s, convert: b, interactive: b)
|
||||
// /
|
||||
// pub async fn set_input_method(
|
||||
// layout: &str,
|
||||
// model: &str,
|
||||
// variant: &str,
|
||||
// options: &str,
|
||||
// ) -> zbus::Result<()> {
|
||||
// use zbus::Connection;
|
||||
|
||||
// let conn = Connection::system().await?;
|
||||
// log::info!("Sending dbus message to change layout");
|
||||
// log::info!(
|
||||
// "layout: {}, model: {}, variant: {}, options: {}",
|
||||
// layout,
|
||||
// model,
|
||||
// variant,
|
||||
// options
|
||||
// );
|
||||
// let resp = conn
|
||||
// .call_method(
|
||||
// Some("org.freedesktop.locale1"),
|
||||
// "/org/freedesktop/locale1",
|
||||
// Some("org.freedesktop.locale1"),
|
||||
// "SetX11Keyboard",
|
||||
// &(layout, model, variant, options, true, false),
|
||||
// )
|
||||
// .await?;
|
||||
|
||||
// log::info!("Dbus response: {}", resp.to_string());
|
||||
|
||||
// Ok(())
|
||||
// }
|
||||
@@ -0,0 +1,189 @@
|
||||
//! Track the cursor of a text input.
|
||||
use crate::kira_text_input::Value;
|
||||
|
||||
/// The cursor of a text input.
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
pub struct Cursor {
|
||||
state: State,
|
||||
}
|
||||
|
||||
/// The state of a [`Cursor`].
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
pub enum State {
|
||||
/// Cursor without a selection
|
||||
Index(usize),
|
||||
|
||||
/// Cursor selecting a range of text
|
||||
Selection {
|
||||
/// The start of the selection
|
||||
start: usize,
|
||||
/// The end of the selection
|
||||
end: usize,
|
||||
},
|
||||
}
|
||||
|
||||
impl Default for Cursor {
|
||||
fn default() -> Self {
|
||||
Cursor {
|
||||
state: State::Index(0),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Cursor {
|
||||
/// Returns the [`State`] of the [`Cursor`].
|
||||
pub fn state(&self, value: &Value) -> State {
|
||||
match self.state {
|
||||
State::Index(index) => State::Index(index.min(value.len())),
|
||||
State::Selection { start, end } => {
|
||||
let start = start.min(value.len());
|
||||
let end = end.min(value.len());
|
||||
|
||||
if start == end {
|
||||
State::Index(start)
|
||||
} else {
|
||||
State::Selection { start, end }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the current selection of the [`Cursor`] for the given [`Value`].
|
||||
///
|
||||
/// `start` is guaranteed to be <= than `end`.
|
||||
pub fn selection(&self, value: &Value) -> Option<(usize, usize)> {
|
||||
match self.state(value) {
|
||||
State::Selection { start, end } => {
|
||||
Some((start.min(end), start.max(end)))
|
||||
}
|
||||
State::Index(_) => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn move_to(&mut self, position: usize) {
|
||||
self.state = State::Index(position);
|
||||
}
|
||||
|
||||
pub(crate) fn move_right(&mut self, value: &Value) {
|
||||
self.move_right_by_amount(value, 1);
|
||||
}
|
||||
|
||||
pub(crate) fn move_right_by_words(&mut self, value: &Value) {
|
||||
self.move_to(value.next_end_of_word(self.right(value)));
|
||||
}
|
||||
|
||||
pub(crate) fn move_right_by_amount(
|
||||
&mut self,
|
||||
value: &Value,
|
||||
amount: usize,
|
||||
) {
|
||||
match self.state(value) {
|
||||
State::Index(index) => {
|
||||
self.move_to(index.saturating_add(amount).min(value.len()));
|
||||
}
|
||||
State::Selection { start, end } => self.move_to(end.max(start)),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn move_left(&mut self, value: &Value) {
|
||||
match self.state(value) {
|
||||
State::Index(index) if index > 0 => self.move_to(index - 1),
|
||||
State::Selection { start, end } => self.move_to(start.min(end)),
|
||||
State::Index(_) => self.move_to(0),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn move_left_by_words(&mut self, value: &Value) {
|
||||
self.move_to(value.previous_start_of_word(self.left(value)));
|
||||
}
|
||||
|
||||
pub(crate) fn select_range(&mut self, start: usize, end: usize) {
|
||||
if start == end {
|
||||
self.state = State::Index(start);
|
||||
} else {
|
||||
self.state = State::Selection { start, end };
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn select_left(&mut self, value: &Value) {
|
||||
match self.state(value) {
|
||||
State::Index(index) if index > 0 => {
|
||||
self.select_range(index, index - 1);
|
||||
}
|
||||
State::Selection { start, end } if end > 0 => {
|
||||
self.select_range(start, end - 1);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn select_right(&mut self, value: &Value) {
|
||||
match self.state(value) {
|
||||
State::Index(index) if index < value.len() => {
|
||||
self.select_range(index, index + 1);
|
||||
}
|
||||
State::Selection { start, end } if end < value.len() => {
|
||||
self.select_range(start, end + 1);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn select_left_by_words(&mut self, value: &Value) {
|
||||
match self.state(value) {
|
||||
State::Index(index) => {
|
||||
self.select_range(index, value.previous_start_of_word(index));
|
||||
}
|
||||
State::Selection { start, end } => {
|
||||
self.select_range(start, value.previous_start_of_word(end));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn select_right_by_words(&mut self, value: &Value) {
|
||||
match self.state(value) {
|
||||
State::Index(index) => {
|
||||
self.select_range(index, value.next_end_of_word(index));
|
||||
}
|
||||
State::Selection { start, end } => {
|
||||
self.select_range(start, value.next_end_of_word(end));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn select_all(&mut self, value: &Value) {
|
||||
self.select_range(0, value.len());
|
||||
}
|
||||
|
||||
pub(crate) fn start(&self, value: &Value) -> usize {
|
||||
let start = match self.state {
|
||||
State::Index(index) => index,
|
||||
State::Selection { start, .. } => start,
|
||||
};
|
||||
|
||||
start.min(value.len())
|
||||
}
|
||||
|
||||
pub(crate) fn end(&self, value: &Value) -> usize {
|
||||
let end = match self.state {
|
||||
State::Index(index) => index,
|
||||
State::Selection { end, .. } => end,
|
||||
};
|
||||
|
||||
end.min(value.len())
|
||||
}
|
||||
|
||||
fn left(&self, value: &Value) -> usize {
|
||||
match self.state(value) {
|
||||
State::Index(index) => index,
|
||||
State::Selection { start, end } => start.min(end),
|
||||
}
|
||||
}
|
||||
|
||||
fn right(&self, value: &Value) -> usize {
|
||||
match self.state(value) {
|
||||
State::Index(index) => index,
|
||||
State::Selection { start, end } => start.max(end),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
use crate::kira_text_input::{Cursor, Value};
|
||||
|
||||
pub struct Editor<'a> {
|
||||
value: &'a mut Value,
|
||||
cursor: &'a mut Cursor,
|
||||
}
|
||||
|
||||
impl<'a> Editor<'a> {
|
||||
pub fn new(value: &'a mut Value, cursor: &'a mut Cursor) -> Editor<'a> {
|
||||
Editor { value, cursor }
|
||||
}
|
||||
|
||||
pub fn contents(&self) -> String {
|
||||
self.value.to_string()
|
||||
}
|
||||
|
||||
pub fn insert(&mut self, character: char) {
|
||||
if let Some((left, right)) = self.cursor.selection(self.value) {
|
||||
self.cursor.move_left(self.value);
|
||||
self.value.remove_many(left, right);
|
||||
}
|
||||
|
||||
self.value.insert(self.cursor.end(self.value), character);
|
||||
self.cursor.move_right(self.value);
|
||||
}
|
||||
|
||||
pub fn paste(&mut self, content: Value) {
|
||||
let length = content.len();
|
||||
if let Some((left, right)) = self.cursor.selection(self.value) {
|
||||
self.cursor.move_left(self.value);
|
||||
self.value.remove_many(left, right);
|
||||
}
|
||||
|
||||
self.value.insert_many(self.cursor.end(self.value), content);
|
||||
|
||||
self.cursor.move_right_by_amount(self.value, length);
|
||||
}
|
||||
|
||||
pub fn backspace(&mut self) {
|
||||
match self.cursor.selection(self.value) {
|
||||
Some((start, end)) => {
|
||||
self.cursor.move_left(self.value);
|
||||
self.value.remove_many(start, end);
|
||||
}
|
||||
None => {
|
||||
let start = self.cursor.start(self.value);
|
||||
|
||||
if start > 0 {
|
||||
self.cursor.move_left(self.value);
|
||||
self.value.remove(start - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn delete(&mut self) {
|
||||
match self.cursor.selection(self.value) {
|
||||
Some(_) => {
|
||||
self.backspace();
|
||||
}
|
||||
None => {
|
||||
let end = self.cursor.end(self.value);
|
||||
|
||||
if end < self.value.len() {
|
||||
self.value.remove(end);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,136 @@
|
||||
use unicode_segmentation::UnicodeSegmentation;
|
||||
|
||||
/// The value of a [`TextInput`].
|
||||
///
|
||||
/// [`TextInput`]: super::TextInput
|
||||
// TODO: Reduce allocations, cache results (?)
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Value {
|
||||
graphemes: Vec<String>,
|
||||
}
|
||||
|
||||
impl Value {
|
||||
/// Creates a new [`Value`] from a string slice.
|
||||
pub fn new(string: &str) -> Self {
|
||||
let graphemes = UnicodeSegmentation::graphemes(string, true)
|
||||
.map(String::from)
|
||||
.collect();
|
||||
|
||||
Self { graphemes }
|
||||
}
|
||||
|
||||
/// Returns whether the [`Value`] is empty or not.
|
||||
///
|
||||
/// A [`Value`] is empty when it contains no graphemes.
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.len() == 0
|
||||
}
|
||||
|
||||
/// Returns the total amount of graphemes in the [`Value`].
|
||||
pub fn len(&self) -> usize {
|
||||
self.graphemes.len()
|
||||
}
|
||||
|
||||
/// Returns the position of the previous start of a word from the given
|
||||
/// grapheme `index`.
|
||||
pub fn previous_start_of_word(&self, index: usize) -> usize {
|
||||
let previous_string =
|
||||
&self.graphemes[..index.min(self.graphemes.len())].concat();
|
||||
|
||||
UnicodeSegmentation::split_word_bound_indices(previous_string as &str)
|
||||
.filter(|(_, word)| !word.trim_start().is_empty())
|
||||
.next_back()
|
||||
.map(|(i, previous_word)| {
|
||||
index
|
||||
- UnicodeSegmentation::graphemes(previous_word, true)
|
||||
.count()
|
||||
- UnicodeSegmentation::graphemes(
|
||||
&previous_string[i + previous_word.len()..] as &str,
|
||||
true,
|
||||
)
|
||||
.count()
|
||||
})
|
||||
.unwrap_or(0)
|
||||
}
|
||||
|
||||
/// Returns the position of the next end of a word from the given grapheme
|
||||
/// `index`.
|
||||
pub fn next_end_of_word(&self, index: usize) -> usize {
|
||||
let next_string = &self.graphemes[index..].concat();
|
||||
|
||||
UnicodeSegmentation::split_word_bound_indices(next_string as &str)
|
||||
.find(|(_, word)| !word.trim_start().is_empty())
|
||||
.map(|(i, next_word)| {
|
||||
index
|
||||
+ UnicodeSegmentation::graphemes(next_word, true).count()
|
||||
+ UnicodeSegmentation::graphemes(
|
||||
&next_string[..i] as &str,
|
||||
true,
|
||||
)
|
||||
.count()
|
||||
})
|
||||
.unwrap_or(self.len())
|
||||
}
|
||||
|
||||
/// Returns a new [`Value`] containing the graphemes from `start` until the
|
||||
/// given `end`.
|
||||
pub fn select(&self, start: usize, end: usize) -> Self {
|
||||
let graphemes =
|
||||
self.graphemes[start.min(self.len())..end.min(self.len())].to_vec();
|
||||
|
||||
Self { graphemes }
|
||||
}
|
||||
|
||||
/// Returns a new [`Value`] containing the graphemes until the given
|
||||
/// `index`.
|
||||
pub fn until(&self, index: usize) -> Self {
|
||||
let graphemes = self.graphemes[..index.min(self.len())].to_vec();
|
||||
|
||||
Self { graphemes }
|
||||
}
|
||||
|
||||
/// Inserts a new `char` at the given grapheme `index`.
|
||||
pub fn insert(&mut self, index: usize, c: char) {
|
||||
self.graphemes.insert(index, c.to_string());
|
||||
|
||||
self.graphemes =
|
||||
UnicodeSegmentation::graphemes(&self.to_string() as &str, true)
|
||||
.map(String::from)
|
||||
.collect();
|
||||
}
|
||||
|
||||
/// Inserts a bunch of graphemes at the given grapheme `index`.
|
||||
pub fn insert_many(&mut self, index: usize, mut value: Value) {
|
||||
let _ = self
|
||||
.graphemes
|
||||
.splice(index..index, value.graphemes.drain(..));
|
||||
}
|
||||
|
||||
/// Removes the grapheme at the given `index`.
|
||||
pub fn remove(&mut self, index: usize) {
|
||||
let _ = self.graphemes.remove(index);
|
||||
}
|
||||
|
||||
/// Removes the graphemes from `start` to `end`.
|
||||
pub fn remove_many(&mut self, start: usize, end: usize) {
|
||||
let _ = self.graphemes.splice(start..end, std::iter::empty());
|
||||
}
|
||||
|
||||
/// Returns a new [`Value`] with all its graphemes replaced with the
|
||||
/// dot ('•') character.
|
||||
pub fn secure(&self) -> Self {
|
||||
Self {
|
||||
graphemes: std::iter::repeat_n(
|
||||
String::from("•"),
|
||||
self.graphemes.len(),
|
||||
)
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Value {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.write_str(&self.graphemes.concat())
|
||||
}
|
||||
}
|
||||
@@ -19,13 +19,14 @@
|
||||
Modify it to your liking.
|
||||
*/
|
||||
|
||||
use iced::{Color, Theme, color};
|
||||
use iced::widget::container;
|
||||
use iced::{Border, Color, Theme, color, Background};
|
||||
|
||||
// Function returns theme to be used by installer
|
||||
pub fn main_theme() -> Theme {
|
||||
let mut pl = Theme::Dracula.palette();
|
||||
pl.primary = color!(0xFFD700);
|
||||
|
||||
return Theme::custom("Kira Theme", pl);
|
||||
}
|
||||
|
||||
@@ -38,19 +39,33 @@ pub fn change_lightnes(c: &Color, factor: f32) -> Color {
|
||||
res
|
||||
}
|
||||
|
||||
pub fn text_with_border(_theme: &Theme) -> container::Style {
|
||||
|
||||
pub fn dialog_background(_theme: &Theme) -> container::Style {
|
||||
let mut back = _theme.palette().background.clone();
|
||||
back.a = 0.8;
|
||||
container::Style {
|
||||
border: Border {
|
||||
color: Color::from_rgb8(120, 98, 10),
|
||||
width: 2.0,
|
||||
radius: 7.into(),
|
||||
},
|
||||
background: Some(Background::Color(change_lightnes(&_theme.palette().background, 0.3))),
|
||||
background: Some(iced::Background::Color(back)),
|
||||
..container::Style::default()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn warning_dialog(_theme: &Theme) -> container::Style {
|
||||
container::bordered_box(_theme).background(color!(0xDB5375))
|
||||
}
|
||||
|
||||
// pub fn text_with_border(_theme: &Theme) -> container::Style {
|
||||
|
||||
// container::Style {
|
||||
// border: Border {
|
||||
// color: Color::from_rgb8(120, 98, 10),
|
||||
// width: 2.0,
|
||||
// radius: 7.into(),
|
||||
// },
|
||||
// background: Some(Background::Color(change_lightnes(&_theme.palette().background, 0.3))),
|
||||
// ..container::Style::default()
|
||||
// }
|
||||
// }
|
||||
|
||||
pub fn get_spiner_bytes() -> Vec<u8>{
|
||||
return include_bytes!("media/spiner.apng").to_vec();
|
||||
}
|
||||
+209
@@ -0,0 +1,209 @@
|
||||
// We need this file because wayland broke Linux desktop.
|
||||
|
||||
use iced::keyboard::key::{Code, NativeCode, Physical};
|
||||
|
||||
const XKB_OFFSET: u32 = 8;
|
||||
|
||||
///
|
||||
/// Converts iced key::Physical to xkb numeric keycode
|
||||
///
|
||||
pub fn physical_to_xkb_keycode(physical: &Physical) -> Option<u32> {
|
||||
match physical {
|
||||
Physical::Unidentified(NativeCode::Xkb(code)) => Some(code.clone()),
|
||||
Physical::Unidentified(_) => None,
|
||||
Physical::Code(code) => code_to_xkb(code),
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
/// Converts iced key::Code to xkb numeric keycode
|
||||
///
|
||||
pub fn code_to_xkb(code: &Code) -> Option<u32> {
|
||||
let evdev: u32 = match code {
|
||||
// Alphanumeric & main typing block
|
||||
Code::Backquote => 41,
|
||||
Code::Backslash => 43,
|
||||
Code::BracketLeft => 26,
|
||||
Code::BracketRight => 27,
|
||||
Code::Comma => 51,
|
||||
Code::Digit0 => 11,
|
||||
Code::Digit1 => 2,
|
||||
Code::Digit2 => 3,
|
||||
Code::Digit3 => 4,
|
||||
Code::Digit4 => 5,
|
||||
Code::Digit5 => 6,
|
||||
Code::Digit6 => 7,
|
||||
Code::Digit7 => 8,
|
||||
Code::Digit8 => 9,
|
||||
Code::Digit9 => 10,
|
||||
Code::Equal => 13,
|
||||
Code::IntlBackslash => 86, // KEY_102ND
|
||||
Code::IntlRo => 89, // KEY_RO
|
||||
Code::IntlYen => 124, // KEY_YEN
|
||||
Code::KeyA => 30,
|
||||
Code::KeyB => 48,
|
||||
Code::KeyC => 46,
|
||||
Code::KeyD => 32,
|
||||
Code::KeyE => 18,
|
||||
Code::KeyF => 33,
|
||||
Code::KeyG => 34,
|
||||
Code::KeyH => 35,
|
||||
Code::KeyI => 23,
|
||||
Code::KeyJ => 36,
|
||||
Code::KeyK => 37,
|
||||
Code::KeyL => 38,
|
||||
Code::KeyM => 50,
|
||||
Code::KeyN => 49,
|
||||
Code::KeyO => 24,
|
||||
Code::KeyP => 25,
|
||||
Code::KeyQ => 16,
|
||||
Code::KeyR => 19,
|
||||
Code::KeyS => 31,
|
||||
Code::KeyT => 20,
|
||||
Code::KeyU => 22,
|
||||
Code::KeyV => 47,
|
||||
Code::KeyW => 17,
|
||||
Code::KeyX => 45,
|
||||
Code::KeyY => 21,
|
||||
Code::KeyZ => 44,
|
||||
Code::Minus => 12,
|
||||
Code::Period => 52,
|
||||
Code::Quote => 40,
|
||||
Code::Semicolon => 39,
|
||||
Code::Slash => 53,
|
||||
|
||||
// Modifiers, whitespace & editing
|
||||
Code::AltLeft => 56,
|
||||
Code::AltRight => 100,
|
||||
Code::Backspace => 14,
|
||||
Code::CapsLock => 58,
|
||||
Code::ContextMenu => 139, // KEY_MENU
|
||||
Code::ControlLeft => 29,
|
||||
Code::ControlRight => 97,
|
||||
Code::Enter => 28,
|
||||
Code::SuperLeft => 125, // KEY_LEFTMETA
|
||||
Code::SuperRight => 126, // KEY_RIGHTMETA
|
||||
Code::ShiftLeft => 42,
|
||||
Code::ShiftRight => 54,
|
||||
Code::Space => 57,
|
||||
Code::Tab => 15,
|
||||
|
||||
// CJK / IME keys
|
||||
Code::Convert => 92, // KEY_HENKAN
|
||||
Code::KanaMode => 93, // KEY_KATAKANAHIRAGANA
|
||||
Code::Lang1 => 122, // KEY_HANGEUL / KEY_HANGUEL
|
||||
Code::Lang2 => 123, // KEY_HANJA
|
||||
Code::Lang3 => 90, // KEY_KATAKANA
|
||||
Code::Lang4 => 91, // KEY_HIRAGANA
|
||||
Code::Lang5 => 93, // KEY_KATAKANAHIRAGANA
|
||||
Code::NonConvert => 94, // KEY_MUHENKAN
|
||||
Code::Hiragana => 91, // KEY_HIRAGANA
|
||||
Code::Katakana => 90, // KEY_KATAKANA
|
||||
|
||||
// Navigation & cluster
|
||||
Code::Delete => 111,
|
||||
Code::End => 107,
|
||||
Code::Help => 138, // KEY_HELP
|
||||
Code::Home => 102,
|
||||
Code::Insert => 110,
|
||||
Code::PageDown => 109,
|
||||
Code::PageUp => 104,
|
||||
Code::ArrowDown => 108,
|
||||
Code::ArrowLeft => 105,
|
||||
Code::ArrowRight => 106,
|
||||
Code::ArrowUp => 103,
|
||||
|
||||
// Numpad
|
||||
Code::NumLock => 69,
|
||||
Code::Numpad0 => 82,
|
||||
Code::Numpad1 => 79,
|
||||
Code::Numpad2 => 80,
|
||||
Code::Numpad3 => 81,
|
||||
Code::Numpad4 => 75,
|
||||
Code::Numpad5 => 76,
|
||||
Code::Numpad6 => 77,
|
||||
Code::Numpad7 => 71,
|
||||
Code::Numpad8 => 72,
|
||||
Code::Numpad9 => 73,
|
||||
Code::NumpadAdd => 78,
|
||||
Code::NumpadComma => 121, // KEY_KPCOMMA
|
||||
Code::NumpadDecimal => 83,
|
||||
Code::NumpadDivide => 98,
|
||||
Code::NumpadEnter => 96,
|
||||
Code::NumpadEqual => 117, // KEY_KPEQUAL
|
||||
Code::NumpadMultiply => 55,
|
||||
Code::NumpadParenLeft => 179, // KEY_KPLEFTPAREN
|
||||
Code::NumpadParenRight => 180, // KEY_KPRIGHTPAREN
|
||||
Code::NumpadSubtract => 74,
|
||||
|
||||
// System, lock & media keys
|
||||
Code::Escape => 1,
|
||||
Code::PrintScreen => 99,
|
||||
Code::ScrollLock => 70,
|
||||
Code::Pause => 119,
|
||||
Code::BrowserBack => 158, // KEY_BACK
|
||||
Code::BrowserFavorites => 156, // KEY_BOOKMARKS
|
||||
Code::BrowserForward => 159, // KEY_FORWARD
|
||||
Code::BrowserHome => 172, // KEY_HOMEPAGE
|
||||
Code::BrowserRefresh => 173, // KEY_REFRESH
|
||||
Code::BrowserSearch => 217, // KEY_SEARCH
|
||||
Code::BrowserStop => 128, // KEY_STOP
|
||||
Code::Eject => 161, // KEY_EJECTCD
|
||||
Code::LaunchApp1 => 157, // KEY_COMPUTER
|
||||
Code::LaunchApp2 => 140, // KEY_CALC
|
||||
Code::LaunchMail => 155, // KEY_MAIL
|
||||
Code::MediaPlayPause => 164, // KEY_PLAYPAUSE
|
||||
Code::MediaSelect => 179, // varies by device; None is safer if ambiguous
|
||||
Code::MediaStop => 166, // KEY_STOPCD
|
||||
Code::MediaTrackNext => 163, // KEY_NEXTSONG
|
||||
Code::MediaTrackPrevious => 165, // KEY_PREVIOUSSONG
|
||||
Code::Power => 116, // KEY_POWER
|
||||
Code::Sleep => 142, // KEY_SLEEP
|
||||
Code::AudioVolumeDown => 114, // KEY_VOLUMEDOWN
|
||||
Code::AudioVolumeMute => 113, // KEY_MUTE
|
||||
Code::AudioVolumeUp => 115, // KEY_VOLUMEUP
|
||||
Code::WakeUp => 143, // KEY_WAKEUP
|
||||
|
||||
Code::Suspend => 205, // KEY_SUSPEND
|
||||
Code::Again => 129, // KEY_AGAIN
|
||||
Code::Copy => 133, // KEY_COPY
|
||||
Code::Cut => 137, // KEY_CUT
|
||||
Code::Find => 136, // KEY_FIND
|
||||
Code::Open => 134, // KEY_OPEN
|
||||
Code::Paste => 135, // KEY_PASTE
|
||||
Code::Props => 130, // KEY_PROPS
|
||||
Code::Select => 353, // KEY_SELECT (0x161)
|
||||
Code::Undo => 131, // KEY_UNDO
|
||||
|
||||
// Function keys F1–F35
|
||||
Code::F1 => 59,
|
||||
Code::F2 => 60,
|
||||
Code::F3 => 61,
|
||||
Code::F4 => 62,
|
||||
Code::F5 => 63,
|
||||
Code::F6 => 64,
|
||||
Code::F7 => 65,
|
||||
Code::F8 => 66,
|
||||
Code::F9 => 67,
|
||||
Code::F10 => 68,
|
||||
Code::F11 => 87,
|
||||
Code::F12 => 88,
|
||||
Code::F13 => 183, // KEY_F13
|
||||
Code::F14 => 184, // KEY_F14
|
||||
Code::F15 => 185, // KEY_F15
|
||||
Code::F16 => 186, // KEY_F16
|
||||
Code::F17 => 187,
|
||||
Code::F18 => 188,
|
||||
Code::F19 => 189,
|
||||
Code::F20 => 190,
|
||||
Code::F21 => 191,
|
||||
Code::F22 => 192,
|
||||
Code::F23 => 193,
|
||||
Code::F24 => 194, // KEY_F24
|
||||
|
||||
// Catch-all in case your `iced_core::keyboard::key::Code` has additional variants
|
||||
_ => return None,
|
||||
};
|
||||
|
||||
Some(evdev + XKB_OFFSET)
|
||||
}
|
||||
+34
-3
@@ -4,11 +4,14 @@
|
||||
"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/>.",
|
||||
"license.accept_text": "By pressing 'Accept' button you agreening to terms described above:",
|
||||
"license.accept_text": "By pressing 'Accept' button you agreening to terms described below:",
|
||||
"license.button.accept": "Accept",
|
||||
"license.button.decline": "Decline",
|
||||
"network.reuse_checkbox_caption": "Reuse settings?",
|
||||
@@ -20,6 +23,34 @@
|
||||
"network.button.check": "Check Network",
|
||||
"timezone.selected_timezone": "Selected timezone:",
|
||||
"timezone.select_timezone": "Please select preffered time zone",
|
||||
"timezone.init_error": "Erro getting time zones data from system."
|
||||
|
||||
"timezone.init_error": "Error getting time zones data from system!",
|
||||
"locale.select_language_locale": "The system language will be set to",
|
||||
"locale.select_formats_locale": "The numbers and dates locale will be set to",
|
||||
"keyboard.select_model": "Select keyboard model",
|
||||
"keyboard.select_layout": "Select keyboard layout",
|
||||
"keyboard.select_variant": "Select keyboard variant",
|
||||
"keyboard.init_error": "Error getting keyboard layouts information from the system!",
|
||||
"partition.no_swap": "No swap partition",
|
||||
"partition.swap_no_hibernate": "Swap without hibernate",
|
||||
"partition.swap_hibernate": "Swap with hibernation",
|
||||
"partition.swap_custom": "Custom swap size",
|
||||
"partition.select_device_placeholder": "Select Device",
|
||||
"partition.select_device": "Select device for system installation",
|
||||
"partition.select_swapmode_placeholder": "Select Swap Mode",
|
||||
"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",
|
||||
"security.user_full_name": "User full name/description",
|
||||
"security.user_password": "User password",
|
||||
"security.reuse_user_password": "Reuse user password for root user",
|
||||
"security.root_password": "Root password",
|
||||
"security.pass_low": "low security",
|
||||
"security.pass_middle": "normal 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!\n\nDo you want to proceed?"
|
||||
}
|
||||
+223
-83
@@ -21,6 +21,7 @@
|
||||
*/
|
||||
|
||||
use iced::widget;
|
||||
use log;
|
||||
use std::process::ExitCode;
|
||||
|
||||
use iced::{Element, Task};
|
||||
@@ -32,9 +33,21 @@ use crate::stages::welcome;
|
||||
use crate::stages::welcome::WelcomeStage;
|
||||
|
||||
rust_i18n::i18n!("src/locales", fallback = "en");
|
||||
mod kira_color_bar;
|
||||
mod kira_disk_layout;
|
||||
mod kira_include;
|
||||
mod kira_locales;
|
||||
mod kira_logger;
|
||||
mod kira_scroll_list;
|
||||
mod kira_size;
|
||||
mod kira_sysinfo;
|
||||
mod kira_system;
|
||||
mod kira_text_input;
|
||||
mod kira_theming;
|
||||
mod kira_xkb;
|
||||
mod stage;
|
||||
mod stages;
|
||||
mod theme;
|
||||
mod tz_to_cc;
|
||||
|
||||
enum Views {
|
||||
Start,
|
||||
@@ -42,6 +55,11 @@ enum Views {
|
||||
License(license::LicenseStage),
|
||||
Network(stages::network::NetworkStage),
|
||||
TimeZone(stages::timezone::TimeZoneStage),
|
||||
Locale(stages::locale::LocaleStage),
|
||||
Keyboard(stages::keyboard::KeyboardStage),
|
||||
Partition(stages::partition::PartitionStage),
|
||||
Security(stages::security::SecurityStage),
|
||||
Install(stages::install::InstallStage),
|
||||
}
|
||||
|
||||
enum Message {
|
||||
@@ -50,56 +68,47 @@ enum Message {
|
||||
License(license::Message),
|
||||
Network(stages::network::Message),
|
||||
TimeZone(stages::timezone::Message),
|
||||
Locale(stages::locale::Message),
|
||||
Keyboard(stages::keyboard::Message),
|
||||
Partition(stages::partition::Message),
|
||||
Security(stages::security::Message),
|
||||
Install(stages::install::Message),
|
||||
}
|
||||
|
||||
struct KiraState {
|
||||
current_view: Views,
|
||||
toml_config: toml::Table,
|
||||
config: KiraConfig,
|
||||
k_config: KiraConfig,
|
||||
stages_save: Vec<Views>,
|
||||
}
|
||||
|
||||
const CONFIG_PATH_STR: &str = "kira_config.toml";
|
||||
// const CONFIG_PATH_STR: &str = "kira_config.toml";
|
||||
|
||||
fn load_kira_config(config_path: &str) -> Result<toml::Table, Box<dyn std::error::Error>> {
|
||||
use std::fs;
|
||||
use toml::Table;
|
||||
// 1. Read the file content into a String
|
||||
let content = fs::read_to_string(config_path)?;
|
||||
// fn load_kira_config(config_path: &str) -> Result<toml::Table, Box<dyn std::error::Error>> {
|
||||
// use std::fs;
|
||||
// use toml::Table;
|
||||
// // 1. Read the file content into a String
|
||||
// let content = fs::read_to_string(config_path)?;
|
||||
|
||||
// 2. Parse the string into a Table
|
||||
let table: Table = content.parse()?;
|
||||
// // 2. Parse the string into a Table
|
||||
// let table: Table = content.parse()?;
|
||||
|
||||
println!("{:?}", table);
|
||||
Ok(table)
|
||||
}
|
||||
// log::info!("{:?}", table);
|
||||
// Ok(table)
|
||||
// }
|
||||
|
||||
impl KiraState {
|
||||
fn boot() -> (Self, Task<Message>) {
|
||||
(
|
||||
Self {
|
||||
current_view: Views::Start,
|
||||
toml_config: toml::Table::new(),
|
||||
config: KiraConfig {
|
||||
config_trail: Vec::new(),
|
||||
},
|
||||
k_config: KiraConfig::default(),
|
||||
stages_save: Vec::new(),
|
||||
},
|
||||
Task::done(Message::Start),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// impl KiraState {
|
||||
// fn new(toml_config: toml::Table) -> Self {
|
||||
|
||||
// Self {
|
||||
// current_view: Views::Start,
|
||||
// toml_config: toml_config,
|
||||
// config: KiraConfig { config_trail: Vec::new() }
|
||||
// }
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
fn view(k_state: &KiraState) -> Element<'_, Message> {
|
||||
match &k_state.current_view {
|
||||
Views::Start => Element::new(widget::space()),
|
||||
@@ -107,46 +116,59 @@ fn view(k_state: &KiraState) -> Element<'_, Message> {
|
||||
Views::License(license_stage) => license_stage.view().map(Message::License),
|
||||
Views::Network(network_stage) => network_stage.view().map(Message::Network),
|
||||
Views::TimeZone(timezone_stage) => timezone_stage.view().map(Message::TimeZone),
|
||||
Views::Locale(locale_stage) => locale_stage.view().map(Message::Locale),
|
||||
Views::Keyboard(keyboard_stage) => keyboard_stage.view().map(Message::Keyboard),
|
||||
Views::Partition(partition_stage) => partition_stage.view().map(Message::Partition),
|
||||
Views::Security(security_stage) => security_stage.view().map(Message::Security),
|
||||
Views::Install(install_stage) => install_stage.view().map(Message::Install),
|
||||
}
|
||||
}
|
||||
|
||||
fn update(k_state: &mut KiraState, message: Message) -> Task<Message> {
|
||||
match message {
|
||||
Message::Start => match load_kira_config(CONFIG_PATH_STR) {
|
||||
Ok(conf) => {
|
||||
println!("Config loaded!");
|
||||
k_state.toml_config = conf;
|
||||
k_state.current_view = Views::Welcome(WelcomeStage::new());
|
||||
Task::none()
|
||||
}
|
||||
Err(ex) => {
|
||||
println!("Error reading config {}: {}", CONFIG_PATH_STR, ex);
|
||||
iced::exit()
|
||||
}
|
||||
},
|
||||
Message::Start => {
|
||||
log::info!("Starting!");
|
||||
k_state.current_view = Views::Welcome(WelcomeStage::new(k_state.k_config.clone()));
|
||||
Task::none()
|
||||
}
|
||||
Message::Welcome(wlc_msg) => {
|
||||
if let Views::Welcome(wlc_view) = &mut k_state.current_view {
|
||||
let action = wlc_view.update(wlc_msg);
|
||||
if let StageAction::Next(welcome_res) = action {
|
||||
k_state.config.config_trail.push(welcome_res);
|
||||
k_state.current_view = Views::License(license::LicenseStage {});
|
||||
match wlc_view.update(wlc_msg) {
|
||||
StageAction::Next(welcome_res) => {
|
||||
k_state.k_config = welcome_res;
|
||||
let s_state = std::mem::replace(
|
||||
&mut k_state.current_view,
|
||||
Views::License(license::LicenseStage::new(k_state.k_config.clone())),
|
||||
);
|
||||
k_state.stages_save.push(s_state);
|
||||
Task::none()
|
||||
}
|
||||
StageAction::Abort => iced::exit(),
|
||||
_ => Task::none(),
|
||||
}
|
||||
} else {
|
||||
Task::none()
|
||||
}
|
||||
Task::none()
|
||||
}
|
||||
Message::License(license_message) => {
|
||||
if let Views::License(license_view) = &mut k_state.current_view {
|
||||
let action = license_view.update(license_message);
|
||||
match action {
|
||||
StageAction::Next(license_res) => {
|
||||
k_state.config.config_trail.push(license_res);
|
||||
k_state.current_view =
|
||||
Views::Network(network::NetworkStage::new(&k_state.toml_config));
|
||||
k_state.k_config = license_res;
|
||||
let s_state = std::mem::replace(
|
||||
&mut k_state.current_view,
|
||||
Views::Network(network::NetworkStage::new(k_state.k_config.clone())),
|
||||
);
|
||||
k_state.stages_save.push(s_state);
|
||||
Task::done(Message::Network(network::Message::CheckNetwork))
|
||||
}
|
||||
StageAction::Abort(_) => iced::exit(),
|
||||
StageAction::Back => iced::exit(),
|
||||
StageAction::None => Task::none(),
|
||||
StageAction::Abort => iced::exit(),
|
||||
StageAction::Back => {
|
||||
k_state.current_view = k_state.stages_save.pop().unwrap();
|
||||
Task::none()
|
||||
}
|
||||
_ => Task::none(),
|
||||
}
|
||||
} else {
|
||||
Task::none()
|
||||
@@ -159,13 +181,18 @@ fn update(k_state: &mut KiraState, message: Message) -> Task<Message> {
|
||||
network::UpdateResult::Task(t) => t.map(Message::Network),
|
||||
network::UpdateResult::StageAction(action) => match action {
|
||||
StageAction::Next(network_res) => {
|
||||
k_state.config.config_trail.push(network_res);
|
||||
k_state.current_view =
|
||||
Views::TimeZone(stages::timezone::TimeZoneStage::new());
|
||||
k_state.k_config = network_res;
|
||||
let s_state = std::mem::replace(
|
||||
&mut k_state.current_view,
|
||||
Views::TimeZone(stages::timezone::TimeZoneStage::new(
|
||||
k_state.k_config.clone(),
|
||||
)),
|
||||
);
|
||||
k_state.stages_save.push(s_state);
|
||||
Task::none()
|
||||
}
|
||||
StageAction::Back => {
|
||||
k_state.current_view = Views::License(license::LicenseStage {});
|
||||
k_state.current_view = k_state.stages_save.pop().unwrap();
|
||||
Task::none()
|
||||
}
|
||||
_ => Task::none(),
|
||||
@@ -180,17 +207,140 @@ fn update(k_state: &mut KiraState, message: Message) -> Task<Message> {
|
||||
let action = timezone_view.update(timezone_message);
|
||||
match action {
|
||||
StageAction::Next(tz_res) => {
|
||||
k_state.config.config_trail.push(tz_res);
|
||||
iced::exit()
|
||||
k_state.k_config = tz_res;
|
||||
let s_state = std::mem::replace(
|
||||
&mut k_state.current_view,
|
||||
Views::Locale(stages::locale::LocaleStage::new(
|
||||
k_state.k_config.clone(),
|
||||
)),
|
||||
);
|
||||
k_state.stages_save.push(s_state);
|
||||
Task::none()
|
||||
}
|
||||
StageAction::Abort(_) => iced::exit(),
|
||||
StageAction::Abort => iced::exit(),
|
||||
StageAction::Back => {
|
||||
k_state.config.config_trail.pop();
|
||||
k_state.current_view =
|
||||
Views::Network(network::NetworkStage::new(&k_state.toml_config));
|
||||
Task::done(Message::Network(network::Message::CheckNetwork))
|
||||
k_state.current_view = k_state.stages_save.pop().unwrap();
|
||||
Task::none()
|
||||
}
|
||||
StageAction::None => Task::none(),
|
||||
_ => Task::none(),
|
||||
}
|
||||
} else {
|
||||
Task::none()
|
||||
}
|
||||
}
|
||||
Message::Locale(locale_msg) => {
|
||||
if let Views::Locale(locale_view) = &mut k_state.current_view {
|
||||
match locale_view.update(locale_msg) {
|
||||
StageAction::Next(locale_res) => {
|
||||
k_state.k_config = locale_res;
|
||||
let s_state = std::mem::replace(
|
||||
&mut k_state.current_view,
|
||||
Views::Keyboard(stages::keyboard::KeyboardStage::new(
|
||||
k_state.k_config.clone(),
|
||||
)),
|
||||
);
|
||||
k_state.stages_save.push(s_state);
|
||||
Task::none()
|
||||
}
|
||||
StageAction::Back => {
|
||||
k_state.current_view = k_state.stages_save.pop().unwrap();
|
||||
Task::none()
|
||||
}
|
||||
_ => Task::none(),
|
||||
}
|
||||
} else {
|
||||
Task::none()
|
||||
}
|
||||
}
|
||||
Message::Keyboard(keyboard_msg) => {
|
||||
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) => {
|
||||
let s_state = std::mem::replace(
|
||||
&mut k_state.current_view,
|
||||
Views::Partition(part_stage),
|
||||
);
|
||||
k_state.stages_save.push(s_state);
|
||||
}
|
||||
Err(ex) => {
|
||||
log::error!("Error, cannot init partition stage: {}", ex);
|
||||
}
|
||||
}
|
||||
Task::none()
|
||||
}
|
||||
StageAction::Back => {
|
||||
k_state.current_view = k_state.stages_save.pop().unwrap();
|
||||
Task::none()
|
||||
}
|
||||
_ => Task::none(),
|
||||
}
|
||||
} else {
|
||||
Task::none()
|
||||
}
|
||||
}
|
||||
Message::Partition(partition_msg) => {
|
||||
if let Views::Partition(partition_view) = &mut k_state.current_view {
|
||||
match partition_view.update(partition_msg) {
|
||||
StageAction::Next(partition_res) => {
|
||||
k_state.k_config = partition_res;
|
||||
let s_state = std::mem::replace(
|
||||
&mut k_state.current_view,
|
||||
Views::Security(stages::security::SecurityStage::new(
|
||||
k_state.k_config.clone(),
|
||||
)),
|
||||
);
|
||||
k_state.stages_save.push(s_state);
|
||||
Task::none()
|
||||
}
|
||||
StageAction::Back => {
|
||||
k_state.current_view = k_state.stages_save.pop().unwrap();
|
||||
Task::none()
|
||||
}
|
||||
_ => Task::none(),
|
||||
}
|
||||
} else {
|
||||
Task::none()
|
||||
}
|
||||
}
|
||||
Message::Security(security_msg) => {
|
||||
if let Views::Security(security_view) = &mut k_state.current_view {
|
||||
match security_view.update(security_msg) {
|
||||
StageAction::Next(security_res) => {
|
||||
k_state.k_config = security_res;
|
||||
let s_state = std::mem::replace(
|
||||
&mut k_state.current_view,
|
||||
Views::Install(stages::install::InstallStage::new(
|
||||
k_state.k_config.clone(),
|
||||
)),
|
||||
);
|
||||
k_state.stages_save.push(s_state);
|
||||
Task::none()
|
||||
}
|
||||
StageAction::Back => {
|
||||
k_state.current_view = k_state.stages_save.pop().unwrap();
|
||||
Task::none()
|
||||
}
|
||||
_ => Task::none(),
|
||||
}
|
||||
} else {
|
||||
Task::none()
|
||||
}
|
||||
}
|
||||
Message::Install(install_msg) => {
|
||||
if let Views::Install(install_view) = &mut k_state.current_view {
|
||||
let update_result = install_view.update(install_msg);
|
||||
match update_result {
|
||||
stages::install::Update::Task(t) => t.map(Message::Install),
|
||||
stages::install::Update::StgAct(stage_action) => match stage_action {
|
||||
StageAction::Back => {
|
||||
k_state.current_view = k_state.stages_save.pop().unwrap();
|
||||
Task::none()
|
||||
}
|
||||
_ => Task::none(),
|
||||
},
|
||||
}
|
||||
} else {
|
||||
Task::none()
|
||||
@@ -199,15 +349,9 @@ fn update(k_state: &mut KiraState, message: Message) -> Task<Message> {
|
||||
}
|
||||
}
|
||||
|
||||
// pub fn main_interface() -> iced::Result {
|
||||
// iced::run(WellcomeStage::update, WellcomeStage::view)
|
||||
// }
|
||||
pub fn main() -> ExitCode {
|
||||
// let app_init = || {
|
||||
// let mut k_state = KiraState::default()
|
||||
// k_state.current_view = Views::Welcome(WelcomeStage::new());
|
||||
// k_stateapp_init
|
||||
// };
|
||||
// Init logger
|
||||
kira_logger::init().unwrap();
|
||||
|
||||
let iced_result = iced::application(KiraState::boot, update, view)
|
||||
.window(iced::window::Settings {
|
||||
@@ -218,19 +362,15 @@ pub fn main() -> ExitCode {
|
||||
..Default::default()
|
||||
})
|
||||
.centered()
|
||||
.theme(theme::main_theme())
|
||||
.theme(kira_theming::main_theme())
|
||||
.default_font(iced::Font::MONOSPACE)
|
||||
.run();
|
||||
|
||||
match iced_result {
|
||||
Ok(()) => ExitCode::SUCCESS,
|
||||
Err(_) => ExitCode::from(42), // Custom error code
|
||||
Err(ex) => {
|
||||
log::error!("ICED Error: {}", ex);
|
||||
ExitCode::from(42)
|
||||
} // Custom error code
|
||||
}
|
||||
}
|
||||
|
||||
// fn main() {
|
||||
// println!("Hello, world!");
|
||||
// println!("{}", t!("wellcome.text"));
|
||||
// // Initialize the state
|
||||
// let _res = main_interface();
|
||||
|
||||
// }
|
||||
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 |
+43
-40
@@ -1,56 +1,59 @@
|
||||
// <Kira Installer - universal Linux installer.>
|
||||
// Copyright (C) <2026> <Kira Foundation>
|
||||
// <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 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/>.
|
||||
// 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/>.
|
||||
|
||||
/*
|
||||
This file contains basic enums and structs to be used with stages.
|
||||
*/
|
||||
This file contains basic enums and structs to be used with stages.
|
||||
*/
|
||||
|
||||
use std::collections::HashMap;
|
||||
use crate::stages;
|
||||
use iced::Task;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum ConfigValue {
|
||||
String(String),
|
||||
I64(i64),
|
||||
U64(u64),
|
||||
F64(f64),
|
||||
Bool(bool),
|
||||
Vector(Vec<ConfigValue>),
|
||||
Dictionary(HashMap<String, ConfigValue>)
|
||||
pub struct KiraConfig {
|
||||
pub res_welcome: Option<stages::welcome::WelcomeStageResult>,
|
||||
pub res_license: bool,
|
||||
pub res_network: Option<stages::network::NetworkStageResult>,
|
||||
pub res_timezone: Option<stages::timezone::TimeZoneStageResult>,
|
||||
pub res_locale: Option<stages::locale::LocaleStageResult>,
|
||||
pub res_keyboard: Option<stages::keyboard::KeyboardStageResult>,
|
||||
pub res_partition: Option<stages::partition::PartitionStageResult>,
|
||||
pub res_security: Option<stages::security::SecurityStageResult>,
|
||||
pub res_install: Option<stages::install::InstallStageResult>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct StageResult {
|
||||
pub name: String,
|
||||
pub config: Option<HashMap<String, ConfigValue>>,
|
||||
pub resuts: Option<HashMap<String, ConfigValue>>,
|
||||
pub error: Option<String>
|
||||
impl Default for KiraConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
res_welcome: None,
|
||||
res_license: false,
|
||||
res_network: None,
|
||||
res_timezone: None,
|
||||
res_locale: None,
|
||||
res_keyboard: None,
|
||||
res_partition: None,
|
||||
res_security: None,
|
||||
res_install: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug)]
|
||||
pub enum StageAction {
|
||||
Back,
|
||||
None,
|
||||
Next(StageResult),
|
||||
Abort(StageResult),
|
||||
Next(KiraConfig),
|
||||
Abort,
|
||||
}
|
||||
|
||||
|
||||
pub struct KiraConfig {
|
||||
pub config_trail: Vec<StageResult>,
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,739 @@
|
||||
// <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.
|
||||
*/
|
||||
|
||||
use std::{fs, path::Path};
|
||||
|
||||
use crate::{
|
||||
kira_disk_layout::{self, BlkDev, FSType, PartInfo, PartLayout, PartRole},
|
||||
kira_size::KiraSize,
|
||||
kira_system::{self, ExecCommandError},
|
||||
kira_theming,
|
||||
stage::{KiraConfig, StageAction},
|
||||
stages::partition::PartitionStageResult,
|
||||
};
|
||||
use iced::{
|
||||
Alignment, Task,
|
||||
futures::{self, SinkExt, StreamExt, TryStreamExt, channel::mpsc::SendError},
|
||||
widget,
|
||||
};
|
||||
use iced::{Color, Length, futures::channel::mpsc::Sender, widget::container};
|
||||
|
||||
use log;
|
||||
use rust_i18n::t;
|
||||
|
||||
const EFI_BOOT_MOUNT_POINT: &str = "/mnt/inst_root/beefi";
|
||||
const MNT_DIR: &str = "/mnt/inst_root";
|
||||
const ROOT_PARTLABEL_DEV: &str = "/dev/disk/by-partlabel/bee-root";
|
||||
const EFI_PARTLABLE_DEV: &str = "/dev/disk/by-partlabel/bee-efi";
|
||||
const SWAP_PARTLABLE_DEV: &str = "/dev/disk/by-partlabel/bee-swap";
|
||||
const CONSOLE_FONT: &str = "ter-v24n";
|
||||
|
||||
///
|
||||
/// List of packages for desktop (elogind-dinit no need for headles system)
|
||||
///
|
||||
const PKG_LIST_CORE_DESKTOP: [&str; 19] = [
|
||||
"linux-kira-lts",
|
||||
"linux-firmware",
|
||||
"less",
|
||||
"sudo",
|
||||
"nano",
|
||||
"diffutils",
|
||||
"bcachefs-tools",
|
||||
"xfsprogs",
|
||||
"exfatprogs",
|
||||
"f2fs-tools",
|
||||
"dosfstools",
|
||||
"efibootmgr",
|
||||
"nvme-cli",
|
||||
"hive-up",
|
||||
"kira-blk-settings",
|
||||
"kira-linux-keyring",
|
||||
"kira-mirrorlist",
|
||||
"ly",
|
||||
"ly-dinit",
|
||||
];
|
||||
|
||||
// const PKG_LIST_MORE_DESKTOP: [&str; 11] = [
|
||||
// "wireless-regdb",
|
||||
// "wpa_supplicant",
|
||||
// "wpa_supplicant-dinit",
|
||||
// "networkmanager",
|
||||
// "networkmanager-dinit",
|
||||
// "chrony", //internet time
|
||||
// "chrony-dinit", //internet time
|
||||
// "smartmontools",
|
||||
// "cryptsetup",
|
||||
// "btop",
|
||||
// "fish",
|
||||
// ];
|
||||
|
||||
// const PKG_LIST_SOUND_DESKTOP: [&str; 8] = [
|
||||
// "pipewire",
|
||||
// "pipewire-dinit",
|
||||
// "pipewire-alsa",
|
||||
// "pipewire-audio",
|
||||
// "pipewire-jack",
|
||||
// "pipewire-pulse",
|
||||
// "wireplumber",
|
||||
// "wireplumber-dinit",
|
||||
// ];
|
||||
|
||||
// const PKG_LIST_MEDIA_DESKTOP: [&str; 4] = ["ffmpeg", "ffmpeg4.4", "strawberry", "mpv"];
|
||||
|
||||
const PKG_LIST_KDE_DESKTOP: [&str; 45] = [
|
||||
"wireless-regdb",
|
||||
"wpa_supplicant",
|
||||
"wpa_supplicant-dinit",
|
||||
"networkmanager", //networkmanager
|
||||
"networkmanager-dinit",
|
||||
"chrony", //internet time
|
||||
"chrony-dinit", //internet time
|
||||
"smartmontools",
|
||||
"cryptsetup",
|
||||
"btop",
|
||||
"fish",
|
||||
"pipewire", //sound
|
||||
"pipewire-dinit",
|
||||
"pipewire-alsa",
|
||||
"pipewire-audio",
|
||||
"pipewire-jack",
|
||||
"pipewire-pulse",
|
||||
"wireplumber",
|
||||
"wireplumber-dinit",
|
||||
"mesa",
|
||||
"libva",
|
||||
"libva-utils",
|
||||
"power-profiles-daemon",
|
||||
"power-profiles-daemon-dinit",
|
||||
"plasma-desktop",
|
||||
"plasma-workspace",
|
||||
"xdg-desktop-portal-kde",
|
||||
"kwallet-pam",
|
||||
"kwayland-integration",
|
||||
"libappindicator",
|
||||
"okular",
|
||||
"partitionmanager",
|
||||
"plasma-browser-integration",
|
||||
"plasma-desktop",
|
||||
"plasma-disks",
|
||||
"plasma-keyboard",
|
||||
"plasma-nm",
|
||||
"plasma-pa",
|
||||
"plasma-systemmonitor",
|
||||
"plasma-workspace",
|
||||
"ffmpeg",
|
||||
"ffmpeg4.4",
|
||||
"strawberry",
|
||||
"mpv",
|
||||
"ttf-unifont",
|
||||
];
|
||||
|
||||
// const PKG_LIST_AWESOME_DESKTOP: [&str; 5] = [
|
||||
// "mesa",
|
||||
// "libva",
|
||||
// "libva-utils",
|
||||
// "awesome",
|
||||
// "wiremix", // pipewire sound control
|
||||
// ];
|
||||
|
||||
/// Creates new GPT table and partitions from PartLayout
|
||||
fn create_partitions(part_layout: &PartLayout) -> Result<(), ExecCommandError> {
|
||||
log::info!("Creating GPT part table...");
|
||||
kira_system::parted_init_gpt_part_table(&part_layout.dev)?;
|
||||
log::info!("Start to create partitions...");
|
||||
for part in &part_layout.part_list {
|
||||
log::info!("Creating partition: {}", part);
|
||||
kira_system::parted_mkpart(&part_layout.dev, part)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// inits bcachefs volume for installation to use
|
||||
/// Formats device to bcachefs
|
||||
/// Unlock it if encryption used
|
||||
/// Mount to specified dir
|
||||
/// creates subvolumes bzz/root bzz/home
|
||||
fn bcachefs_init(
|
||||
dev_name: &str,
|
||||
mnt_dir: &str,
|
||||
password: Option<String>,
|
||||
) -> Result<(), ExecCommandError> {
|
||||
// if encryption used - unlock drive
|
||||
if let Some(pass) = password {
|
||||
kira_system::bcachefs_unlock(dev_name, pass.as_str())?;
|
||||
}
|
||||
|
||||
//mount drive
|
||||
kira_system::bcachefs_mount(dev_name, mnt_dir)?;
|
||||
|
||||
// Creating bzz-snaps directory for root snapshoots
|
||||
std::fs::create_dir(format!("{}{}", mnt_dir, "/bzz-snaps"))?;
|
||||
|
||||
// Creating boot directory for efi mounting
|
||||
std::fs::create_dir_all(EFI_BOOT_MOUNT_POINT)?;
|
||||
|
||||
// create subvolumes
|
||||
log::info!("Creating subvolumes...");
|
||||
for vol_name in ["/home", "/usr", "/var", "/var/tmp"] {
|
||||
let vol_path = format!("{}{}", mnt_dir, vol_name);
|
||||
kira_system::bcachefs_create_subvolume(vol_path.as_str())?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
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)?;
|
||||
|
||||
// format partitions
|
||||
for part in &part_layout.part_list {
|
||||
match part.role {
|
||||
Some(PartRole::EFI) => {
|
||||
if let Some(part_l) = part.partlabel_dev() {
|
||||
log::info!("Formating EFI partition.");
|
||||
kira_system::mkfs_esp(&part_l)?;
|
||||
}
|
||||
}
|
||||
Some(PartRole::ROOT) => {
|
||||
if let Some(part_l) = part.partlabel_dev() {
|
||||
if let FSType::BCACHEFS(bc_par) = &part.fs_type {
|
||||
log::info!("Formating root partition.");
|
||||
kira_system::bcachefs_format(
|
||||
&part_l,
|
||||
bc_par.comp_alg.clone(),
|
||||
bc_par.password.clone(),
|
||||
)?;
|
||||
} else {
|
||||
return Err(ExecCommandError::Other(
|
||||
"ROOT partition is not BCACHEFS type!".into(),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
Some(PartRole::SWAP) => {
|
||||
if let Some(part_l) = part.partlabel_dev() {
|
||||
log::info!("Formating SWAP partition.");
|
||||
kira_system::mkswap(&part_l)?;
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
///
|
||||
/// Writes locales from loc_lines to locale.gen file passed in loc_gen_file_path
|
||||
/// Checks if locales from loc_lines defined in locale.gen
|
||||
///
|
||||
fn locale_gen_write(
|
||||
loc_gen_file_path: &str,
|
||||
loc_lines: &Vec<String>,
|
||||
) -> Result<(), ExecCommandError> {
|
||||
use std::fs::OpenOptions;
|
||||
use std::io::Write;
|
||||
|
||||
// need this to check for locales existance
|
||||
let loc_gen_content = fs::read_to_string(loc_gen_file_path)?;
|
||||
|
||||
// Open locale.gen file in append mode
|
||||
let mut locale_file = OpenOptions::new()
|
||||
.create(false)
|
||||
.append(true)
|
||||
.open(loc_gen_file_path)?;
|
||||
|
||||
writeln!(
|
||||
locale_file,
|
||||
"\n# Next lines is autogenerated by Kira Installer"
|
||||
)?;
|
||||
for loc in loc_lines {
|
||||
// check if locale defined
|
||||
if loc_gen_content.contains(loc) {
|
||||
writeln!(locale_file, "{}", loc)?;
|
||||
log::info!("Added ({}) locale.", loc);
|
||||
} else {
|
||||
// if not defined write comment on this matter
|
||||
log::info!("Locale ({}) is not defined in locale.gen file.", loc);
|
||||
writeln!(locale_file, "# Missing: {}", loc)?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn config_stuff(k_config: KiraConfig) -> Result<(), ExecCommandError> {
|
||||
use std::fs::OpenOptions;
|
||||
use std::io::Write;
|
||||
|
||||
let loc_gen_fn = format!("{}/etc/locale.gen", MNT_DIR);
|
||||
|
||||
log::info!("Generating fstab...");
|
||||
kira_system::fstabgen(MNT_DIR)?;
|
||||
|
||||
log::info!("Configuring locales...");
|
||||
{
|
||||
let loc_data = k_config.res_locale.as_ref().unwrap();
|
||||
let lang_line = loc_data.lang_locale.locale_gen_line();
|
||||
let formats_line = loc_data.formats_locale.locale_gen_line();
|
||||
let mut loc_lines: Vec<String> = Vec::new();
|
||||
// if selected locale is not en, we will add en_US.UTF-8 UTF-8 to locales.gen
|
||||
if !lang_line.starts_with("en_") && !formats_line.starts_with("en_") {
|
||||
loc_lines.push("en_US.UTF-8 UTF-8".into());
|
||||
}
|
||||
// write formats locale if it is different from lang locale
|
||||
if lang_line != formats_line {
|
||||
loc_lines.push(formats_line);
|
||||
}
|
||||
loc_lines.push(lang_line);
|
||||
|
||||
locale_gen_write(&loc_gen_fn, &loc_lines)?;
|
||||
}
|
||||
// Running locale-gen
|
||||
kira_system::exec_cmd_chroot(MNT_DIR, "locale-gen", &vec![])?;
|
||||
|
||||
log::info!("Konfiguring keyboard...");
|
||||
log::info!("Kayboard conf: {}", k_config.res_keyboard.as_ref().unwrap());
|
||||
|
||||
// dinit reads /etc/vconsole.conf
|
||||
// but
|
||||
// config /etc/conf.d/keymaps as a backup
|
||||
log::info!("Writing /etc/conf.d/keymaps");
|
||||
let kbd_conf = k_config.res_keyboard.as_ref().unwrap();
|
||||
let console_keymap = kbd_conf.crazy_bonker_console_keymap();
|
||||
fs::write(
|
||||
"/etc/conf.d/keymaps",
|
||||
format!(
|
||||
"# Autogeneradet by Kira Installer\nkeymap={}",
|
||||
console_keymap
|
||||
),
|
||||
)?;
|
||||
|
||||
log::info!("Writing /etc/vconsole.conf");
|
||||
let vconsole_content = format!(
|
||||
"Autogeneradet by Kira Installer \
|
||||
FONT={} \
|
||||
KEYMAP={} \
|
||||
XKBMODEL={} \
|
||||
XKBLAYOUT={} \
|
||||
XKBVARIANT={}\n",
|
||||
CONSOLE_FONT,
|
||||
&console_keymap,
|
||||
kbd_conf.xkb_model(),
|
||||
kbd_conf.xkb_layout(),
|
||||
kbd_conf.xkb_variant()
|
||||
);
|
||||
fs::write("/etc/vconsole.conf", vconsole_content)?;
|
||||
|
||||
//kira_system::exec_cmd_chroot(chroot_dir, cmd, args)
|
||||
|
||||
//locale-gen
|
||||
//Configure the system clock
|
||||
|
||||
// Set the time zone:
|
||||
// ln -sf /usr/share/zoneinfo/Region/City /etc/localtime
|
||||
// Run hwclock to generate /etc/adjtime:
|
||||
// hwclock --systohc
|
||||
log::info!("Configuring timezone...");
|
||||
let time_conf = k_config.res_timezone.as_ref().unwrap();
|
||||
let tz_file_name = time_conf.time_zone.tz_file_name();
|
||||
kira_system::exec_cmd_chroot(
|
||||
MNT_DIR,
|
||||
"ln",
|
||||
&vec!["-sf", tz_file_name.as_ref(), "/etc/localtime"],
|
||||
)?;
|
||||
// Run hwclock to generate /etc/adjtime:
|
||||
// hwclock --systohc
|
||||
kira_system::exec_cmd_chroot(MNT_DIR, "hwclock", &vec!["--systohc"])?;
|
||||
|
||||
// set root password
|
||||
log::info!("Setting root password...");
|
||||
let sec_conf = k_config.res_security.as_ref().unwrap();
|
||||
kira_system::set_root_passwd(MNT_DIR, &sec_conf.root_password)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
enum InstallationState {
|
||||
UserConfirmDialog,
|
||||
Installing,
|
||||
Finish,
|
||||
Error,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct InstallStageResult {
|
||||
pub sucess: Result<(), String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct InstallStage {
|
||||
state: InstallationState,
|
||||
progress: f32,
|
||||
progress_message: String,
|
||||
modal_backgroud: Color,
|
||||
k_config: KiraConfig,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Message {
|
||||
UserConfirms,
|
||||
UserDenies,
|
||||
Success,
|
||||
Cancel,
|
||||
Finish,
|
||||
UpdateProgress(Result<(f32, String), String>),
|
||||
Failure(String),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Update {
|
||||
StgAct(StageAction),
|
||||
Task(Task<Message>),
|
||||
}
|
||||
|
||||
pub fn mount_and_init_root(
|
||||
part_layout: &PartLayout,
|
||||
mnt_dir: &str,
|
||||
) -> Result<(), ExecCommandError> {
|
||||
// init root
|
||||
let root_part = part_layout
|
||||
.get_part(PartRole::ROOT)
|
||||
.expect("Root partition must be present!");
|
||||
log::info!("Mount and init root partition.");
|
||||
if let FSType::BCACHEFS(bcache_prop) = root_part.fs_type {
|
||||
bcachefs_init(ROOT_PARTLABEL_DEV, mnt_dir, bcache_prop.password.clone())?;
|
||||
} else {
|
||||
return Err(ExecCommandError::Other(format!(
|
||||
"Unexpected root partition type: {}",
|
||||
root_part.fs_type
|
||||
)));
|
||||
}
|
||||
|
||||
log::info!("Mounting EFI partition");
|
||||
kira_system::mount_fs(EFI_PARTLABLE_DEV, EFI_BOOT_MOUNT_POINT)?;
|
||||
|
||||
log::info!("Attaching swap partition");
|
||||
kira_system::swapon(SWAP_PARTLABLE_DEV)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn init_disk_async(part_layout: PartLayout, mnt_dir: String) -> Result<(), ExecCommandError> {
|
||||
use blocking;
|
||||
blocking::unblock(move || init_disk(&part_layout, &mnt_dir)).await
|
||||
}
|
||||
|
||||
async fn mount_and_init_root_async(
|
||||
part_layout: PartLayout,
|
||||
mnt_dir: String,
|
||||
) -> Result<(), ExecCommandError> {
|
||||
use blocking;
|
||||
blocking::unblock(move || mount_and_init_root(&part_layout, &mnt_dir)).await
|
||||
}
|
||||
|
||||
async fn install_base_async(mnt_dir: String) -> Result<(), ExecCommandError> {
|
||||
use blocking;
|
||||
log::info!("Installing base system...");
|
||||
blocking::unblock(move || kira_system::basestrap_dinit(&mnt_dir)).await
|
||||
}
|
||||
|
||||
async fn install_core_desk_async(mnt_dir: String) -> Result<(), ExecCommandError> {
|
||||
use blocking;
|
||||
log::info!("Installing core desktop packages...");
|
||||
blocking::unblock(move || kira_system::basestrap(&mnt_dir, &PKG_LIST_CORE_DESKTOP)).await
|
||||
}
|
||||
|
||||
async fn install_kde_desk_async(mnt_dir: String) -> Result<(), ExecCommandError> {
|
||||
use blocking;
|
||||
log::info!("Installing KDE desktop packages...");
|
||||
blocking::unblock(move || kira_system::basestrap(&mnt_dir, &PKG_LIST_KDE_DESKTOP)).await
|
||||
}
|
||||
|
||||
async fn config_stuff_async(k_config: KiraConfig) -> Result<(), ExecCommandError> {
|
||||
use blocking;
|
||||
log::info!("Configuring installed system...");
|
||||
blocking::unblock(move || config_stuff(k_config)).await
|
||||
}
|
||||
|
||||
fn do_install(
|
||||
k_config: KiraConfig,
|
||||
) -> impl futures::Stream<Item = Result<(f32, String), ExecCommandError>> {
|
||||
iced::stream::channel(
|
||||
100,
|
||||
|mut output: Sender<Result<(f32, String), ExecCommandError>>| async move {
|
||||
//sleep(Duration::from_millis(10)).await;
|
||||
let disk_layout = k_config.res_partition.as_ref().unwrap().part_layout.clone();
|
||||
|
||||
// creating gpt partition table
|
||||
let res = init_disk_async(disk_layout.clone(), MNT_DIR.into()).await;
|
||||
let res_err = res.is_err();
|
||||
output
|
||||
.send(res.map(|_| (1.1f32, "Formatting bcachefs".into())))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
if res_err {
|
||||
return;
|
||||
}
|
||||
|
||||
// Mount and init root
|
||||
let res = mount_and_init_root_async(disk_layout, MNT_DIR.into()).await;
|
||||
let res_err = res.is_err();
|
||||
output
|
||||
.send(res.map(|_| (5.1f32, "Installing base".into())))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
if res_err {
|
||||
return;
|
||||
}
|
||||
|
||||
// installing base system
|
||||
let res = install_base_async(MNT_DIR.into()).await;
|
||||
let res_err = res.is_err();
|
||||
output
|
||||
.send(res.map(|_| (10.0f32, "Installing core system".into())))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
if res_err {
|
||||
return;
|
||||
}
|
||||
|
||||
// installing core system
|
||||
let res = install_core_desk_async(MNT_DIR.into()).await;
|
||||
let res_err = res.is_err();
|
||||
output
|
||||
.send(res.map(|_| (20.0f32, "Installing KDE desktop envirometn".into())))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
if res_err {
|
||||
return;
|
||||
}
|
||||
|
||||
// installing KDE
|
||||
let res = install_kde_desk_async(MNT_DIR.into()).await;
|
||||
let res_err = res.is_err();
|
||||
output
|
||||
.send(res.map(|_| (50.0f32, "Configuring system".into())))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
if res_err {
|
||||
return;
|
||||
}
|
||||
|
||||
// configuring system
|
||||
let res = config_stuff_async(k_config.clone()).await;
|
||||
let res_err = res.is_err();
|
||||
output
|
||||
.send(res.map(|_| (60.0f32, "Next step".into())))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
if res_err {
|
||||
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();
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
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;
|
||||
modal_backgroud.a = 0.5;
|
||||
Self {
|
||||
modal_backgroud: modal_backgroud,
|
||||
state: InstallationState::UserConfirmDialog,
|
||||
progress: 0.0,
|
||||
progress_message: String::new(),
|
||||
k_config: k_config,
|
||||
}
|
||||
}
|
||||
|
||||
fn gen_result(&mut self) -> KiraConfig {
|
||||
self.k_config.res_install = Some(InstallStageResult { sucess: Ok(()) });
|
||||
self.k_config.clone()
|
||||
}
|
||||
|
||||
pub fn update(&mut self, message: Message) -> Update {
|
||||
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;
|
||||
Update::Task(Task::run(
|
||||
do_install(self.k_config.clone()).map_err(|ex| ex.to_string()),
|
||||
Message::UpdateProgress,
|
||||
))
|
||||
//Update::Task(Task::perform(, Message::PartitioningFinish))
|
||||
}
|
||||
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::Failure(ex) => {
|
||||
self.state = InstallationState::Error;
|
||||
Update::StgAct(StageAction::Abort)
|
||||
}
|
||||
Message::Cancel => Update::StgAct(StageAction::Abort),
|
||||
Message::Success => Update::StgAct(StageAction::None),
|
||||
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 logo_handle = widget::image::Handle::from_bytes(kira_theming::get_logo_bytes());
|
||||
|
||||
let main_content = widget::column![
|
||||
widget::container(
|
||||
widget::column![
|
||||
widget::image(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::opaque(
|
||||
container(
|
||||
container(
|
||||
widget::column![
|
||||
widget::text(t!("install.warning")).align_x(Alignment::Center),
|
||||
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)
|
||||
]
|
||||
.padding(10)
|
||||
]
|
||||
.spacing(10)
|
||||
.padding(10)
|
||||
.width(512)
|
||||
.align_x(Alignment::Center),
|
||||
)
|
||||
.style(kira_theming::warning_dialog),
|
||||
)
|
||||
.style(container::bordered_box)
|
||||
.style(kira_theming::dialog_background)
|
||||
.align_x(Alignment::Center)
|
||||
.align_y(Alignment::Center)
|
||||
.height(Length::Fill)
|
||||
.width(Length::Fill),
|
||||
))
|
||||
.into()
|
||||
} else {
|
||||
page_stack.into()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,565 @@
|
||||
// <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/>.
|
||||
|
||||
/*
|
||||
This is Keyboar stage, used to select Keyboard Layouts
|
||||
*/
|
||||
|
||||
use crate::kira_scroll_list::{self, ListViewMessage};
|
||||
use crate::kira_system;
|
||||
use crate::kira_text_input;
|
||||
use crate::stage::{KiraConfig, StageAction};
|
||||
use iced::{Alignment, Length, Task, widget};
|
||||
use log;
|
||||
use rust_i18n::t;
|
||||
use std::collections::HashMap;
|
||||
use xkbcommon::xkb;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct Layout {
|
||||
layout: String,
|
||||
description: String,
|
||||
}
|
||||
impl std::fmt::Display for Layout {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{} ({})", &self.layout, &self.description)
|
||||
}
|
||||
}
|
||||
impl Layout {
|
||||
pub fn from_str_touple(v: &(&str, &str)) -> Self {
|
||||
Self {
|
||||
layout: v.0.trim().to_string(),
|
||||
description: v.1.trim().to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct Variant {
|
||||
variant: String,
|
||||
description: String,
|
||||
}
|
||||
impl std::fmt::Display for Variant {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{} ({})", &self.variant, &self.description)
|
||||
}
|
||||
}
|
||||
impl Variant {
|
||||
pub fn from_str_touple(v: &(&str, &str)) -> Self {
|
||||
Self {
|
||||
variant: v.0.trim().to_string(),
|
||||
description: v.1.trim().to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Variant {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
variant: "default".into(),
|
||||
description: "Default variant".into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct KeyboarLayout {
|
||||
layout: Layout,
|
||||
variant: Variant,
|
||||
}
|
||||
|
||||
impl KeyboarLayout {
|
||||
pub fn to_result(&self) -> String {
|
||||
format!("{}||{}", self.layout.layout, self.variant.variant)
|
||||
}
|
||||
pub fn xkb_layout(&self) -> String {
|
||||
self.layout.layout.clone()
|
||||
}
|
||||
///
|
||||
/// Returns string variant or empty string if variant is "default"
|
||||
///
|
||||
pub fn xkb_variant(&self) -> String {
|
||||
if self.variant.variant == "default" {
|
||||
"".into()
|
||||
} else {
|
||||
self.variant.variant.clone()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct KeyboarModel {
|
||||
model: String,
|
||||
description: String,
|
||||
}
|
||||
impl std::fmt::Display for KeyboarModel {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{} ({})", &self.model, &self.description)
|
||||
}
|
||||
}
|
||||
|
||||
impl KeyboarModel {
|
||||
pub fn from_str_touple(v: &(&str, &str)) -> Self {
|
||||
Self {
|
||||
model: v.0.trim().to_string(),
|
||||
description: v.1.trim().to_string(),
|
||||
}
|
||||
}
|
||||
pub fn xkb_model(&self) -> String {
|
||||
self.model.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for KeyboarLayout {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{}/{}", &self.layout.layout, &self.variant.variant)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct KeyboardStage {
|
||||
models: Vec<KeyboarModel>,
|
||||
model: Option<KeyboarModel>,
|
||||
layouts: Vec<Layout>,
|
||||
layout: Option<usize>,
|
||||
variants_map: HashMap<String, Vec<Variant>>,
|
||||
variants: Vec<Variant>,
|
||||
variant: Option<usize>,
|
||||
keyboard_layout: Option<KeyboarLayout>,
|
||||
// selected_kbd_layout_id: Option<usize>,
|
||||
k_config: KiraConfig,
|
||||
test_text: String,
|
||||
xkb_keymap: Option<xkb::Keymap>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct KeyboardStageResult {
|
||||
pub keyboard_model: KeyboarModel,
|
||||
pub keyboard_layout: KeyboarLayout,
|
||||
}
|
||||
|
||||
impl KeyboardStageResult {
|
||||
///
|
||||
/// doing crazy guess of console keymap
|
||||
///
|
||||
pub fn crazy_bonker_console_keymap(&self) -> String {
|
||||
const LAT_MAP: [&str; 13] = [
|
||||
"us", "fr", "it", "es", "pt", "pl", "cz", "no", "se", "fi", "dk", "nl", "hu",
|
||||
];
|
||||
const DE_MAP: &str = "de-latin1-nodeadkeys";
|
||||
const DEAFULT_MAP: &str = "us";
|
||||
|
||||
let layout = self.keyboard_layout.layout.layout.as_str();
|
||||
let model = self.keyboard_model.model.as_str();
|
||||
if layout == "de" {
|
||||
DE_MAP.to_string()
|
||||
} else if LAT_MAP.contains(&layout) {
|
||||
layout.to_string()
|
||||
}
|
||||
// if xkb_layout is non-Latin
|
||||
else if model == "pc105" {
|
||||
DE_MAP.to_string()
|
||||
} else {
|
||||
DEAFULT_MAP.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn xkb_model(&self) -> String {
|
||||
self.keyboard_model.xkb_model()
|
||||
}
|
||||
|
||||
pub fn xkb_layout(&self) -> String {
|
||||
self.keyboard_layout.xkb_layout()
|
||||
}
|
||||
|
||||
///
|
||||
/// Returns string variant or empty string if variant is "default"
|
||||
///
|
||||
pub fn xkb_variant(&self) -> String {
|
||||
self.keyboard_layout.xkb_variant()
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for KeyboardStageResult {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"keyboard_model: {} | keyboard_layout: {}",
|
||||
&self.keyboard_model, &self.keyboard_layout
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Message {
|
||||
SelectKeyboardModel(KeyboarModel),
|
||||
SelectLayout(kira_scroll_list::ListViewMessage),
|
||||
SelectVariant(kira_scroll_list::ListViewMessage),
|
||||
TestTextChange(String),
|
||||
|
||||
// AddLayout(usize),
|
||||
// RemoveLayout(usize),
|
||||
// SelectAddedLayout(kira_scroll_list::ListViewMessage),
|
||||
Next,
|
||||
Back,
|
||||
}
|
||||
|
||||
const XKB_RULES_FILE_NAME: &str = "/usr/share/X11/xkb/rules/evdev.lst";
|
||||
|
||||
/// Getting list of awailable keyboard layouts from from xkb/rules/evdev.lst file.
|
||||
fn get_layouts_blocking() -> std::io::Result<(
|
||||
Vec<KeyboarModel>,
|
||||
Vec<Layout>,
|
||||
HashMap<String, Vec<Variant>>,
|
||||
)> {
|
||||
use std::fs::File;
|
||||
use std::io::{BufReader, Read};
|
||||
|
||||
let mut file_content = String::new();
|
||||
{
|
||||
let locgen_file = File::open(XKB_RULES_FILE_NAME)?;
|
||||
let mut reader = BufReader::new(locgen_file);
|
||||
reader.read_to_string(&mut file_content)?;
|
||||
}
|
||||
|
||||
let raw_sections: Vec<String> = file_content.split("! ").map(str::to_string).collect();
|
||||
|
||||
// Parsing models data
|
||||
let models: Vec<KeyboarModel> = raw_sections
|
||||
.iter()
|
||||
.find(|s| s.starts_with("model"))
|
||||
.and_then(|s| {
|
||||
Some(
|
||||
s.lines()
|
||||
.skip(1)
|
||||
.filter_map(|s| s.trim().split_once(char::is_whitespace))
|
||||
.map(|s_spl| KeyboarModel::from_str_touple(&s_spl))
|
||||
.collect(),
|
||||
)
|
||||
})
|
||||
.unwrap_or_else(Vec::new);
|
||||
|
||||
// Parsing layots data
|
||||
let layouts: Vec<Layout> = raw_sections
|
||||
.iter()
|
||||
.find(|s| s.starts_with("layout"))
|
||||
.and_then(|s| {
|
||||
Some(
|
||||
s.lines()
|
||||
.skip(1)
|
||||
.filter_map(|s| s.trim().split_once(char::is_whitespace))
|
||||
.map(|s_spl| Layout::from_str_touple(&s_spl))
|
||||
.collect(),
|
||||
)
|
||||
})
|
||||
.unwrap_or_else(Vec::new);
|
||||
|
||||
// parsing variants data to HashMap
|
||||
let mut variants: HashMap<String, Vec<Variant>> = layouts
|
||||
.iter()
|
||||
.map(|l| (l.layout.clone(), vec![Variant::default()]))
|
||||
.collect();
|
||||
|
||||
raw_sections
|
||||
.iter()
|
||||
.find(|s| s.starts_with("variant"))
|
||||
.and_then(|s| {
|
||||
Some(
|
||||
s.lines()
|
||||
.skip(1)
|
||||
.filter_map(|s| s.trim().split_once(char::is_whitespace))
|
||||
.filter_map(|(vrnt, l_plus_descr)| {
|
||||
l_plus_descr
|
||||
.trim()
|
||||
.split_once(": ")
|
||||
.and_then(|(loc, descr)| {
|
||||
Some((loc.trim(), Variant::from_str_touple(&(vrnt, descr))))
|
||||
})
|
||||
})
|
||||
.for_each(|v| {
|
||||
let maybe_key = variants
|
||||
.get_mut(v.0)
|
||||
.and_then(|vrn_vec| Some(vrn_vec.push(v.1.clone())));
|
||||
if maybe_key.is_none() {
|
||||
variants.insert(v.0.to_string(), vec![v.1.clone()]);
|
||||
}
|
||||
}),
|
||||
)
|
||||
});
|
||||
|
||||
Ok((models, layouts, variants))
|
||||
}
|
||||
|
||||
impl KeyboardStage {
|
||||
pub fn new(k_config: KiraConfig) -> Self {
|
||||
match get_layouts_blocking() {
|
||||
Ok((models, layouts, variants_map)) => {
|
||||
let def_layout = layouts
|
||||
.iter()
|
||||
.enumerate()
|
||||
.find_map(|(idx, l)| (l.layout == "us").then_some(idx));
|
||||
|
||||
let variants = variants_map["us"].clone();
|
||||
|
||||
let def_model = models[0].clone();
|
||||
|
||||
let keyboard_layout = def_layout.and_then(|li_d| {
|
||||
Some(KeyboarLayout {
|
||||
layout: layouts[li_d].clone(),
|
||||
variant: variants[0].clone(),
|
||||
})
|
||||
});
|
||||
|
||||
Self {
|
||||
layouts: layouts,
|
||||
variants_map: variants_map,
|
||||
variants: variants,
|
||||
model: Some(def_model),
|
||||
models: models,
|
||||
layout: def_layout,
|
||||
variant: Some(0),
|
||||
keyboard_layout: keyboard_layout,
|
||||
k_config: k_config,
|
||||
test_text: String::new(),
|
||||
xkb_keymap: None,
|
||||
}
|
||||
}
|
||||
Err(ex) => {
|
||||
log::error!(
|
||||
"Exception while trying to get kayboard layouts data from system {}",
|
||||
ex
|
||||
);
|
||||
Self {
|
||||
layouts: Vec::new(),
|
||||
variants_map: HashMap::new(),
|
||||
variants: Vec::new(),
|
||||
model: None,
|
||||
models: Vec::new(),
|
||||
layout: None,
|
||||
variant: None,
|
||||
keyboard_layout: None,
|
||||
k_config: k_config,
|
||||
test_text: String::new(),
|
||||
xkb_keymap: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// fn set_input_method(&self) -> Task<Message> {
|
||||
// log::info!("Preparing task!");
|
||||
// let (layout, variant) = if let Some(kb_layout) = &self.keyboard_layout {
|
||||
// (kb_layout.xkb_layout(), kb_layout.xkb_variant())
|
||||
// } else {
|
||||
// (String::new(), String::new())
|
||||
// };
|
||||
// let model = if let Some(kb_model) = &self.model {
|
||||
// kb_model.xkb_model()
|
||||
// } else {
|
||||
// String::new()
|
||||
// };
|
||||
// log::info!("Task perform!");
|
||||
// Task::perform(
|
||||
// async move {
|
||||
// let a = kira_system::set_input_method(&layout, &model, &variant, "").await;
|
||||
// log::info!("Result: {:?}", a);
|
||||
// },
|
||||
// |_| Message::SysLayoutChanged,
|
||||
// )
|
||||
// }s
|
||||
|
||||
fn gen_keymap(&mut self) -> () {
|
||||
log::debug!("Generating keyboard keymap!");
|
||||
let (layout, variant) = if let Some(kb_layout) = &self.keyboard_layout {
|
||||
(kb_layout.xkb_layout(), kb_layout.xkb_variant())
|
||||
} else {
|
||||
(String::new(), String::new())
|
||||
};
|
||||
let model = if let Some(kb_model) = &self.model {
|
||||
kb_model.xkb_model()
|
||||
} else {
|
||||
String::new()
|
||||
};
|
||||
log::debug!(
|
||||
"model:{:?}, layout:{:?}, variant:{:?}",
|
||||
model,
|
||||
layout,
|
||||
variant
|
||||
);
|
||||
|
||||
// create context
|
||||
let ctx = xkb::Context::new(xkb::CONTEXT_NO_FLAGS);
|
||||
let xkb_keymap = xkb::Keymap::new_from_names(
|
||||
&ctx,
|
||||
"evdev",
|
||||
&model,
|
||||
&layout,
|
||||
&variant,
|
||||
None,
|
||||
xkb::COMPILE_NO_FLAGS,
|
||||
);
|
||||
if xkb_keymap.is_none() {
|
||||
log::error!("Cannot compile XKB keymap!");
|
||||
} else {
|
||||
self.xkb_keymap = xkb_keymap;
|
||||
}
|
||||
}
|
||||
|
||||
fn gen_result(&mut self) -> KiraConfig {
|
||||
self.k_config.res_keyboard = Some(KeyboardStageResult {
|
||||
keyboard_model: self.model.clone().expect("Keyboard model must be choosed!"),
|
||||
keyboard_layout: self
|
||||
.keyboard_layout
|
||||
.clone()
|
||||
.expect("Keyboard layout must be choosed!"),
|
||||
});
|
||||
self.k_config.clone()
|
||||
}
|
||||
|
||||
pub fn update(&mut self, message: Message) -> StageAction {
|
||||
match message {
|
||||
Message::SelectLayout(ListViewMessage::Select(l_id)) => {
|
||||
if let Some(current_l_id) = self.layout
|
||||
&& current_l_id != l_id
|
||||
{
|
||||
self.layout = Some(l_id);
|
||||
self.variants = self.variants_map[self.layouts[l_id].layout.as_str()].clone();
|
||||
self.variant = Some(0);
|
||||
|
||||
let layout = self.layouts[l_id].clone();
|
||||
let variant = self.variants[0].clone();
|
||||
|
||||
self.keyboard_layout = Some(KeyboarLayout {
|
||||
layout: layout,
|
||||
variant: variant,
|
||||
});
|
||||
|
||||
self.gen_keymap();
|
||||
}
|
||||
StageAction::None
|
||||
}
|
||||
Message::SelectVariant(ListViewMessage::Select(v_id)) => {
|
||||
self.variant = Some(v_id);
|
||||
self.keyboard_layout = Some(KeyboarLayout {
|
||||
layout: self.layouts[self.layout.unwrap()].clone(),
|
||||
variant: self.variants[v_id].clone(),
|
||||
});
|
||||
self.gen_keymap();
|
||||
StageAction::None
|
||||
}
|
||||
Message::SelectKeyboardModel(k_m) => {
|
||||
self.model = Some(k_m);
|
||||
self.gen_keymap();
|
||||
StageAction::None
|
||||
}
|
||||
Message::TestTextChange(test_text) => {
|
||||
let mut res: String = test_text;
|
||||
res.retain(|c: char| !c.is_control());
|
||||
self.test_text = res;
|
||||
StageAction::None
|
||||
}
|
||||
Message::Next => StageAction::Next(self.gen_result()),
|
||||
Message::Back => StageAction::Back,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn view(&self) -> iced::Element<'_, Message> {
|
||||
let next_button = if self.model.is_some() && self.keyboard_layout.is_some() {
|
||||
widget::button(widget::text(t!("button.next"))).on_press(Message::Next)
|
||||
} else {
|
||||
widget::button(widget::text(t!("button.next")))
|
||||
};
|
||||
|
||||
let main_content = if self.layouts.len() > 0 {
|
||||
widget::container(
|
||||
widget::column![
|
||||
widget::column![
|
||||
widget::text(t!("keyboard.select_model")),
|
||||
widget::pick_list(
|
||||
self.models.clone(),
|
||||
self.model.clone(),
|
||||
Message::SelectKeyboardModel,
|
||||
)
|
||||
],
|
||||
widget::row![
|
||||
widget::column![
|
||||
widget::text(t!("keyboard.select_layout")),
|
||||
crate::kira_scroll_list::list_view(
|
||||
&self.layouts,
|
||||
self.layout,
|
||||
Length::Fill
|
||||
)
|
||||
.map(Message::SelectLayout)
|
||||
],
|
||||
widget::column![
|
||||
widget::text(t!("keyboard.select_variant")),
|
||||
crate::kira_scroll_list::list_view(
|
||||
&self.variants,
|
||||
self.variant,
|
||||
Length::Fill
|
||||
)
|
||||
.map(Message::SelectVariant)
|
||||
],
|
||||
]
|
||||
.spacing(10)
|
||||
.height(Length::Fill),
|
||||
widget::row![
|
||||
widget::text("Test Keyboard:"),
|
||||
//widget::text_input("", &self.test_text).on_input(Message::TestTextChange),
|
||||
kira_text_input::TextInput::new("", &self.test_text)
|
||||
.keymap(self.xkb_keymap.clone())
|
||||
.on_input(Message::TestTextChange),
|
||||
]
|
||||
.spacing(2)
|
||||
.align_y(Alignment::Center)
|
||||
.width(Length::Fill),
|
||||
]
|
||||
.spacing(10)
|
||||
.height(Length::Fill)
|
||||
.align_x(Alignment::Center),
|
||||
)
|
||||
} else {
|
||||
widget::container(widget::text(t!("keyboard.init_error")))
|
||||
};
|
||||
|
||||
let back_button = widget::button(widget::text(t!("button.back"))).on_press(Message::Back);
|
||||
|
||||
widget::column![
|
||||
main_content
|
||||
.padding(iced::Padding {
|
||||
top: 10.0,
|
||||
right: 10.0,
|
||||
bottom: 0.0,
|
||||
left: 10.0,
|
||||
})
|
||||
.height(iced::Length::Fill)
|
||||
.width(iced::Length::Fill)
|
||||
.align_x(Alignment::Center)
|
||||
.align_y(Alignment::Center),
|
||||
widget::row![
|
||||
back_button,
|
||||
widget::space::horizontal(), // Pushes the right button to the far right
|
||||
next_button
|
||||
]
|
||||
.width(iced::Length::Fill)
|
||||
.align_y(Alignment::End)
|
||||
.padding(10),
|
||||
]
|
||||
.align_x(Alignment::Center)
|
||||
.spacing(10)
|
||||
.into()
|
||||
}
|
||||
}
|
||||
+42
-44
@@ -1,36 +1,34 @@
|
||||
// <Kira Installer - universal Linux installer.>
|
||||
// Copyright (C) <2026> <Kira Foundation>
|
||||
// <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 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/>.
|
||||
// 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/>.
|
||||
|
||||
/*
|
||||
This is License stage. Used to inform user about program legal status.
|
||||
*/
|
||||
|
||||
|
||||
This is License stage. Used to inform user about program legal status.
|
||||
*/
|
||||
|
||||
use iced::{Alignment, widget};
|
||||
|
||||
use rust_i18n::t;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::{stage, theme};
|
||||
use crate::stage::StageResult;
|
||||
use crate::stage;
|
||||
use crate::stage::KiraConfig;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct LicenseStage {}
|
||||
pub struct LicenseStage {
|
||||
k_config: KiraConfig,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Message {
|
||||
@@ -46,28 +44,20 @@ pub enum Message {
|
||||
//const LICENSE_TEXT: &str = include_str!("gpl-3.0.txt");
|
||||
|
||||
impl LicenseStage {
|
||||
fn accepted() -> StageResult {
|
||||
StageResult {
|
||||
name: "license".into(),
|
||||
config: Some(HashMap::from([(
|
||||
"accepted".to_string(),
|
||||
stage::ConfigValue::Bool(true),
|
||||
)])),
|
||||
resuts: None,
|
||||
error: None,
|
||||
}
|
||||
pub fn new(k_config: KiraConfig) -> Self {
|
||||
Self { k_config: k_config }
|
||||
}
|
||||
|
||||
fn accepted(&mut self) -> KiraConfig {
|
||||
self.k_config.res_license = true;
|
||||
self.k_config.clone()
|
||||
}
|
||||
|
||||
pub fn update(&mut self, message: Message) -> stage::StageAction {
|
||||
match message {
|
||||
Message::Accept => stage::StageAction::Next(Self::accepted()),
|
||||
Message::Accept => stage::StageAction::Next(self.accepted()),
|
||||
Message::Back => stage::StageAction::Back,
|
||||
Message::Decline => stage::StageAction::Abort(StageResult {
|
||||
name: "license".into(),
|
||||
config: None,
|
||||
resuts: None,
|
||||
error: Some("Declined.".to_string()),
|
||||
}),
|
||||
Message::Decline => stage::StageAction::Abort,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,12 +69,20 @@ impl LicenseStage {
|
||||
widget::button(widget::text(t!("license.button.decline"))).on_press(Message::Decline);
|
||||
|
||||
widget::column![
|
||||
widget::container(widget::column![
|
||||
widget::text(t!("license.accept_text")),
|
||||
widget::container(widget::text(t!("license.license")))
|
||||
.padding(10)
|
||||
.style(theme::text_with_border)
|
||||
].align_x(Alignment::Center).padding(20).spacing(5))
|
||||
widget::container(
|
||||
widget::column![
|
||||
widget::text(t!("license.accept_text")).font(iced::Font {
|
||||
weight: iced::font::Weight::Bold,
|
||||
..iced::Font::DEFAULT
|
||||
}),
|
||||
widget::container(widget::text(t!("license.license")))
|
||||
.padding(10)
|
||||
.style(widget::container::bordered_box)
|
||||
]
|
||||
.align_x(Alignment::Center)
|
||||
.padding(20)
|
||||
.spacing(15)
|
||||
)
|
||||
.height(iced::Length::Fill)
|
||||
.width(iced::Length::Fill)
|
||||
.align_x(Alignment::Center)
|
||||
|
||||
@@ -0,0 +1,191 @@
|
||||
// <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/>.
|
||||
|
||||
/*
|
||||
This is Locales stage, used to choose global and numbers locale
|
||||
*/
|
||||
|
||||
use crate::{
|
||||
kira_theming,
|
||||
stage::{KiraConfig, StageAction},
|
||||
};
|
||||
use iced::{Alignment, widget};
|
||||
use rust_i18n::t;
|
||||
|
||||
use crate::kira_locales::{self, LocaleData, get_locales_blocking};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct LocaleStage {
|
||||
lang_locale: Option<LocaleData>,
|
||||
formats_locale: Option<LocaleData>,
|
||||
locales: Vec<LocaleData>,
|
||||
lang_locale_text: String,
|
||||
all_locale_text: String,
|
||||
k_config: KiraConfig,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct LocaleStageResult {
|
||||
pub lang_locale: LocaleData,
|
||||
pub formats_locale: LocaleData,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Message {
|
||||
SelectLangLocale(LocaleData),
|
||||
SelectFormatsLocale(LocaleData),
|
||||
Next,
|
||||
Back,
|
||||
}
|
||||
|
||||
impl LocaleStage {
|
||||
pub fn new(k_config: KiraConfig) -> Self {
|
||||
// get seelctet language code from welcome stage
|
||||
let maybe_lang = k_config
|
||||
.res_welcome
|
||||
.as_ref()
|
||||
.and_then(|rw| Some(rw.loc_code.clone()));
|
||||
|
||||
let maybe_tz = k_config
|
||||
.res_timezone
|
||||
.as_ref()
|
||||
.and_then(|tzr| Some(tzr.time_zone.clone()));
|
||||
|
||||
let locales: Vec<LocaleData> = get_locales_blocking(Some("UTF-8")).unwrap();
|
||||
|
||||
let lang_match = maybe_lang
|
||||
.and_then(|lang| kira_locales::guess_locale(&locales, &lang, maybe_tz))
|
||||
.unwrap_or_else(LocaleData::default);
|
||||
|
||||
let lang_locale_text = format!(
|
||||
"{}: {}",
|
||||
t!("locale.select_language_locale"),
|
||||
lang_match.code
|
||||
);
|
||||
let all_locale_text = format!(
|
||||
"{}: {}",
|
||||
t!("locale.select_formats_locale"),
|
||||
lang_match.code
|
||||
);
|
||||
Self {
|
||||
lang_locale: Some(lang_match.clone()),
|
||||
formats_locale: Some(lang_match),
|
||||
locales: locales,
|
||||
lang_locale_text: lang_locale_text,
|
||||
all_locale_text: all_locale_text,
|
||||
k_config: k_config,
|
||||
}
|
||||
}
|
||||
|
||||
fn gen_result(&mut self) -> KiraConfig {
|
||||
self.k_config.res_locale = if let Some(lang_locale) = &self.lang_locale
|
||||
&& let Some(formats_locale) = &self.formats_locale
|
||||
{
|
||||
Some(LocaleStageResult {
|
||||
lang_locale: lang_locale.clone(),
|
||||
formats_locale: formats_locale.clone(),
|
||||
})
|
||||
} else {
|
||||
let loc = LocaleData::default();
|
||||
Some(LocaleStageResult {
|
||||
lang_locale: loc.clone(),
|
||||
formats_locale: loc,
|
||||
})
|
||||
};
|
||||
self.k_config.clone()
|
||||
}
|
||||
|
||||
pub fn update(&mut self, message: Message) -> StageAction {
|
||||
match message {
|
||||
Message::SelectLangLocale(loc) => {
|
||||
self.lang_locale_text =
|
||||
format!("{}: {}", t!("locale.select_language_locale"), loc.code);
|
||||
self.lang_locale = Some(loc);
|
||||
StageAction::None
|
||||
}
|
||||
Message::SelectFormatsLocale(loc) => {
|
||||
self.all_locale_text =
|
||||
format!("{}: {}", t!("locale.select_formats_locale"), loc.code);
|
||||
self.formats_locale = Some(loc);
|
||||
StageAction::None
|
||||
}
|
||||
Message::Back => StageAction::Back,
|
||||
Message::Next => StageAction::Next(self.gen_result()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn view(&self) -> iced::Element<'_, Message> {
|
||||
let next_button = widget::button(widget::text(t!("button.next"))).on_press(Message::Next);
|
||||
let back_button = widget::button(widget::text(t!("button.back"))).on_press(Message::Back);
|
||||
|
||||
// Embed the image bytes into the executable
|
||||
let welcome_logo_handle = widget::image::Handle::from_bytes(kira_theming::get_logo_bytes());
|
||||
|
||||
widget::column![
|
||||
widget::container(
|
||||
widget::column![
|
||||
widget::image(welcome_logo_handle)
|
||||
.width(iced::Pixels(128.0))
|
||||
.height(iced::Pixels(128.0)),
|
||||
widget::container(
|
||||
widget::column![
|
||||
widget::text(self.lang_locale_text.as_str()),
|
||||
widget::pick_list(
|
||||
self.locales.clone(),
|
||||
self.lang_locale.clone(),
|
||||
Message::SelectLangLocale,
|
||||
)
|
||||
]
|
||||
.spacing(5)
|
||||
)
|
||||
.style(widget::container::bordered_box)
|
||||
.padding(5),
|
||||
widget::container(
|
||||
widget::column![
|
||||
widget::text(self.all_locale_text.as_str()),
|
||||
widget::pick_list(
|
||||
self.locales.clone(),
|
||||
self.formats_locale.clone(),
|
||||
Message::SelectFormatsLocale,
|
||||
)
|
||||
]
|
||||
.spacing(5)
|
||||
)
|
||||
.style(widget::container::bordered_box)
|
||||
.padding(5)
|
||||
]
|
||||
.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::row![
|
||||
back_button,
|
||||
widget::space::horizontal(), // Pushes the right button to the far right
|
||||
next_button
|
||||
]
|
||||
.width(iced::Length::Fill)
|
||||
.align_y(Alignment::End)
|
||||
.padding(10),
|
||||
]
|
||||
.align_x(Alignment::Center)
|
||||
.spacing(10)
|
||||
.into()
|
||||
}
|
||||
}
|
||||
+6
-1
@@ -18,4 +18,9 @@
|
||||
pub mod welcome;
|
||||
pub mod license;
|
||||
pub mod network;
|
||||
pub mod timezone;
|
||||
pub mod timezone;
|
||||
pub mod locale;
|
||||
pub mod keyboard;
|
||||
pub mod partition;
|
||||
pub mod security;
|
||||
pub mod install;
|
||||
+46
-53
@@ -20,17 +20,15 @@
|
||||
*/
|
||||
|
||||
use iced::{Alignment, Task, widget};
|
||||
use iced_moving_picture::widget::apng;
|
||||
use iced_moving_picture::widget::moving_picture;
|
||||
use log;
|
||||
use rust_i18n::t;
|
||||
use std::collections::HashMap;
|
||||
use toml::Table;
|
||||
|
||||
use crate::stage;
|
||||
use crate::stage::StageResult;
|
||||
use crate::stage::{self, KiraConfig};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
const REQIRE_NETWORK: bool = false;
|
||||
|
||||
#[derive(PartialEq, Eq)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum State {
|
||||
Cheking,
|
||||
Normal,
|
||||
@@ -43,14 +41,21 @@ pub enum CheckResult {
|
||||
CheckError,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct NetworkStageResult {
|
||||
pub internet_active: bool,
|
||||
pub use_net_settings: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct NetworkStage {
|
||||
internet_active: bool,
|
||||
state: State,
|
||||
use_net_settings: bool,
|
||||
reqire_network: bool,
|
||||
spinner_frames: apng::Frames,
|
||||
spinner_frames: moving_picture::Frames,
|
||||
logo_handle: widget::image::Handle,
|
||||
status_message: String,
|
||||
k_config: KiraConfig,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@@ -71,7 +76,7 @@ pub enum UpdateResult {
|
||||
fn check_connection_blocking() -> CheckResult {
|
||||
use std::process::Command;
|
||||
|
||||
std::thread::sleep(std::time::Duration::from_secs(1));
|
||||
std::thread::sleep(std::time::Duration::from_millis(500));
|
||||
|
||||
match Command::new("nm-online").arg("-q").status() {
|
||||
Ok(status) => {
|
||||
@@ -82,7 +87,7 @@ fn check_connection_blocking() -> CheckResult {
|
||||
}
|
||||
}
|
||||
Err(ex) => {
|
||||
println!("Exception while trying to chen net connectivity: {}", ex);
|
||||
log::error!("Exception while trying to chen net connectivity: {}", ex);
|
||||
CheckResult::CheckError
|
||||
}
|
||||
}
|
||||
@@ -95,50 +100,30 @@ async fn check_connected() -> CheckResult {
|
||||
}
|
||||
|
||||
impl NetworkStage {
|
||||
pub fn new(toml_config: &Table) -> Self {
|
||||
let mut reqire_network = false;
|
||||
|
||||
if let Some(reqire_network_conf) = toml_config
|
||||
.get("network")
|
||||
.and_then(|v| v.as_table())
|
||||
.and_then(|v| v.get("reqire_network"))
|
||||
.and_then(|v| v.as_bool())
|
||||
{
|
||||
println!("Config value reqire_network read {}", reqire_network_conf);
|
||||
reqire_network = reqire_network_conf;
|
||||
} else {
|
||||
println!("Error parsing network config. Using default values.");
|
||||
}
|
||||
|
||||
pub fn new(k_config: KiraConfig) -> Self {
|
||||
let spinner_frames =
|
||||
apng::Frames::from_bytes(crate::theme::get_spiner_bytes()).unwrap();
|
||||
moving_picture::Frames::from_bytes(crate::kira_theming::get_spiner_bytes(), moving_picture::Kind::Apng).unwrap();
|
||||
|
||||
let logo_handle = widget::image::Handle::from_bytes(crate::kira_theming::get_logo_bytes());
|
||||
|
||||
Self {
|
||||
logo_handle: logo_handle,
|
||||
internet_active: false,
|
||||
state: State::Cheking,
|
||||
use_net_settings: false,
|
||||
reqire_network: reqire_network,
|
||||
use_net_settings: true,
|
||||
spinner_frames: spinner_frames,
|
||||
status_message: t!("network.checking").into(),
|
||||
k_config: k_config,
|
||||
}
|
||||
}
|
||||
|
||||
fn gen_result(&self) -> StageResult {
|
||||
StageResult {
|
||||
name: "network".into(),
|
||||
config: Some(HashMap::from([
|
||||
(
|
||||
"internet_active".to_string(),
|
||||
stage::ConfigValue::Bool(self.internet_active),
|
||||
),
|
||||
(
|
||||
"use_net_settings".to_string(),
|
||||
stage::ConfigValue::Bool(self.use_net_settings),
|
||||
),
|
||||
])),
|
||||
resuts: None,
|
||||
error: None,
|
||||
}
|
||||
fn gen_result(&self) -> KiraConfig {
|
||||
let mut k_config = self.k_config.clone();
|
||||
k_config.res_network = Some(NetworkStageResult {
|
||||
internet_active: self.internet_active,
|
||||
use_net_settings: self.use_net_settings,
|
||||
});
|
||||
k_config
|
||||
}
|
||||
|
||||
pub fn update(&mut self, message: Message) -> UpdateResult {
|
||||
@@ -178,12 +163,12 @@ impl NetworkStage {
|
||||
}
|
||||
|
||||
pub fn view(&self) -> iced::Element<'_, Message> {
|
||||
let next_button = if (self.state == State::Cheking) || (!self.internet_active && self.reqire_network) {
|
||||
widget::button(widget::text(t!("button.next")))
|
||||
}
|
||||
else {
|
||||
widget::button(widget::text(t!("button.next"))).on_press(Message::Next)
|
||||
};
|
||||
let next_button =
|
||||
if (self.state == State::Cheking) || (!self.internet_active && REQIRE_NETWORK) {
|
||||
widget::button(widget::text(t!("button.next")))
|
||||
} else {
|
||||
widget::button(widget::text(t!("button.next"))).on_press(Message::Next)
|
||||
};
|
||||
|
||||
let (back_button, check_button, reuse_checkbox) = match self.state {
|
||||
State::Cheking => (
|
||||
@@ -202,8 +187,16 @@ impl NetworkStage {
|
||||
};
|
||||
|
||||
let spinner_container = match self.state {
|
||||
State::Cheking => widget::container(apng(&self.spinner_frames)),
|
||||
State::Normal => widget::container(widget::space().height(128).width(128)),
|
||||
State::Cheking => widget::container(
|
||||
moving_picture(&self.spinner_frames)
|
||||
.width(iced::Pixels(128.0).into())
|
||||
.height(iced::Pixels(128.0).into()),
|
||||
),
|
||||
State::Normal => widget::container(
|
||||
widget::image(&self.logo_handle)
|
||||
.width(iced::Pixels(128.0))
|
||||
.height(iced::Pixels(128.0)),
|
||||
),
|
||||
};
|
||||
|
||||
let info_column = widget::column![
|
||||
|
||||
@@ -0,0 +1,440 @@
|
||||
// <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/>.
|
||||
|
||||
/*
|
||||
This is partition stage!
|
||||
*/
|
||||
|
||||
use std::char;
|
||||
|
||||
use crate::kira_color_bar;
|
||||
use crate::kira_disk_layout::{BlkDev, FSType, PartInfo, PartLayout};
|
||||
use crate::kira_size::KiraSize;
|
||||
use crate::kira_sysinfo;
|
||||
use crate::stage::{KiraConfig, StageAction};
|
||||
use iced::{Alignment, Color, Element, Length, widget};
|
||||
use log;
|
||||
use rust_i18n::t;
|
||||
|
||||
const MIN_DISK_SIZE_MB: u64 = 8192;
|
||||
const EFI_SIZE_MB: u64 = 128;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum SwapMode {
|
||||
NoSwap,
|
||||
SwapNoHibernate,
|
||||
SwapHibernate,
|
||||
SwapCustom,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for SwapMode {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::NoSwap => f.write_str(t!("partition.no_swap").as_ref()),
|
||||
Self::SwapNoHibernate => f.write_str(t!("partition.swap_no_hibernate").as_ref()),
|
||||
Self::SwapHibernate => f.write_str(t!("partition.swap_hibernate").as_ref()),
|
||||
Self::SwapCustom => f.write_str(t!("partition.swap_custom").as_ref()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const SWAP_MODES: [SwapMode; 4] = [
|
||||
SwapMode::NoSwap,
|
||||
SwapMode::SwapNoHibernate,
|
||||
SwapMode::SwapHibernate,
|
||||
SwapMode::SwapCustom,
|
||||
];
|
||||
|
||||
fn part_type_to_color(t: &FSType) -> Color {
|
||||
match t {
|
||||
FSType::VFAT => Color::from_rgb8(204, 121, 167),
|
||||
FSType::XFS => Color::from_rgb8(0, 158, 115),
|
||||
FSType::LUKS => Color::from_rgb8(240, 228, 66),
|
||||
FSType::SWAP => Color::from_rgb8(213, 94, 0),
|
||||
FSType::EXT4 => Color::from_rgb8(0, 114, 178),
|
||||
FSType::BTRFS => Color::from_rgb8(86, 180, 233),
|
||||
_ => Color::from_rgb8(230, 159, 0),
|
||||
}
|
||||
}
|
||||
|
||||
/// 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);
|
||||
let part_color = part_type_to_color(&part.fs_type);
|
||||
(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,
|
||||
k_config: KiraConfig,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Message {
|
||||
SelectDevice(BlkDev),
|
||||
SelectSwapMode(SwapMode),
|
||||
ToggleZram(bool),
|
||||
ToggleSecureBoot(bool),
|
||||
ToggleEncrypDrive(bool),
|
||||
SwapSizeFieldChange(String),
|
||||
SwapSizeIncrement,
|
||||
SwapSizeDecrement,
|
||||
Next,
|
||||
Back,
|
||||
}
|
||||
|
||||
impl PartitionStage {
|
||||
pub fn new(k_config: KiraConfig) -> Result<Self, String> {
|
||||
let maybe_dev_list = BlkDev::list_sys_blk_dev();
|
||||
log::info!("hiii from partition");
|
||||
|
||||
let min_disk_size: KiraSize = KiraSize::new_mb(MIN_DISK_SIZE_MB);
|
||||
let efi_size: KiraSize = KiraSize::new_mb(EFI_SIZE_MB);
|
||||
|
||||
let sec_boot_setup = match kira_sysinfo::get_secure_boot_status() {
|
||||
Ok(sb_status) => sb_status.setup_mode,
|
||||
Err(ex) => {
|
||||
log::error!("Unable to get secure boot status! {}", ex);
|
||||
false
|
||||
}
|
||||
};
|
||||
match maybe_dev_list {
|
||||
Ok(dev_list) => {
|
||||
let acepted_dev: Vec<BlkDev> = dev_list
|
||||
.iter()
|
||||
.filter(|v| v.size.b() >= min_disk_size.b())
|
||||
.cloned()
|
||||
.collect();
|
||||
|
||||
// getting system memory info
|
||||
let system_ram_size = KiraSize::new_kb(kira_sysinfo::get_meminfo()["MemTotal"]); // from kB to bytes
|
||||
let vram_of_all_gpus_size = KiraSize::new_b(
|
||||
kira_sysinfo::get_gpus_list()
|
||||
.iter()
|
||||
.fold(0u64, |acc, gpi| acc + gpi.vis_vram_total),
|
||||
);
|
||||
|
||||
log::debug!(
|
||||
"stage init ram {} vram {}",
|
||||
system_ram_size,
|
||||
vram_of_all_gpus_size
|
||||
);
|
||||
Ok(Self {
|
||||
device: None,
|
||||
devices: acepted_dev,
|
||||
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,
|
||||
k_config: k_config,
|
||||
})
|
||||
}
|
||||
Err(ex) => Err(ex),
|
||||
}
|
||||
}
|
||||
|
||||
fn get_swap_size(&self) -> KiraSize {
|
||||
if let Some(s_mode) = self.swap_mode
|
||||
&& s_mode == SwapMode::SwapCustom
|
||||
{
|
||||
return KiraSize::new_mb(self.custom_swap_size_mb as u64);
|
||||
}
|
||||
|
||||
let total_ram = self.system_ram_size + self.vram_of_all_gpus_size;
|
||||
|
||||
let sys_ram_gb = self.system_ram_size.gb();
|
||||
log::debug!("sys_ram_gb {}", sys_ram_gb);
|
||||
let mut disk_swap_gb = if sys_ram_gb >= 32 {
|
||||
1u64
|
||||
} else if sys_ram_gb >= 24 {
|
||||
2u64
|
||||
} else if sys_ram_gb >= 16 {
|
||||
sys_ram_gb / 2
|
||||
} else if sys_ram_gb >= 8 {
|
||||
sys_ram_gb
|
||||
} else {
|
||||
sys_ram_gb * 2
|
||||
};
|
||||
|
||||
if self.use_zram {
|
||||
disk_swap_gb = disk_swap_gb.saturating_sub(sys_ram_gb).max(2);
|
||||
}
|
||||
let disk_swap = KiraSize::new_gb(disk_swap_gb);
|
||||
|
||||
match self.swap_mode {
|
||||
Some(SwapMode::NoSwap) => KiraSize::new_b(0),
|
||||
Some(SwapMode::SwapHibernate) => disk_swap + total_ram,
|
||||
Some(SwapMode::SwapNoHibernate) => disk_swap,
|
||||
_ => KiraSize::new_gb(2),
|
||||
}
|
||||
}
|
||||
|
||||
fn gen_layout(&mut self) {
|
||||
if let Some(dev) = self.device.clone() {
|
||||
let swap_size: KiraSize = self.get_swap_size();
|
||||
let patr_layout = PartLayout::gen_kira_layout(
|
||||
dev.clone(),
|
||||
self.efi_size,
|
||||
swap_size,
|
||||
None,
|
||||
Some("lz4".into()),
|
||||
);
|
||||
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(&mut self) -> KiraConfig {
|
||||
let disk_layout = self
|
||||
.generated_part_layout
|
||||
.clone()
|
||||
.expect("Layout must be generated!");
|
||||
|
||||
self.k_config.res_partition = Some(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,
|
||||
});
|
||||
|
||||
self.k_config.clone()
|
||||
}
|
||||
|
||||
pub fn update(&mut self, message: Message) -> StageAction {
|
||||
match message {
|
||||
Message::SelectDevice(dev) => {
|
||||
self.selected_disk_parts = match PartLayout::read_from_disk(&dev) {
|
||||
Ok(dev_parts) => Some(
|
||||
dev_parts
|
||||
.part_list
|
||||
.iter()
|
||||
.map(|part_inf| part_to_ct_params(&part_inf, dev.size))
|
||||
.collect(),
|
||||
),
|
||||
Err(ex) => {
|
||||
log::error!("Error getting dev partitions info: {}", ex);
|
||||
None
|
||||
}
|
||||
};
|
||||
|
||||
// let swap_size: KiraSize = self.get_swap_size();
|
||||
|
||||
// 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) => {
|
||||
self.swap_mode = Some(sm);
|
||||
self.gen_layout();
|
||||
StageAction::None
|
||||
}
|
||||
Message::ToggleSecureBoot(t) => {
|
||||
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();
|
||||
StageAction::None
|
||||
}
|
||||
Message::SwapSizeIncrement => {
|
||||
self.custom_swap_size_mb = (self.custom_swap_size_mb / 1024u32)
|
||||
.strict_mul(1024u32)
|
||||
.saturating_add(1024u32);
|
||||
self.custom_swap_size_str = format!("{}MB", self.custom_swap_size_mb);
|
||||
self.gen_layout();
|
||||
StageAction::None
|
||||
}
|
||||
Message::SwapSizeDecrement => {
|
||||
self.custom_swap_size_mb = (self.custom_swap_size_mb / 1024u32)
|
||||
.strict_mul(1024u32)
|
||||
.saturating_sub(1024u32);
|
||||
self.custom_swap_size_str = format!("{}MB", self.custom_swap_size_mb);
|
||||
self.gen_layout();
|
||||
StageAction::None
|
||||
}
|
||||
Message::SwapSizeFieldChange(f_v) => {
|
||||
let mut only_num = f_v.trim().to_string();
|
||||
only_num.retain(char::is_numeric);
|
||||
self.custom_swap_size_mb = u32::from_str_radix(&only_num, 10).unwrap_or(1024);
|
||||
self.custom_swap_size_str = format!("{}MB", self.custom_swap_size_mb);
|
||||
self.gen_layout();
|
||||
StageAction::None
|
||||
}
|
||||
Message::Back => StageAction::Back,
|
||||
Message::Next => StageAction::Next(self.gen_result()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn view(&self) -> iced::Element<'_, Message> {
|
||||
let swap_size_select: Element<'_, _> = match self.swap_mode {
|
||||
Some(SwapMode::SwapCustom) => widget::row![
|
||||
widget::text_input("", &self.custom_swap_size_str)
|
||||
.width(100)
|
||||
.on_input(Message::SwapSizeFieldChange),
|
||||
widget::button("+").on_press(Message::SwapSizeIncrement),
|
||||
widget::button("-").on_press(Message::SwapSizeDecrement),
|
||||
]
|
||||
.spacing(2)
|
||||
.into(),
|
||||
_ => widget::space().into(),
|
||||
};
|
||||
|
||||
let dev_parts_text = match self.generated_disk_parts {
|
||||
Some(_) => widget::text(t!("partition.current_after_install")),
|
||||
None => widget::text(""),
|
||||
};
|
||||
let dev_parts_content = kira_color_bar::color_bar(self.generated_disk_parts.clone(), 64);
|
||||
let dev_parts_content = widget::column![dev_parts_text, dev_parts_content];
|
||||
|
||||
let back_button = widget::button(widget::text(t!("button.back"))).on_press(Message::Back);
|
||||
let next_button = if self.device.is_some() {
|
||||
widget::button(widget::text(t!("button.next"))).on_press(Message::Next)
|
||||
} else {
|
||||
widget::button(widget::text(t!("button.next")))
|
||||
};
|
||||
|
||||
let selected_dev_text = match self.selected_disk_parts {
|
||||
Some(_) => widget::text(t!("partition.current_dev_layout")),
|
||||
None => widget::text(""),
|
||||
};
|
||||
let selected_dev_content = kira_color_bar::color_bar(self.selected_disk_parts.clone(), 64);
|
||||
let selected_dev_content = widget::column![selected_dev_text, selected_dev_content];
|
||||
|
||||
let use_sec_boot_checkbox = if self.secure_boot_in_setup_mode {
|
||||
widget::checkbox(self.secure_boot)
|
||||
.label(t!("partition.use_secure_boot"))
|
||||
.on_toggle(Message::ToggleSecureBoot)
|
||||
} else {
|
||||
widget::checkbox(self.secure_boot).label(t!("partition.use_secure_boot"))
|
||||
};
|
||||
|
||||
widget::column![
|
||||
widget::container(
|
||||
widget::column![
|
||||
widget::rule::horizontal(2),
|
||||
widget::text(t!("partition.select_device")),
|
||||
widget::pick_list(
|
||||
self.devices.clone(),
|
||||
self.device.clone(),
|
||||
Message::SelectDevice,
|
||||
)
|
||||
.placeholder(t!("partition.select_device_placeholder")),
|
||||
widget::rule::horizontal(2),
|
||||
widget::text(t!("partition.select_swapmode")),
|
||||
widget::row![
|
||||
widget::pick_list(SWAP_MODES, self.swap_mode, Message::SelectSwapMode,)
|
||||
.placeholder(t!("partition.select_swapmode_placeholder")),
|
||||
swap_size_select
|
||||
]
|
||||
.spacing(5)
|
||||
.width(Length::Shrink)
|
||||
.align_y(Alignment::Center),
|
||||
widget::checkbox(self.use_zram)
|
||||
.label(t!("partition.use_zram"))
|
||||
.on_toggle(Message::ToggleZram),
|
||||
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,
|
||||
]
|
||||
.padding(10)
|
||||
.spacing(10)
|
||||
.align_x(Alignment::Start)
|
||||
)
|
||||
.height(iced::Length::Fill)
|
||||
.width(iced::Length::Fill)
|
||||
.align_x(Alignment::Start)
|
||||
.align_y(Alignment::Center),
|
||||
widget::row![
|
||||
back_button,
|
||||
widget::space::horizontal(), // Pushes the right button to the far right
|
||||
next_button
|
||||
]
|
||||
.width(iced::Length::Fill)
|
||||
.align_y(Alignment::End)
|
||||
.padding(10),
|
||||
]
|
||||
.align_x(Alignment::Center)
|
||||
.spacing(10)
|
||||
.into()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,301 @@
|
||||
// <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/>.
|
||||
|
||||
/*
|
||||
This is Security stage, setup users logins and such
|
||||
*/
|
||||
|
||||
use crate::stage::{KiraConfig, StageAction};
|
||||
use iced::{Alignment, Color, widget};
|
||||
use rust_i18n::t;
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
enum PasswordStrenght {
|
||||
Low,
|
||||
Middle,
|
||||
Hight,
|
||||
}
|
||||
|
||||
impl PasswordStrenght {
|
||||
pub fn from_password(password: &str) -> Self {
|
||||
if password.len() < 8 {
|
||||
Self::Low
|
||||
} else if password.len() < 16 {
|
||||
Self::Middle
|
||||
} else {
|
||||
Self::Hight
|
||||
}
|
||||
}
|
||||
pub fn color(&self) -> Color {
|
||||
match self {
|
||||
Self::Low => Color::from_rgb8(212, 32, 32),
|
||||
Self::Middle => Color::from_rgb8(212, 212, 32),
|
||||
Self::Hight => Color::from_rgb8(32, 212, 32),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for PasswordStrenght {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::Low => f.write_str(t!("security.pass_low").as_ref()),
|
||||
Self::Middle => f.write_str(t!("security.pass_middle").as_ref()),
|
||||
Self::Hight => f.write_str(t!("security.pass_hight").as_ref()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct SecurityStage {
|
||||
user_name: String,
|
||||
user_full_name: String,
|
||||
user_password: String,
|
||||
root_password: String,
|
||||
reuse_user_password_for_roor: bool,
|
||||
user_pass_is_secure: bool,
|
||||
root_pass_is_secure: bool,
|
||||
user_password_strenght: PasswordStrenght,
|
||||
root_password_strenght: PasswordStrenght,
|
||||
k_config: KiraConfig,
|
||||
}
|
||||
|
||||
#[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),
|
||||
UserNameChange(String),
|
||||
UserFullNameChange(String),
|
||||
UserPasswordChange(String),
|
||||
RootPasswordChange(String),
|
||||
ToggleUserPassSecure,
|
||||
ToggleRootPassSecure,
|
||||
Next,
|
||||
Back,
|
||||
}
|
||||
|
||||
/// Mothod safely retain first n chars in utf-8 string avoiding cutting utf-8 char in the middle
|
||||
fn retain_first_n(s: &str, n: usize) -> &str {
|
||||
s.char_indices()
|
||||
.nth(n)
|
||||
.and_then(|(idx, _)| Some(&s[..idx]))
|
||||
.unwrap_or(s)
|
||||
}
|
||||
|
||||
impl SecurityStage {
|
||||
pub fn new(k_config: KiraConfig) -> Self {
|
||||
Self {
|
||||
user_name: "".into(),
|
||||
user_full_name: "".into(),
|
||||
user_password: "".into(),
|
||||
root_password: "".into(),
|
||||
reuse_user_password_for_roor: false,
|
||||
user_pass_is_secure: true,
|
||||
root_pass_is_secure: true,
|
||||
user_password_strenght: PasswordStrenght::Low,
|
||||
root_password_strenght: PasswordStrenght::Low,
|
||||
k_config: k_config,
|
||||
}
|
||||
}
|
||||
|
||||
fn gen_result(&mut self) -> KiraConfig {
|
||||
self.k_config.res_security = Some(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(),
|
||||
});
|
||||
self.k_config.clone()
|
||||
}
|
||||
|
||||
pub fn update(&mut self, message: Message) -> StageAction {
|
||||
match message {
|
||||
Message::ToggleReusePass(reuse_pass) => {
|
||||
self.reuse_user_password_for_roor = reuse_pass;
|
||||
if reuse_pass {
|
||||
self.root_password = self.user_password.clone();
|
||||
}
|
||||
StageAction::None
|
||||
}
|
||||
Message::UserNameChange(u_name) => {
|
||||
let mut trimmed = u_name
|
||||
.trim_start_matches(|c: char| !c.is_ascii_alphabetic())
|
||||
.to_string();
|
||||
trimmed.retain(|c| c.is_ascii_alphanumeric() || c == '-');
|
||||
trimmed.truncate(30); // it is safe bacuse we retained only ascii characters
|
||||
self.user_name = trimmed;
|
||||
StageAction::None
|
||||
}
|
||||
Message::UserFullNameChange(f_name) => {
|
||||
let mut res = f_name.clone();
|
||||
res.retain(|c| c.is_alphanumeric() || ['_', '-', ' ', '.', ','].contains(&c));
|
||||
self.user_full_name = retain_first_n(&res, 128).to_string();
|
||||
StageAction::None
|
||||
}
|
||||
Message::UserPasswordChange(u_pass) => {
|
||||
let mut res = u_pass;
|
||||
res.retain(|c: char| !c.is_control());
|
||||
self.user_password = res;
|
||||
self.user_password_strenght = PasswordStrenght::from_password(&self.user_password);
|
||||
if self.reuse_user_password_for_roor {
|
||||
self.root_password_strenght = self.user_password_strenght;
|
||||
self.root_password = self.user_password.clone();
|
||||
}
|
||||
StageAction::None
|
||||
}
|
||||
Message::RootPasswordChange(r_pass) => {
|
||||
let mut res: String = r_pass;
|
||||
res.retain(|c: char| !c.is_control());
|
||||
self.root_password = res;
|
||||
self.root_password_strenght = PasswordStrenght::from_password(&self.root_password);
|
||||
StageAction::None
|
||||
}
|
||||
Message::ToggleUserPassSecure => {
|
||||
self.user_pass_is_secure = !self.user_pass_is_secure;
|
||||
StageAction::None
|
||||
}
|
||||
Message::ToggleRootPassSecure => {
|
||||
self.root_pass_is_secure = !self.root_pass_is_secure;
|
||||
StageAction::None
|
||||
}
|
||||
Message::Back => StageAction::Back,
|
||||
Message::Next => StageAction::Next(self.gen_result()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn view(&self) -> iced::Element<'_, Message> {
|
||||
let back_button = widget::button(widget::text(t!("button.back"))).on_press(Message::Back);
|
||||
let next_button = if self.user_name.is_empty()
|
||||
|| self.user_password.is_empty()
|
||||
|| self.root_password.is_empty()
|
||||
{
|
||||
widget::button(widget::text(t!("button.next")))
|
||||
} else {
|
||||
widget::button(widget::text(t!("button.next"))).on_press(Message::Next)
|
||||
};
|
||||
|
||||
let user_pass_sec_text = if self.user_pass_is_secure {
|
||||
widget::text("👁")
|
||||
} else {
|
||||
widget::text("*")
|
||||
};
|
||||
let root_pass_sec_text = if self.root_pass_is_secure {
|
||||
widget::text("👁")
|
||||
} else {
|
||||
widget::text("*")
|
||||
};
|
||||
let user_pass_sec_text = user_pass_sec_text
|
||||
.width(12)
|
||||
.align_x(Alignment::Center)
|
||||
.align_y(Alignment::Center);
|
||||
let root_pass_sec_text = root_pass_sec_text
|
||||
.width(12)
|
||||
.align_x(Alignment::Center)
|
||||
.align_y(Alignment::Center);
|
||||
let mut root_pass_input =
|
||||
widget::text_input("", &self.root_password).secure(self.root_pass_is_secure);
|
||||
if !self.reuse_user_password_for_roor {
|
||||
root_pass_input = root_pass_input.on_input(Message::RootPasswordChange);
|
||||
}
|
||||
|
||||
let user_p_strenght_text = widget::text(self.user_password_strenght.to_string())
|
||||
.color(self.user_password_strenght.color());
|
||||
let root_p_strenght_text = widget::text(self.root_password_strenght.to_string())
|
||||
.color(self.root_password_strenght.color());
|
||||
|
||||
widget::column![
|
||||
widget::container(
|
||||
widget::column![
|
||||
widget::column![
|
||||
widget::text(t!("security.user_name")),
|
||||
widget::text_input("", &self.user_name)
|
||||
.width(256)
|
||||
.on_input(Message::UserNameChange)
|
||||
],
|
||||
widget::column![
|
||||
widget::text(t!("security.user_full_name")),
|
||||
widget::text_input("", &self.user_full_name)
|
||||
.width(256)
|
||||
.on_input(Message::UserFullNameChange)
|
||||
],
|
||||
widget::column![
|
||||
widget::text(t!("security.user_password")),
|
||||
widget::row![
|
||||
widget::text_input("", &self.user_password)
|
||||
.width(512)
|
||||
.on_input(Message::UserPasswordChange)
|
||||
.secure(self.user_pass_is_secure),
|
||||
widget::button(user_pass_sec_text)
|
||||
.on_press(Message::ToggleUserPassSecure),
|
||||
widget::container(user_p_strenght_text)
|
||||
.align_x(Alignment::Center)
|
||||
.style(widget::container::bordered_box)
|
||||
.style(widget::container::rounded_box)
|
||||
.padding(6)
|
||||
.width(160),
|
||||
]
|
||||
.spacing(5)
|
||||
.align_y(Alignment::Center)
|
||||
],
|
||||
widget::rule::horizontal(2),
|
||||
widget::column![
|
||||
widget::text(t!("security.root_password")),
|
||||
widget::row![
|
||||
root_pass_input.width(512),
|
||||
widget::button(root_pass_sec_text)
|
||||
.on_press(Message::ToggleRootPassSecure),
|
||||
widget::container(root_p_strenght_text)
|
||||
.align_x(Alignment::Center)
|
||||
.style(widget::container::rounded_box)
|
||||
.style(widget::container::bordered_box)
|
||||
.padding(6)
|
||||
.width(160),
|
||||
]
|
||||
.spacing(5)
|
||||
.align_y(Alignment::Center),
|
||||
widget::checkbox(self.reuse_user_password_for_roor)
|
||||
.label(t!("security.reuse_user_password"))
|
||||
.on_toggle(Message::ToggleReusePass),
|
||||
],
|
||||
]
|
||||
.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::row![
|
||||
back_button,
|
||||
widget::space::horizontal(), // Pushes the right button to the far right
|
||||
next_button,
|
||||
]
|
||||
.width(iced::Length::Fill)
|
||||
.align_y(Alignment::End)
|
||||
.padding(10),
|
||||
]
|
||||
.align_x(Alignment::Center)
|
||||
.spacing(10)
|
||||
.into()
|
||||
}
|
||||
}
|
||||
+103
-125
@@ -15,163 +15,136 @@
|
||||
// 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
|
||||
This is TimeZone stage, used to select timezone
|
||||
*/
|
||||
|
||||
use crate::stage::{ConfigValue, StageAction, StageResult};
|
||||
use crate::stage::{KiraConfig, StageAction};
|
||||
use iced::{Alignment, Length, widget};
|
||||
use log;
|
||||
use rust_i18n::t;
|
||||
use std::collections::HashMap;
|
||||
|
||||
mod scroll_list;
|
||||
use crate::kira_scroll_list;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct TimeZoneData {
|
||||
region: String,
|
||||
zone: String,
|
||||
}
|
||||
|
||||
impl TimeZoneData {
|
||||
|
||||
fn to_full_code(&self) -> String {
|
||||
format!("{}/{}", self.region, self.zone)
|
||||
}
|
||||
fn from_str(s: &str) -> Option<Self> {
|
||||
let idx = s.find('/')?;
|
||||
let (region, zone) = s.split_at(idx);
|
||||
Some(Self {
|
||||
region: region.into(),
|
||||
zone: zone.trim_start_matches('/').into(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for TimeZoneData {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{}", self.zone)
|
||||
}
|
||||
}
|
||||
use crate::kira_locales::{TimeZoneData, get_timezones_blocking};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct TimeZoneStage {
|
||||
time_zones: Result<HashMap<String, Vec<TimeZoneData>>, String>,
|
||||
time_zones: Result<HashMap<String, Vec<String>>, String>,
|
||||
regions: Vec<String>,
|
||||
region_id: Option<usize>,
|
||||
zones: Vec<TimeZoneData>,
|
||||
zones: Vec<String>,
|
||||
zone_id: Option<usize>,
|
||||
selected_zone: Option<TimeZoneData>,
|
||||
selected_zone_text: String,
|
||||
k_config: KiraConfig,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct TimeZoneStageResult {
|
||||
pub time_zone: TimeZoneData,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Message {
|
||||
SelectRegion(scroll_list::ListViewMessage),
|
||||
SelectZone(scroll_list::ListViewMessage),
|
||||
SelectRegion(kira_scroll_list::ListViewMessage),
|
||||
SelectZone(kira_scroll_list::ListViewMessage),
|
||||
Next,
|
||||
Back,
|
||||
}
|
||||
|
||||
/// Getting list of awailable timezones from system.
|
||||
fn get_timezones_blocking() -> Result<Vec<TimeZoneData>, String> {
|
||||
use std::process::Command;
|
||||
//timedatectl list-timezones --no-pager
|
||||
match Command::new("timedatectl")
|
||||
.arg("list-timezones")
|
||||
.arg("--no-pager")
|
||||
.output()
|
||||
{
|
||||
Ok(cmd_output) => {
|
||||
if cmd_output.status.success() {
|
||||
//Etc/UTC
|
||||
match String::from_utf8(cmd_output.stdout) {
|
||||
Ok(str_tz_list) => Ok(str_tz_list
|
||||
.split("\n")
|
||||
.filter(|sb| sb.contains('/'))
|
||||
.filter_map(|str_t_zone| TimeZoneData::from_str(str_t_zone.trim()))
|
||||
.collect::<Vec<TimeZoneData>>()),
|
||||
Err(ex) => Err(format!("Exception while converting to UTF8 {}", ex)),
|
||||
}
|
||||
} else {
|
||||
Err(format!(
|
||||
"Error getting timezones list: {}",
|
||||
String::from_utf8(cmd_output.stderr).unwrap_or("UNKNOWN".into())
|
||||
))
|
||||
}
|
||||
}
|
||||
Err(ex) => Err(format!("Exception while trying to list time zones {}", ex)),
|
||||
}
|
||||
}
|
||||
// fn get_timezones_blocking_depr() -> Result<Vec<TimeZoneData>, String> {
|
||||
// use std::process::Command;
|
||||
// //timedatectl list-timezones --no-pager
|
||||
// match Command::new("timedatectl")
|
||||
// .arg("list-timezones")
|
||||
// .arg("--no-pager")
|
||||
// .output()
|
||||
// {
|
||||
// Ok(cmd_output) => {
|
||||
// if cmd_output.status.success() {
|
||||
// //Etc/UTC
|
||||
// match String::from_utf8(cmd_output.stdout) {
|
||||
// Ok(str_tz_list) => Ok(str_tz_list
|
||||
// .split("\n")
|
||||
// .filter(|sb| sb.contains('/'))
|
||||
// .filter_map(|str_t_zone| TimeZoneData::from_str(str_t_zone.trim()))
|
||||
// .collect::<Vec<TimeZoneData>>()),
|
||||
// Err(ex) => Err(format!("Exception while converting to UTF8 {}", ex)),
|
||||
// }
|
||||
// } else {
|
||||
// Err(format!(
|
||||
// "Error getting timezones list: {}",
|
||||
// String::from_utf8(cmd_output.stderr).unwrap_or("UNKNOWN".into())
|
||||
// ))
|
||||
// }
|
||||
// }
|
||||
// Err(ex) => Err(format!("Exception while trying to list time zones {}", ex)),
|
||||
// }
|
||||
// }
|
||||
|
||||
impl TimeZoneStage {
|
||||
pub fn new() -> Self {
|
||||
pub fn new(k_config: KiraConfig) -> Self {
|
||||
match get_timezones_blocking() {
|
||||
Ok(tzs) => {
|
||||
let mut time_zones: HashMap<String, Vec<TimeZoneData>> = HashMap::new();
|
||||
for tz in &tzs {
|
||||
if let Some(z) = time_zones.get_mut(tz.region.as_str()) {
|
||||
z.push(tz.clone());
|
||||
Ok(time_zones_data_list) => {
|
||||
let mut time_zones_map: HashMap<String, Vec<String>> = HashMap::new();
|
||||
for tz_data in &time_zones_data_list {
|
||||
if let Some(zones) = time_zones_map.get_mut(&tz_data.region) {
|
||||
zones.push(tz_data.zone.clone());
|
||||
} else {
|
||||
time_zones.insert(tz.region.clone(), vec![tz.clone()]);
|
||||
time_zones_map.insert(tz_data.region.clone(), vec![tz_data.zone.clone()]);
|
||||
}
|
||||
}
|
||||
//let time_zones: HashMap<String, TimeZoneData> = HashMap::from_iter(tzs.iter().map(|tz| (tz.region.clone(), tz.clone())));
|
||||
// sort zones alphabetically
|
||||
time_zones_map.values_mut().for_each(|v| v.sort());
|
||||
// sort region names alphabetically
|
||||
let mut regions: Vec<String> = time_zones_map.keys().cloned().collect();
|
||||
regions.sort();
|
||||
|
||||
Self {
|
||||
regions: time_zones.keys().cloned().collect(),
|
||||
zones: tzs.clone(),
|
||||
time_zones: Ok(time_zones),
|
||||
regions: regions,
|
||||
zones: Vec::new(),
|
||||
time_zones: Ok(time_zones_map),
|
||||
region_id: None,
|
||||
zone_id: None,
|
||||
selected_zone: None,
|
||||
selected_zone_text: String::new(),
|
||||
k_config: k_config,
|
||||
}
|
||||
}
|
||||
Err(ex) => {
|
||||
println!(
|
||||
log::error!(
|
||||
"Exception while trying to get time zones list from system {}",
|
||||
ex
|
||||
);
|
||||
Self {
|
||||
time_zones: Err(ex),
|
||||
time_zones: Err(ex.to_string()),
|
||||
regions: Vec::new(),
|
||||
zones: Vec::new(),
|
||||
region_id: None,
|
||||
zone_id: None,
|
||||
selected_zone: None,
|
||||
selected_zone_text: String::new(),
|
||||
k_config: k_config,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn gen_result(&self) -> StageResult {
|
||||
if let Some(tz_id) = self.zone_id {
|
||||
let time_zone = &self.zones[tz_id];
|
||||
StageResult {
|
||||
name: "time_zone".to_string(),
|
||||
config: Some(HashMap::from([
|
||||
(
|
||||
"name".to_string(),
|
||||
ConfigValue::String(time_zone.to_full_code()),
|
||||
),
|
||||
(
|
||||
"region".to_string(),
|
||||
ConfigValue::String(time_zone.region.clone()),
|
||||
),
|
||||
(
|
||||
"zone".to_string(),
|
||||
ConfigValue::String(time_zone.zone.clone()),
|
||||
),
|
||||
])),
|
||||
resuts: None,
|
||||
error: None,
|
||||
}
|
||||
} else {
|
||||
StageResult {
|
||||
name: "time_zone".to_string(),
|
||||
config: None,
|
||||
resuts: None,
|
||||
error: None,
|
||||
}
|
||||
}
|
||||
fn gen_result(&mut self) -> KiraConfig {
|
||||
self.k_config.res_timezone = Some(TimeZoneStageResult {
|
||||
time_zone: self
|
||||
.selected_zone
|
||||
.clone()
|
||||
.expect("Timezone must be selected!"),
|
||||
});
|
||||
self.k_config.clone()
|
||||
}
|
||||
|
||||
pub fn update(&mut self, message: Message) -> StageAction {
|
||||
match message {
|
||||
Message::SelectRegion(scroll_list::ListViewMessage::Select(region_id)) => {
|
||||
Message::SelectRegion(kira_scroll_list::ListViewMessage::Select(region_id)) => {
|
||||
let region = self.regions.get(region_id).unwrap();
|
||||
self.zones = self
|
||||
.time_zones
|
||||
@@ -181,10 +154,19 @@ impl TimeZoneStage {
|
||||
.unwrap()
|
||||
.clone();
|
||||
self.region_id = Some(region_id);
|
||||
self.zone_id = None;
|
||||
//self.selected_zone_text.clear();
|
||||
StageAction::None
|
||||
}
|
||||
Message::SelectZone(scroll_list::ListViewMessage::Select(zone_id)) => {
|
||||
Message::SelectZone(kira_scroll_list::ListViewMessage::Select(zone_id)) => {
|
||||
let zone = TimeZoneData {
|
||||
region: self.regions[self.region_id.unwrap()].clone(),
|
||||
zone: self.zones[zone_id].clone(),
|
||||
};
|
||||
self.selected_zone_text =
|
||||
format!("{} {}", t!("timezone.selected_timezone"), zone.to_string());
|
||||
self.zone_id = Some(zone_id);
|
||||
self.selected_zone = Some(zone);
|
||||
StageAction::None
|
||||
}
|
||||
Message::Next => StageAction::Next(self.gen_result()),
|
||||
@@ -199,32 +181,28 @@ impl TimeZoneStage {
|
||||
widget::button(widget::text(t!("button.next")))
|
||||
};
|
||||
let main_content = match &self.time_zones {
|
||||
Ok(_) => {
|
||||
let mut col = widget::column![
|
||||
Ok(_) => widget::container(
|
||||
widget::column![
|
||||
widget::text(t!("timezone.select_timezone")),
|
||||
widget::row![
|
||||
scroll_list::list_view(&self.regions, self.region_id, Length::Shrink)
|
||||
kira_scroll_list::list_view(&self.regions, self.region_id, Length::Shrink)
|
||||
.map(Message::SelectRegion),
|
||||
scroll_list::list_view(&self.zones, self.zone_id, Length::FillPortion(1))
|
||||
.map(Message::SelectZone),
|
||||
kira_scroll_list::list_view(
|
||||
&self.zones,
|
||||
self.zone_id,
|
||||
Length::FillPortion(1)
|
||||
)
|
||||
.map(Message::SelectZone),
|
||||
]
|
||||
.padding(20)
|
||||
.padding([0, 10])
|
||||
.spacing(10)
|
||||
.height(Length::Shrink)
|
||||
.height(Length::Shrink),
|
||||
widget::text(self.selected_zone_text.clone())
|
||||
]
|
||||
.spacing(10)
|
||||
.align_x(Alignment::Center);
|
||||
.align_x(Alignment::Center),
|
||||
),
|
||||
|
||||
if let Some(tz_id) = self.zone_id {
|
||||
col = col.push(widget::text(format!(
|
||||
"{} {}",
|
||||
t!("timezone.selected_timezone"),
|
||||
self.zones[tz_id].to_full_code()
|
||||
)))
|
||||
};
|
||||
|
||||
widget::container(col)
|
||||
}
|
||||
Err(_) => widget::container(widget::text(t!("timezone.init_error"))),
|
||||
};
|
||||
let back_button = widget::button(widget::text(t!("button.back"))).on_press(Message::Back);
|
||||
|
||||
@@ -1,110 +0,0 @@
|
||||
use std::fmt::Display;
|
||||
|
||||
use iced::widget::{Column, button, container, scrollable, text};
|
||||
use iced::{Alignment, Color, Element, Length, Theme};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum ListViewMessage {
|
||||
Select(usize),
|
||||
}
|
||||
|
||||
fn unselected_button_style(theme: &Theme, status: button::Status) -> button::Style {
|
||||
//let palette = theme.extended_palette();
|
||||
use iced::{Border, border::Radius};
|
||||
|
||||
match status {
|
||||
button::Status::Hovered => button::Style {
|
||||
border: Border {
|
||||
color: Color::from_rgb(0.8, 0.3, 0.3),
|
||||
width: 2.0,
|
||||
radius: Radius::new(5.0),
|
||||
},
|
||||
..button::primary(theme, status)
|
||||
},
|
||||
button::Status::Active => button::Style {
|
||||
background: Some(iced::Background::Color(crate::theme::change_lightnes(
|
||||
&theme.palette().primary,
|
||||
-0.1,
|
||||
))),
|
||||
..button::primary(theme, status)
|
||||
},
|
||||
_ => button::primary(theme, status),
|
||||
}
|
||||
}
|
||||
|
||||
fn selected_button_style(theme: &Theme, status: button::Status) -> button::Style {
|
||||
//let palette = theme.extended_palette();
|
||||
|
||||
match status {
|
||||
button::Status::Active => button::Style {
|
||||
background: Some(iced::Background::Color(Color::from_rgb(0.8, 0.3, 0.3))),
|
||||
..button::primary(theme, status)
|
||||
},
|
||||
_ => button::Style {
|
||||
background: Some(iced::Background::Color(Color::from_rgb(0.8, 0.3, 0.3))),
|
||||
..button::primary(theme, status)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// fn view() -> container::Style {
|
||||
// container::Style {
|
||||
// text_color: None,
|
||||
// background: None,
|
||||
// border: Border {
|
||||
// color: Color::BLACK,
|
||||
// width: 2.0,
|
||||
// radius: Radius::new(5.0),
|
||||
// },
|
||||
// shadow: None,
|
||||
// snap: false,
|
||||
// }
|
||||
// }
|
||||
|
||||
// fn border_style(theme: &Theme) -> container::Style {
|
||||
// use iced::{Border, border::Radius};
|
||||
|
||||
// container::Style {
|
||||
// border: Border {
|
||||
// color: Color::from_rgb(0.8, 0.3, 0.3),
|
||||
// width: 2.0,
|
||||
// radius: Radius::new(5.0),
|
||||
// },
|
||||
// ..container::bordered_box(theme)
|
||||
// }
|
||||
// }
|
||||
|
||||
// Assuming your Item struct or type implements Display or has a text representation
|
||||
pub fn list_view<T: Display>(
|
||||
items: &Vec<T>,
|
||||
selected_id: Option<usize>,
|
||||
container_height: Length,
|
||||
) -> Element<'_, ListViewMessage> {
|
||||
let mut column = Column::new()
|
||||
.spacing(2)
|
||||
.align_x(Alignment::Center)
|
||||
.width(Length::Fill);
|
||||
|
||||
for (index, value) in items.iter().enumerate() {
|
||||
// Create a row for each item, possibly with buttons or other controls
|
||||
let list_item = if let Some(id) = selected_id
|
||||
&& id == index
|
||||
{
|
||||
button(text(value.to_string())).style(selected_button_style)
|
||||
} else {
|
||||
button(text(value.to_string())).style(unselected_button_style)
|
||||
};
|
||||
let list_item = list_item
|
||||
.width(Length::Fill)
|
||||
.on_press(ListViewMessage::Select(index));
|
||||
|
||||
column = column.push(list_item);
|
||||
}
|
||||
|
||||
// Wrap the column in a scrollable widget
|
||||
container(scrollable(column).width(Length::Fill))
|
||||
.style(container::bordered_box)
|
||||
.height(container_height)
|
||||
.padding(8)
|
||||
.into()
|
||||
}
|
||||
+39
-59
@@ -1,29 +1,29 @@
|
||||
// <Kira Installer - universal Linux installer.>
|
||||
// Copyright (C) <2026> <Kira Foundation>
|
||||
// <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 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/>.
|
||||
// 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/>.
|
||||
|
||||
/*
|
||||
This is Welcome stage, used to greet used and allow user to choose program language
|
||||
*/
|
||||
This is Welcome stage, used to greet used and allow user to choose program language
|
||||
*/
|
||||
|
||||
|
||||
use crate::{stage::{ConfigValue, StageAction, StageResult}, theme};
|
||||
use crate::{
|
||||
kira_theming,
|
||||
stage::{KiraConfig, StageAction},
|
||||
};
|
||||
use iced::{Alignment, widget};
|
||||
use rust_i18n::t;
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct LocData {
|
||||
@@ -37,10 +37,17 @@ impl std::fmt::Display for LocData {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct WelcomeStageResult {
|
||||
pub loc_code: String,
|
||||
pub loc_name: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct WelcomeStage {
|
||||
locale: Option<LocData>,
|
||||
locales: Vec<LocData>,
|
||||
k_config: KiraConfig,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@@ -51,8 +58,7 @@ pub enum Message {
|
||||
}
|
||||
|
||||
impl WelcomeStage {
|
||||
pub fn new() -> Self {
|
||||
|
||||
pub fn new(k_config: KiraConfig) -> Self {
|
||||
Self {
|
||||
locale: Some(LocData {
|
||||
name: "English".into(),
|
||||
@@ -65,43 +71,23 @@ impl WelcomeStage {
|
||||
code: s.to_string(),
|
||||
})
|
||||
.collect(),
|
||||
k_config: k_config,
|
||||
}
|
||||
}
|
||||
|
||||
fn gen_result(&self) -> StageResult {
|
||||
if let Some(loc) = &self.locale {
|
||||
StageResult {
|
||||
name: "welcome".to_string(),
|
||||
config: Some(HashMap::from([
|
||||
(
|
||||
"loc_code".to_string(),
|
||||
ConfigValue::String(loc.code.clone()),
|
||||
),
|
||||
(
|
||||
"loc_name".to_string(),
|
||||
ConfigValue::String(loc.name.clone()),
|
||||
),
|
||||
])),
|
||||
resuts: None,
|
||||
error: None,
|
||||
fn gen_result(&mut self) -> KiraConfig {
|
||||
self.k_config.res_welcome = Some(if let Some(loc) = &self.locale {
|
||||
WelcomeStageResult {
|
||||
loc_code: loc.code.clone(),
|
||||
loc_name: loc.name.clone(),
|
||||
}
|
||||
} else {
|
||||
StageResult {
|
||||
name: "welcome".to_string(),
|
||||
config: Some(HashMap::from([
|
||||
(
|
||||
"loc_code".to_string(),
|
||||
ConfigValue::String("en".to_string()),
|
||||
),
|
||||
(
|
||||
"loc_name".to_string(),
|
||||
ConfigValue::String("English".to_string()),
|
||||
),
|
||||
])),
|
||||
resuts: None,
|
||||
error: None,
|
||||
WelcomeStageResult {
|
||||
loc_code: "en".to_string(),
|
||||
loc_name: "English".to_string(),
|
||||
}
|
||||
}
|
||||
});
|
||||
self.k_config.clone()
|
||||
}
|
||||
|
||||
pub fn update(&mut self, message: Message) -> StageAction {
|
||||
@@ -111,12 +97,7 @@ impl WelcomeStage {
|
||||
self.locale = Some(loc);
|
||||
StageAction::None
|
||||
}
|
||||
Message::Exit => StageAction::Abort(StageResult {
|
||||
name: "welcome".to_string(),
|
||||
config: None,
|
||||
resuts: None,
|
||||
error: None,
|
||||
}),
|
||||
Message::Exit => StageAction::Abort,
|
||||
Message::Next => StageAction::Next(self.gen_result()),
|
||||
}
|
||||
}
|
||||
@@ -126,8 +107,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(theme::get_logo_bytes());
|
||||
let welcom_logo_handle = widget::image::Handle::from_bytes(kira_theming::get_logo_bytes());
|
||||
|
||||
widget::column![
|
||||
widget::container(
|
||||
|
||||
+1167
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user