1 Commits
9 changed files with 46 additions and 36 deletions
Generated
+1 -1
View File
@@ -220,7 +220,7 @@ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]]
name = "hive-up"
version = "0.1.0"
version = "0.1.1"
dependencies = [
"clap",
"nix",
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "hive-up"
version = "0.1.0"
version = "0.1.1"
edition = "2024"
[dependencies]
+12
View File
@@ -0,0 +1,12 @@
# Section (Table) headers
[update]
# Interval between updates check in hours. 0 - no auto check for updates.
check_interval = 58
# Tells hive-up to automatically download updates when awailable.
download_updates = true
# Tells hive-up to automatically perform updates during system reboot
auto_update = false
# In [kernel] section user may specify kernel cmd
# [kernel]
# cmd = ""
+2 -2
View File
@@ -176,7 +176,7 @@ fn process_remoute(
// doing what daemons usually beezz
fn do_local_work(config: &HiveConfig, bzz_db: &mut HiveDb) -> Result<(), DaemonError> {
// if updates check is turned on
if config.update.updates_check_interval != 0 {
if config.update.check_interval != 0 {
let timestamp = get_timestamp_sec();
// calculate how many hours passed sinse last update
@@ -186,7 +186,7 @@ fn do_local_work(config: &HiveConfig, bzz_db: &mut HiveDb) -> Result<(), DaemonE
/ 3600;
// if more than updates_check_interval specifiyed in config - check for updates
if hours_since_update_check > config.update.updates_check_interval {
if hours_since_update_check > config.update.check_interval {
// perform update check
println!("Cheking for updates...");
// now that may fail because of bad internet and idealy we
+4 -4
View File
@@ -22,13 +22,13 @@ use serde::{Deserialize, Serialize};
use std::fs;
use toml;
const CONFIG_PATH: &str = "/etc/hive_up.toml";
const CONFIG_PATH: &str = "/etc/hive-up.toml";
#[derive(Debug, Serialize, Deserialize)]
pub struct HiveConfig {
// Matches [kernel] in TOML
pub kernel: KernelConfig,
// Updates process config
pub kernel: Option<KernelConfig>,
// Updates [update] in TOML
pub update: UpdateConfig,
}
@@ -41,7 +41,7 @@ pub struct KernelConfig {
#[derive(Debug, Serialize, Deserialize)]
pub struct UpdateConfig {
/// Interval between updates check in hours. 0 - no auto check for updates.
pub updates_check_interval: u64,
pub check_interval: u64,
/// Tells hive-up to automatically download updates when awailable.
pub download_updates: bool,
/// Tells hive-up to automatically perform updates during system reboot.
+19 -23
View File
@@ -70,10 +70,29 @@ pub struct HiveDb {
pub update_on_reboot: bool,
}
fn init_db() -> Result<HiveDb, DBError> {
let bzz_db = HiveDb{
update_check_timestamp: 0,
updates_available: 0,
update_status: false,
last_snapshot_time: "".into(),
update_on_reboot: false,
};
write_db(&bzz_db)?;
Ok(bzz_db)
}
pub fn read_db() -> Result<HiveDb, DBError> {
if fs::exists(DB_PATH)? {
let file_content = fs::read_to_string(DB_PATH)?;
let db: HiveDb = serde_json::from_str(&file_content)?;
Ok(db)
}
else {
println!("WARNING database file do not exist {}", DB_PATH);
print!("Creating default db file...");
init_db()
}
}
pub fn write_db(db: &HiveDb) -> Result<(), DBError> {
@@ -94,26 +113,3 @@ pub fn update_last_check_update_time(new_timestamp: u64) -> Result<u64, DBError>
Ok(old_value)
}
///
/// writes new update_status to db
/// and returns old db value on success
///
pub fn update_update_status(sucess_status: bool) -> Result<bool, DBError> {
let mut db = read_db()?;
let old_value = db.update_status;
db.update_status = sucess_status;
write_db(&db)?;
Ok(old_value)
}
///
/// writes new last_update_timestamp to db
/// and returns old value on success
///
pub fn update_last_update_timestamp(new_timestamp: String) -> Result<String, DBError> {
let mut db = read_db()?;
let old_value = db.last_snapshot_time;
db.last_snapshot_time = new_timestamp;
write_db(&db)?;
Ok(old_value)
}
+4 -2
View File
@@ -212,11 +212,13 @@ fn main() -> Result<(), HiveUpError> {
hive_system::boot_update()?;
} else if cli_args.init_boot_menu {
println!("Init EFI boot menu...");
hive_system::init_efi_boot_record(&bzz_config.kernel.cmd)?;
let kernel_cmd = bzz_config.kernel.and_then(|kk| kk.cmd.clone());
hive_system::init_efi_boot_record(&kernel_cmd)?;
} else if cli_args.init_boot {
println!("Init EFI boot menu and EFI partition content...");
println!("Init EFI Partition content...");
hive_system::init_efi_boot_record(&bzz_config.kernel.cmd)?;
let kernel_cmd = bzz_config.kernel.and_then(|kk| kk.cmd.clone());
hive_system::init_efi_boot_record(&kernel_cmd)?;
println!("Init EFI boot menu...");
hive_system::init_efi_boot_partition_content()?;
}