SHA256
A bit of cleanups and wraping up stuff
This commit is contained in:
+7
-7
@@ -97,11 +97,11 @@ pub fn read_config() -> Result<HiveConfig, ConfigError> {
|
||||
Ok(config)
|
||||
}
|
||||
|
||||
pub fn change_updates_check_interval(new_interval: u64) -> Result<HiveConfig, ConfigError> {
|
||||
let mut config: HiveConfig = read_config()?;
|
||||
config.update.updates_check_interval = new_interval;
|
||||
let conf_str = toml::to_string_pretty(&config)?;
|
||||
fs::write(CONFIG_PATH, conf_str)?;
|
||||
// pub fn change_updates_check_interval(new_interval: u64) -> Result<HiveConfig, ConfigError> {
|
||||
// let mut config: HiveConfig = read_config()?;
|
||||
// config.update.updates_check_interval = new_interval;
|
||||
// let conf_str = toml::to_string_pretty(&config)?;
|
||||
// fs::write(CONFIG_PATH, conf_str)?;
|
||||
|
||||
Ok(config)
|
||||
}
|
||||
// Ok(config)
|
||||
// }
|
||||
|
||||
@@ -194,3 +194,12 @@ pub fn client_check_for_updates() -> Result<u32, IntercomError> {
|
||||
_ => Err(IntercomError::UnexpectedResponse),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn client_schedule_update() -> Result<(), IntercomError> {
|
||||
let resp = send_and_recv(BzzReq::ScheduleUpdate)?;
|
||||
match resp {
|
||||
BzzResp::Finish => Ok(()),
|
||||
BzzResp::Error(ex) => Err(IntercomError::ServerError(ex)),
|
||||
_ => Err(IntercomError::UnexpectedResponse),
|
||||
}
|
||||
}
|
||||
|
||||
+36
-23
@@ -388,9 +388,13 @@ fn delete_all_efi_bootnums() -> Result<usize, ExecCommandError> {
|
||||
/// Creates EFI boot record
|
||||
/// boot_index - inserting it at specified boot index (bootorder)
|
||||
/// Assuming boot partition has "bee-efi" PARTLABEL
|
||||
///
|
||||
fn efi_boot_record_create(boot_index: u16, boot_label: &str, uki_path: &str, maybe_kernel_cmd: &Option<String>) -> Result<(), ExecCommandError> {
|
||||
|
||||
///
|
||||
fn efi_boot_record_create(
|
||||
boot_index: u16,
|
||||
boot_label: &str,
|
||||
uki_path: &str,
|
||||
maybe_kernel_cmd: &Option<String>,
|
||||
) -> Result<(), ExecCommandError> {
|
||||
let (efi_partno, efi_parent_dev) = get_efi_part_info()?;
|
||||
|
||||
//let local_date = time_format::strftime_local("%Y-%m-%d", time_format::now().unwrap()).unwrap();
|
||||
@@ -418,8 +422,6 @@ fn efi_boot_record_create(boot_index: u16, boot_label: &str, uki_path: &str, may
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
|
||||
///
|
||||
/// Deletes all existing boot records and create a default
|
||||
///
|
||||
@@ -428,26 +430,31 @@ pub fn init_efi_boot_record(maybe_kernel_cmd: &Option<String>) -> Result<(), Exe
|
||||
delete_all_efi_bootnums()?;
|
||||
// 2 create defaul
|
||||
efi_boot_record_create(0, BOOT_MENU_LABEL, BOOT_UKI_IMAGE_NAME, maybe_kernel_cmd)?;
|
||||
efi_boot_record_create(1, BOOT_MENU_LABEL_BACK, BOOT_UKI_IMAGE_NAME_BACK, maybe_kernel_cmd)?;
|
||||
efi_boot_record_create(
|
||||
1,
|
||||
BOOT_MENU_LABEL_BACK,
|
||||
BOOT_UKI_IMAGE_NAME_BACK,
|
||||
maybe_kernel_cmd,
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
///
|
||||
/// List installed kernels by inspecting /usr/lib/modules directory
|
||||
/// List installed kernels by inspecting /usr/lib/modules directory
|
||||
/// Result is a sorted vector of string
|
||||
///
|
||||
///
|
||||
fn list_installed_kernels() -> Result<Vec<String>, ExecCommandError> {
|
||||
use regex::Regex;
|
||||
|
||||
let re = Regex::new(r#"^[0-9]+\.[0-9]+\.[0-9]+-[0-9]-kira-lts"#).unwrap();
|
||||
let mut kernel_dirs: Vec<String> = Vec::new();
|
||||
|
||||
|
||||
// Oh boy we roll
|
||||
// finding first dir in /usr/lib/modules that matches common kernel name
|
||||
for r_d_entry in fs::read_dir("/usr/lib/modules")? {
|
||||
let d_entry = r_d_entry?;
|
||||
if d_entry.file_type()?.is_dir() {
|
||||
let maybe_file_name = d_entry.file_name().to_str().map(|s|s.to_string());
|
||||
let maybe_file_name = d_entry.file_name().to_str().map(|s| s.to_string());
|
||||
if let Some(file_name) = maybe_file_name {
|
||||
if re.is_match(&file_name) {
|
||||
kernel_dirs.push(file_name);
|
||||
@@ -465,20 +472,20 @@ pub fn init_efi_boot_partition_content() -> Result<(), ExecCommandError> {
|
||||
if let Some(kernel_dir) = kernel_dirs.last() {
|
||||
let kernel_img_path = format!("/usr/lib/modules/{}/vmlinuz", kernel_dir);
|
||||
let efi_dir = format!("{}/EFI", EFI_BOOT_MOUNT_POINT);
|
||||
println!("Romoving efi dir {}",efi_dir);
|
||||
println!("Romoving efi dir {}", efi_dir);
|
||||
fs::remove_dir_all(&efi_dir)?;
|
||||
println!("Creating efi dir {}",efi_dir);
|
||||
println!("Creating efi dir {}", efi_dir);
|
||||
fs::create_dir(efi_dir)?;
|
||||
println!("Copy {} to {}", kernel_img_path, UKI_IMAGE_NAME);
|
||||
fs::copy(&kernel_img_path, UKI_IMAGE_NAME)?;
|
||||
println!("Copy {} to {}", kernel_img_path, UKI_IMAGE_BACK_NAME);
|
||||
fs::copy(&kernel_img_path, UKI_IMAGE_BACK_NAME)?;
|
||||
Ok(())
|
||||
} else {
|
||||
Err(ExecCommandError::Other(
|
||||
"Cannot find kernel files under /usr/lib/modules dir!".into(),
|
||||
))
|
||||
}
|
||||
else {
|
||||
Err(ExecCommandError::Other("Cannot find kernel files under /usr/lib/modules dir!".into()))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
///
|
||||
@@ -490,22 +497,28 @@ pub fn init_efi_boot_partition_content() -> Result<(), ExecCommandError> {
|
||||
/// sudo cp /usr/lib/modules/6.18.46-1-kira-lts/vmlinuz /beefi/EFI/kira-linux-lts.efi
|
||||
///
|
||||
pub fn boot_update() -> Result<(), ExecCommandError> {
|
||||
|
||||
// find vmlinuz path in filesystem
|
||||
let kernel_dirs = list_installed_kernels()?;
|
||||
|
||||
|
||||
// check if kernel even exist lol
|
||||
if let Some(kernel_dir) = kernel_dirs.last() {
|
||||
let kernel_img_path = format!("/usr/lib/modules/{}/vmlinuz", kernel_dir);
|
||||
// rename old kernel to
|
||||
println!("Renaming old kernel {} to {}",UKI_IMAGE_NAME,UKI_IMAGE_BACK_NAME);
|
||||
println!(
|
||||
"Renaming old kernel {} to {}",
|
||||
UKI_IMAGE_NAME, UKI_IMAGE_BACK_NAME
|
||||
);
|
||||
fs::rename(UKI_IMAGE_NAME, UKI_IMAGE_BACK_NAME)?;
|
||||
// copy new kernel image
|
||||
println!("Copy new kernel from {} to {}",kernel_img_path,UKI_IMAGE_NAME);
|
||||
println!(
|
||||
"Copy new kernel from {} to {}",
|
||||
kernel_img_path, UKI_IMAGE_NAME
|
||||
);
|
||||
fs::copy(&kernel_img_path, UKI_IMAGE_NAME)?;
|
||||
Ok(())
|
||||
}
|
||||
else {
|
||||
Err(ExecCommandError::Other("Cannot find kernel files under /usr/lib/modules dir!".into()))
|
||||
} else {
|
||||
Err(ExecCommandError::Other(
|
||||
"Cannot find kernel files under /usr/lib/modules dir!".into(),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
+10
-2
@@ -18,7 +18,7 @@ use clap::{Args, Parser, Subcommand};
|
||||
use signal_hook;
|
||||
use std;
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicBool};
|
||||
use std::sync::atomic::AtomicBool;
|
||||
|
||||
mod hive_system;
|
||||
|
||||
@@ -111,13 +111,17 @@ impl std::error::Error for HiveUpError {}
|
||||
#[derive(Args, Debug)]
|
||||
#[group(required = true, multiple = false)]
|
||||
struct RemoteArgs {
|
||||
/// Ask daemon to chack for updates
|
||||
/// Ask daemon to check for updates
|
||||
#[arg(long)]
|
||||
check_updates: bool,
|
||||
|
||||
/// Ask daemon if there is any updates available
|
||||
#[arg(long)]
|
||||
updates_avail: bool,
|
||||
|
||||
/// Ask daemon to perform system update on next reboot
|
||||
#[arg(long)]
|
||||
schedule_update: bool,
|
||||
}
|
||||
|
||||
#[derive(Args, Debug)]
|
||||
@@ -224,6 +228,10 @@ fn main() -> Result<(), HiveUpError> {
|
||||
} else if remote_args.updates_avail {
|
||||
let up_num = hive_intercom::client_updates_available()?;
|
||||
println!("Updates awailable: {}", up_num);
|
||||
} else if remote_args.schedule_update {
|
||||
println!("Scheduling system update...");
|
||||
hive_intercom::client_schedule_update()?;
|
||||
print!("Done!")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user