SHA256
Compare commits
23
Commits
c758c68f23
...
v0.1.4
| Author | SHA256 | Date | |
|---|---|---|---|
|
|
b90544bac5 | ||
|
|
62a9e244a6 | ||
|
|
32a1491537 | ||
|
|
56d181864a | ||
|
|
ba4cca635b | ||
|
|
92cb61dccc | ||
|
|
f15fa368ac | ||
|
|
70246f0d97 | ||
|
|
856a759315 | ||
|
|
4d01705527 | ||
|
|
e6a3425109 | ||
|
|
81a0f4f8a2 | ||
|
|
0b4291b97e | ||
|
|
f74461f6fb | ||
|
|
4396c5011b | ||
|
|
acdf923ce0 | ||
|
|
68c19d84cf | ||
|
|
33cabc86c9 | ||
|
|
379a992421 | ||
|
|
ab7ba83428 | ||
|
|
75c043b652 | ||
|
|
212fa7ed44 | ||
|
|
76a04b7d3e |
@@ -0,0 +1,43 @@
|
||||
name: "Build Release Binary"
|
||||
run-name: "Build Release: ${{ inputs.tag_name }}"
|
||||
|
||||
on:
|
||||
# Allows triggering from another workflow
|
||||
workflow_call:
|
||||
inputs:
|
||||
tag_name:
|
||||
description: 'Git tag to build (e.g., v1.0.0)'
|
||||
required: true
|
||||
type: string
|
||||
|
||||
workflow_dispatch: # Enables manual triggering
|
||||
inputs:
|
||||
tag_name:
|
||||
description: 'Git tag to build (e.g., v1.0.0)'
|
||||
required: true
|
||||
type: string
|
||||
|
||||
jobs:
|
||||
build-release:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
env:
|
||||
GIT_DEFAULT_HASH: sha256
|
||||
with:
|
||||
# If triggered manually, use the input tag.
|
||||
# If triggered by push, GITHUB_REF_NAME is the tag.
|
||||
ref: ${{ inputs.tag_name || gitea.ref_name }}
|
||||
|
||||
- name: Setup Rust toolchain
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
|
||||
- name: Build Release Binary
|
||||
run: cargo build --release
|
||||
|
||||
- name: Upload Artifact
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: nyanit-${{ inputs.tag_name || gitea.ref_name }}
|
||||
path: target/release/nyanit
|
||||
@@ -0,0 +1,40 @@
|
||||
name: Create Release with Binary
|
||||
|
||||
on:
|
||||
workflow_dispatch: # Enables manual triggering
|
||||
inputs:
|
||||
tag_name:
|
||||
description: 'Git tag to build (e.g., v1.0.0)'
|
||||
required: true
|
||||
type: string
|
||||
rel_description:
|
||||
description: 'Release description'
|
||||
required: false
|
||||
type: string
|
||||
|
||||
|
||||
jobs:
|
||||
# This job calls the reusable workflow
|
||||
build-binary:
|
||||
uses: ./.gitea/workflows/build-release-binary.yml
|
||||
with:
|
||||
tag_name: "${{ inputs.tag_name }}"
|
||||
|
||||
create-release:
|
||||
needs: build-binary # Wait for the reusable workflow to finish
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Download Artifact
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: nyanit-${{ inputs.tag_name }}
|
||||
|
||||
- name: Create Release and Attach Binary
|
||||
uses: actions/release-action@main
|
||||
with:
|
||||
artifacts: "nyanit-${{ inputs.tag_name }}"
|
||||
api_key: ${{ secrets.bzzpss_release_psszz }}
|
||||
tag_name: ${{ inputs.tag_name }}
|
||||
name: Release ${{ inputs.tag_name }}
|
||||
body: "Automated release for ${{ inputs.tag_name }}\n${{ inputs.rel_description }}"
|
||||
|
||||
Generated
+40
-27
@@ -242,18 +242,18 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "lru"
|
||||
version = "0.18.0"
|
||||
version = "0.18.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8a860605968fce16869fd239cf4237a82f3ac470723415db603b0e8b6c8d4fb9"
|
||||
checksum = "0b6180140927ee907000b0aa540091f6ea512ead4447c92b8fc35bc72788a5a6"
|
||||
dependencies = [
|
||||
"hashbrown 0.17.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.8.2"
|
||||
version = "2.8.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "88904434abc2901f197fe8cc55f0445e7ded921dba5911dad2e2b39b48e663c4"
|
||||
checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
|
||||
|
||||
[[package]]
|
||||
name = "num-conv"
|
||||
@@ -287,9 +287,10 @@ checksum = "6aa2c4e539b869820a2b82e1aef6ff40aa85e65decdd5185e83fb4b1249cd00f"
|
||||
|
||||
[[package]]
|
||||
name = "nyanit"
|
||||
version = "0.1.0"
|
||||
version = "0.1.4"
|
||||
dependencies = [
|
||||
"ratatui",
|
||||
"ratatui-textarea",
|
||||
"regex",
|
||||
"termion",
|
||||
]
|
||||
@@ -341,18 +342,18 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.45"
|
||||
version = "1.0.46"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924"
|
||||
checksum = "dfbc457d0c7a0759a614551b11a6409e5951f6c7537be1f1b7682b9ae9230368"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ratatui"
|
||||
version = "0.30.1"
|
||||
version = "0.30.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1695748e3a735b34968c887ceea5a380b43545903868ae8f5b666593100f6b68"
|
||||
checksum = "3274ba0a2c5e1bcad2a2005d20f4dc59dad26b2eb0940fb094500dba4099d57d"
|
||||
dependencies = [
|
||||
"instability",
|
||||
"ratatui-core",
|
||||
@@ -363,14 +364,13 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ratatui-core"
|
||||
version = "0.1.1"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "42d3603f354bba8c595fa47860e60142d7372b7210c27044c6a7d0e1a4336b44"
|
||||
checksum = "cbb175c433c8e28a809d1f5773a2ae96e68c0ce40db865cbab1020bf33ae479c"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"compact_str",
|
||||
"hashbrown 0.17.1",
|
||||
"indoc",
|
||||
"itertools",
|
||||
"kasuari",
|
||||
"lru",
|
||||
@@ -385,9 +385,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ratatui-termion"
|
||||
version = "0.1.1"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5c16cc35a9d9114e0b2bb4b22018b96ae7f5fe60e2595dc73e622b4e78624835"
|
||||
checksum = "87c732202fa5a71a9da0991013f0853e53f87048f45198e3a1ca3ee722accc2f"
|
||||
dependencies = [
|
||||
"instability",
|
||||
"ratatui-core",
|
||||
@@ -395,10 +395,23 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ratatui-widgets"
|
||||
version = "0.3.1"
|
||||
name = "ratatui-textarea"
|
||||
version = "0.9.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7ef4f17dd7ac3abf5adc2b920a03c61eee4bfe6a88fa5191936895525371d79c"
|
||||
checksum = "3c78d5ba0f26f97baed69a4c479f268a31c7b5b89d68ab939842152e383d6e73"
|
||||
dependencies = [
|
||||
"ratatui-core",
|
||||
"ratatui-termion",
|
||||
"ratatui-widgets",
|
||||
"unicode-segmentation",
|
||||
"unicode-width",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ratatui-widgets"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "66e3d19bcc9130ca376277d93b60767ff121ace3be06f5f95f81dd68956407d1"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"hashbrown 0.17.1",
|
||||
@@ -416,9 +429,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.12.4"
|
||||
version = "1.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f1292b7759ae1cb9ec195452d1390a074f0cd8541ab7a5a8c31cd6db45d4a6ba"
|
||||
checksum = "2a0e75113e14dc5acb068cd0786884f214f1312650a3d36d269f5c4f3cdee8a2"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
@@ -428,9 +441,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "regex-automata"
|
||||
version = "0.4.14"
|
||||
version = "0.4.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6e1dd4122fc1595e8162618945476892eefca7b88c52820e74af6262213cae8f"
|
||||
checksum = "1f388202e4b80542a0921078cc23b6333bcf1409c1e3f86404cae4766a6131db"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
@@ -445,9 +458,9 @@ checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4"
|
||||
|
||||
[[package]]
|
||||
name = "rustversion"
|
||||
version = "1.0.22"
|
||||
version = "1.0.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
|
||||
checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f"
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
@@ -520,9 +533,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.117"
|
||||
version = "2.0.118"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99"
|
||||
checksum = "1b9ae57f904213ebb649ce6895b8a66c66f0203b9319718f69a5612a065b1422"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -561,9 +574,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "time"
|
||||
version = "0.3.49"
|
||||
version = "0.3.53"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "711a53c2d47bbd818258c498c8dbfe186a2526c631495cfe7e078567f86b8469"
|
||||
checksum = "18dfaaeddcb932337b5e7866ee7d0ce9b76d2fd092997146f187ec09b4558a50"
|
||||
dependencies = [
|
||||
"deranged",
|
||||
"libc",
|
||||
|
||||
+4
-3
@@ -1,11 +1,12 @@
|
||||
[package]
|
||||
name = "nyanit"
|
||||
version = "0.1.0"
|
||||
version = "0.1.4"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
ratatui = { version = "0.30", default-features = false, features = ["termion"] }
|
||||
regex = "1.12.4"
|
||||
ratatui-textarea = { version = "0.9", default-features = false, features = ["termion"] }
|
||||
regex = "1.1"
|
||||
termion = "4"
|
||||
|
||||
|
||||
@@ -14,5 +15,5 @@ lto = true
|
||||
debug = false
|
||||
incremental = false
|
||||
codegen-units = 1
|
||||
opt-level = 3
|
||||
opt-level = 2
|
||||
strip = true
|
||||
|
||||
@@ -1,3 +1,21 @@
|
||||
# nyanit
|
||||
|
||||
Init program for initrd
|
||||
Kira-Linux init program for initrd
|
||||
|
||||
|
||||
1. It looks for partitoin with GPT labelve **bee-root** what will shown in dev tree as **/dev/disk/by-partlabel/bee-root**
|
||||
And this partition should be formated to bcachefs.
|
||||
|
||||
2. Nyanit checks if bcachefs is encrypted, and asks for unlock password if it is.
|
||||
|
||||
3. Then it mounts it to **/mnt/bee-root**.
|
||||
|
||||
4. And looks for snapshots with name pattern **/mnt/bee-root/bzz_snaps/bzz-yyyy-mm-ddTHH-MM-SS**
|
||||
|
||||
5. If no snapshots are found it calls **switch_root** for **/mnt/bee-root**
|
||||
|
||||
6. Othervise vait for F2 for few seconds.
|
||||
And if F2 pressed provides list of snapshoots to boot from.
|
||||
|
||||
7. After some snapshoot or just **/mnt/bee-root** is selected, Nyanit doing **switch_root** to it.
|
||||
|
||||
|
||||
+137
-48
@@ -14,25 +14,27 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use ratatui::widgets::Borders;
|
||||
use ratatui::{Frame, Terminal, backend::TermionBackend, widgets::Paragraph};
|
||||
use ratatui::{Frame, Terminal, backend::TermionBackend};
|
||||
use ratatui::{
|
||||
layout::{Constraint, Layout},
|
||||
style::{Style, Stylize},
|
||||
text::{Line},
|
||||
widgets::{Block, List, ListState},
|
||||
style::{Color, Style, Stylize},
|
||||
text::Line,
|
||||
widgets::{Block, Borders, List, ListState, Paragraph},
|
||||
};
|
||||
|
||||
use ratatui_textarea::TextArea;
|
||||
|
||||
use std::io::{self, Read, stdout};
|
||||
use std::process::ExitCode;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
|
||||
use termion::event::{Event, Key};
|
||||
use termion::event::{self, Event};
|
||||
use termion::raw::IntoRawMode;
|
||||
|
||||
mod nyan_system;
|
||||
|
||||
use nyan_system::{ExecCommandError};
|
||||
use nyan_system::ExecCommandError;
|
||||
|
||||
const BEE_CAT: &str = include_str!("bee_cat.txt");
|
||||
|
||||
@@ -71,17 +73,8 @@ enum NyanitState {
|
||||
HandOff(String),
|
||||
}
|
||||
|
||||
fn init_stage() -> Result<NyanitState, ExecCommandError> {
|
||||
// mount sysfss
|
||||
nyan_system::prepare_env()?;
|
||||
|
||||
// check if device is encrypted
|
||||
if nyan_system::bzzpss_dev_encrypted(ROOT_DEV)? {
|
||||
// if encrypted return EnterPassword so used get promted for pass
|
||||
return Ok(NyanitState::EnterPassword);
|
||||
}
|
||||
|
||||
// if unencrypted
|
||||
/// Mounting bee-root and chiking if there any snapshots
|
||||
fn mount_and_check_snaps() -> Result<NyanitState, ExecCommandError> {
|
||||
// mount bee-root
|
||||
nyan_system::mount_bee_root(TMP_ROOT, ROOT_DEV)?;
|
||||
|
||||
@@ -93,24 +86,40 @@ fn init_stage() -> Result<NyanitState, ExecCommandError> {
|
||||
return Ok(NyanitState::WaitForF2(snaps_list));
|
||||
}
|
||||
|
||||
// tell to finish boot
|
||||
// else tell to finish boot
|
||||
Ok(NyanitState::HandOff(TMP_ROOT.into()))
|
||||
}
|
||||
|
||||
pub struct NyanitTUI {
|
||||
fn init_stage() -> Result<NyanitState, ExecCommandError> {
|
||||
// mount sysfss
|
||||
nyan_system::prepare_env().map_err(|ex| format!("prepare_env error: {}", ex))?;
|
||||
|
||||
// check if device is encrypted
|
||||
if nyan_system::bzzpss_dev_encrypted(ROOT_DEV).map_err(|ex| format!("Error checking if device is encrypted: {}", ex))? {
|
||||
// if encrypted return EnterPassword so used get promted for pass
|
||||
return Ok(NyanitState::EnterPassword);
|
||||
}
|
||||
|
||||
// if unencrypted
|
||||
mount_and_check_snaps()
|
||||
}
|
||||
|
||||
struct NyanitTUI<'a> {
|
||||
exit: bool,
|
||||
state: NyanitState,
|
||||
list_state: ListState,
|
||||
time_counter: u32,
|
||||
textarea: Option<TextArea<'a>>,
|
||||
}
|
||||
|
||||
impl NyanitTUI {
|
||||
impl NyanitTUI<'_> {
|
||||
pub fn new() -> io::Result<Self> {
|
||||
Ok(Self {
|
||||
exit: false,
|
||||
state: NyanitState::Init,
|
||||
list_state: ListState::default().with_selected(Some(0)),
|
||||
time_counter: 0,
|
||||
textarea: None,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -127,19 +136,34 @@ impl NyanitTUI {
|
||||
};
|
||||
|
||||
// if drive unencrypted and there is no root snapshots finish boot
|
||||
if let NyanitState::HandOff(root_mnt) = &self.state {
|
||||
if let Err(ex) = nyan_system::hand_off_control(root_mnt, SYS_INIT) {
|
||||
self.state = NyanitState::Error(ex.to_string())
|
||||
match &self.state {
|
||||
// if drive unencrypted and there is no root snapshots finish boot
|
||||
NyanitState::HandOff(root_mnt) => {
|
||||
if let Err(ex) = nyan_system::hand_off_control(root_mnt, SYS_INIT) {
|
||||
self.state = NyanitState::Error(ex.to_string())
|
||||
}
|
||||
}
|
||||
// init password input
|
||||
NyanitState::EnterPassword => {
|
||||
let mut textarea: TextArea<'_> = TextArea::default();
|
||||
textarea.set_cursor_line_style(Style::default());
|
||||
textarea.set_mask_char('\u{1F41D}'); //U+2022 BULLET (•)
|
||||
textarea.set_placeholder_text("Please enter your password");
|
||||
textarea.set_style(Style::default().fg(Color::LightYellow));
|
||||
textarea.set_block(Block::default().borders(Borders::ALL).title("Password"));
|
||||
self.textarea = Some(textarea);
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
||||
// Init terminal
|
||||
// 1. Enable raw mode
|
||||
let stdout = stdout().into_raw_mode()?;
|
||||
// 2. Setup Terminal
|
||||
let backend = TermionBackend::new(stdout);
|
||||
let mut terminal = Terminal::new(backend)?;
|
||||
|
||||
// init tty input and start actually drawing things now!
|
||||
// init tty async input and start actually drawing things now!
|
||||
let mut tty_input_async = termion::async_stdin().bytes();
|
||||
|
||||
self.time_counter = 0;
|
||||
@@ -207,51 +231,116 @@ impl NyanitTUI {
|
||||
&mut self.list_state,
|
||||
);
|
||||
}
|
||||
NyanitState::EnterPassword => {
|
||||
frame.render_widget(self.textarea.as_ref().unwrap(), vertical_chunks[1]);
|
||||
}
|
||||
NyanitState::HandOff(_) => {
|
||||
let ok_text = Paragraph::new("Booting\nKira Linux\n \u{1F41D} \u{1F41D} :3")
|
||||
.block(Block::bordered().light_green())
|
||||
.light_green();
|
||||
frame.render_widget(ok_text, vertical_chunks[1]);
|
||||
// just some time to look at message
|
||||
thread::sleep(Duration::from_millis(1000))
|
||||
}
|
||||
_ => (),
|
||||
};
|
||||
}
|
||||
|
||||
fn handle_events(&mut self, tty_input: &mut io::Bytes<termion::AsyncReader>) -> io::Result<()> {
|
||||
|
||||
// cheking if there is any input to read
|
||||
if let Some(item) = tty_input.next() {
|
||||
let read_byte = item?;
|
||||
|
||||
let e = termion::event::parse_event(read_byte, tty_input)?;
|
||||
let e = event::parse_event(read_byte, tty_input)?;
|
||||
match &self.state {
|
||||
NyanitState::WaitForF2(vol_list) => {
|
||||
if e == Event::Key(Key::F(2)) {
|
||||
self.state = NyanitState::ChooseSnapshot(vol_list.clone());
|
||||
}
|
||||
},
|
||||
NyanitState::ChooseSnapshot(vol_list) => {
|
||||
match e {
|
||||
Event::Key(Key::Down) => self.list_state.select_next(),
|
||||
Event::Key(Key::Up) => self.list_state.select_previous(),
|
||||
Event::Key(Key::Char('\n')) => if let Some(idx) = self.list_state.selected() {
|
||||
self.state = NyanitState::HandOff(vol_list[idx].clone());
|
||||
},
|
||||
_ => (),
|
||||
// finishing boot
|
||||
NyanitState::HandOff(root_mnt) => {
|
||||
if let Err(ex) = nyan_system::hand_off_control(root_mnt, SYS_INIT) {
|
||||
self.state = NyanitState::Error(ex.to_string())
|
||||
}
|
||||
}
|
||||
NyanitState::WaitForF2(vol_list) => {
|
||||
if e == Event::Key(event::Key::F(2)) {
|
||||
self.state = NyanitState::ChooseSnapshot(vol_list.clone());
|
||||
}
|
||||
}
|
||||
NyanitState::ChooseSnapshot(vol_list) => match e {
|
||||
Event::Key(event::Key::Down) => self.list_state.select_next(),
|
||||
Event::Key(event::Key::Up) => self.list_state.select_previous(),
|
||||
Event::Key(event::Key::Char('\n')) => {
|
||||
if let Some(idx) = self.list_state.selected() {
|
||||
self.state = NyanitState::HandOff(vol_list[idx].clone());
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
},
|
||||
_ => ()
|
||||
NyanitState::EnterPassword => {
|
||||
match e {
|
||||
// try to unlock if enter pressed
|
||||
Event::Key(event::Key::Char('\n')) => {
|
||||
let password = self.textarea.as_ref().unwrap().lines()[0].clone();
|
||||
match nyan_system::bcachefs_unlock(password, ROOT_DEV) {
|
||||
Ok(unlocked) => {
|
||||
if unlocked {
|
||||
// need to check for subvolumes and stuff
|
||||
self.state = match mount_and_check_snaps() {
|
||||
Ok(st) => {
|
||||
self.time_counter = 0;
|
||||
st
|
||||
}
|
||||
Err(ex) => NyanitState::Error(ex.to_string()),
|
||||
}
|
||||
}
|
||||
// ask to enter password again
|
||||
else {
|
||||
self.textarea
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.set_placeholder_text("Wrong password, try again");
|
||||
self.textarea
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.set_style(Style::default().fg(Color::LightRed));
|
||||
self.textarea.as_mut().unwrap().clear();
|
||||
}
|
||||
}
|
||||
Err(ex) => {
|
||||
self.state = NyanitState::Error(ex.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
self.textarea
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.set_style(Style::default().fg(Color::LightYellow));
|
||||
self.textarea.as_mut().unwrap().input(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// Tick time
|
||||
thread::sleep(Duration::from_millis(500));
|
||||
self.time_counter = self.time_counter.wrapping_add(1u32);
|
||||
// 2.5 sec wait
|
||||
if self.time_counter > 5 {
|
||||
// boot from root
|
||||
self.state = NyanitState::HandOff(TMP_ROOT.into());
|
||||
|
||||
if let NyanitState::WaitForF2(_) = self.state {
|
||||
self.time_counter = self.time_counter.wrapping_add(1u32);
|
||||
// 2.5 sec wait
|
||||
if self.time_counter > 5 {
|
||||
// boot from root
|
||||
self.state = NyanitState::HandOff(TMP_ROOT.into());
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
fn main() -> ExitCode {
|
||||
nyan_system::set_env_vars_unsafe();
|
||||
let mut app = NyanitTUI::new().unwrap();
|
||||
app.run().unwrap();
|
||||
// Terminal restores automatically when `stdout` (RawTerminal) is dropped
|
||||
|
||||
+97
-20
@@ -101,7 +101,9 @@ impl std::error::Error for ExecCommandError {}
|
||||
|
||||
/// exec given command 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()?;
|
||||
// For testing shake lets assume all binaries is in /usr/bin
|
||||
let ex_cmd = format!("/usr/bin/{}", cmd);
|
||||
let out = Command::new(ex_cmd).args(args).output()?;
|
||||
if out.status.success() {
|
||||
Ok(())
|
||||
} else {
|
||||
@@ -111,33 +113,80 @@ pub fn exec_command(cmd: &str, args: &Vec<&str>) -> Result<(), ExecCommandError>
|
||||
|
||||
/// exec given command 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())
|
||||
}
|
||||
}
|
||||
// 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())
|
||||
// }
|
||||
// }
|
||||
|
||||
// ls /dev/disk/by-partlabel/
|
||||
// here we can find gpt part labels
|
||||
pub fn list_gpt_labeled_devs() -> Result<Vec<String>, ExecCommandError> {
|
||||
use std::os::unix::fs::FileTypeExt;
|
||||
let mut res: Vec<String> = Vec::new();
|
||||
for maybe_entry in fs::read_dir("/dev/disk/by-partlabel/")? {
|
||||
let entry = maybe_entry?;
|
||||
if entry.file_type()?.is_block_device() {
|
||||
res.push(entry.path().to_str().unwrap().to_string());
|
||||
}
|
||||
// pub fn list_gpt_labeled_devs() -> Result<Vec<String>, ExecCommandError> {
|
||||
// use std::os::unix::fs::FileTypeExt;
|
||||
// let mut res: Vec<String> = Vec::new();
|
||||
// for maybe_entry in fs::read_dir("/dev/disk/by-partlabel/")? {
|
||||
// let entry = maybe_entry?;
|
||||
// if entry.file_type()?.is_block_device() {
|
||||
// res.push(entry.path().to_str().unwrap().to_string());
|
||||
// }
|
||||
// }
|
||||
|
||||
// Ok(res)
|
||||
// }
|
||||
|
||||
/// bcachefs unlock --file=/tmp/bzzpsspass.txt /dev/loop0somedev
|
||||
/// Ok so. It is stupid, because bcacheutils far from ideal.
|
||||
/// But if we provide wrong password from file or stdin this stuff plays stupid and asks for right password.
|
||||
/// Sooo.. In order to know if unlock was sucessfull we need to check if program exited with Ok status,
|
||||
/// or it shits to STDERR still waiting for stdin
|
||||
/// Returns true if unlock successful, and false otherwise
|
||||
pub fn bcachefs_unlock(pass: String, dev: &str) -> Result<bool, ExecCommandError> {
|
||||
use std::io::Read;
|
||||
use std::io::Write;
|
||||
use std::process::Stdio;
|
||||
// "-k", "session" is important as it stores key in sessyin keyring what allows
|
||||
// system to mount filesystem after switch_root
|
||||
let mut child = Command::new("bcachefs")
|
||||
.args(&vec!["unlock", "-k", "session", dev])
|
||||
.stdin(Stdio::piped())
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
.spawn()?;
|
||||
|
||||
let mut c_stderr = child.stderr.take().ok_or_else(||{"Unable to get child process STDERR".to_string()})?;
|
||||
|
||||
// Write password to STDIN in a limited scope
|
||||
{
|
||||
let mut c_stdin = child.stdin.take().ok_or_else(||{"Unable to get child process STDIN".to_string()})?;
|
||||
// neccessery to use thread or we may be deadlocking
|
||||
c_stdin.write_all(pass.as_bytes())?;
|
||||
let bytes_written = c_stdin.write(b"\n")?;
|
||||
println!("bytes_written: {}", bytes_written);
|
||||
// stdin is dropped here automatically when the block ends
|
||||
}
|
||||
|
||||
Ok(res)
|
||||
let mut buffer = [0u8; 10];
|
||||
// This blocks.
|
||||
// if unlok fails it reads 10 bytes (piece of err message)
|
||||
// if sucess it reads 0 bytes and exit
|
||||
let read_b = c_stderr.read(&mut buffer)?;
|
||||
if read_b > 0 {
|
||||
println!("STDERR error not empty, password incorrect! Try to kill a child.");
|
||||
child.kill()?;
|
||||
}
|
||||
|
||||
// Safe to wait now; child will see EOF
|
||||
let exit_status = child.wait()?;
|
||||
// if exit status is SUCCESS - unloking is successful
|
||||
Ok(exit_status.success())
|
||||
}
|
||||
|
||||
/// Cheking if device is encripted
|
||||
pub fn bzzpss_dev_encrypted(dev_name: &str) -> Result<bool, ExecCommandError> {
|
||||
match exec_command("bcachefs", &vec!["unlock", "--check"]) {
|
||||
match exec_command("bcachefs", &vec!["unlock", "--check", dev_name]) {
|
||||
Ok(_) => Ok(true), // if status OK - dev encrypted
|
||||
Err(ExecCommandError::CommandFailed(_)) => Ok(false), // if bcachefs returned error - unencrypted
|
||||
Err(ex) => Err(ex), // othervice its error
|
||||
@@ -176,10 +225,38 @@ pub fn prepare_env() -> Result<(), ExecCommandError> {
|
||||
exec_command("mount", &vec!["-t", "sysfs", "none", "/sys"])?;
|
||||
|
||||
// modprobe bcachefs
|
||||
exec_command("modprobe", &vec!["bcachefs"])?;
|
||||
// exec_command("modprobe", &vec!["bcachefs"])?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
///
|
||||
/// MUST be done before spawning any threads or async runtimes
|
||||
pub fn set_env_vars_unsafe() -> () {
|
||||
use std::env;
|
||||
// 1. Define your custom paths
|
||||
let custom_bin = "/usr/bin";
|
||||
let custom_lib = "/usr/lib";
|
||||
|
||||
// 2. Retrieve existing paths to append/prepend (optional but recommended)
|
||||
// 3. Construct new path strings
|
||||
let new_path = match env::var("PATH") {
|
||||
Err(_) => custom_bin.to_string(),
|
||||
Ok(v) => format!("{}:{}", v, custom_bin)
|
||||
};
|
||||
|
||||
let new_ld_path = match env::var("LD_LIBRARY_PATH") {
|
||||
Err(_) => custom_lib.to_string(),
|
||||
Ok(v) => format!("{}:{}", v, custom_lib)
|
||||
};
|
||||
|
||||
// 4. Set environment variables (UNSAFE in Rust 2024+)
|
||||
// MUST be done before spawning any threads or async runtimes
|
||||
unsafe {
|
||||
env::set_var("PATH", new_path);
|
||||
env::set_var("LD_LIBRARY_PATH", new_ld_path);
|
||||
}
|
||||
}
|
||||
|
||||
// # Mount the real root filesystem
|
||||
pub fn mount_bee_root(mount_point: &str, dev_name: &str) -> Result<(), ExecCommandError> {
|
||||
exec_command("mount", &vec!["-o", "ro", dev_name, mount_point])?;
|
||||
|
||||
Reference in New Issue
Block a user