diff --git a/Cargo.lock b/Cargo.lock index c5eb870..d08915a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -220,7 +220,7 @@ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] name = "hive-up" -version = "0.1.0" +version = "0.1.1" dependencies = [ "clap", "nix", diff --git a/Cargo.toml b/Cargo.toml index 31e1a60..12f6172 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hive-up" -version = "0.1.0" +version = "0.1.1" edition = "2024" [dependencies] diff --git a/pacman/99-kernel-update.hook b/files/99-kira-kernel-update.hook similarity index 100% rename from pacman/99-kernel-update.hook rename to files/99-kira-kernel-update.hook diff --git a/service_defenitions/dinit.service b/files/dinit.service similarity index 100% rename from service_defenitions/dinit.service rename to files/dinit.service diff --git a/files/hive-up.toml b/files/hive-up.toml new file mode 100644 index 0000000..cf4d035 --- /dev/null +++ b/files/hive-up.toml @@ -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 = "" diff --git a/src/daemon.rs b/src/daemon.rs index d317b53..ce3dc09 100644 --- a/src/daemon.rs +++ b/src/daemon.rs @@ -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 diff --git a/src/hive_config.rs b/src/hive_config.rs index 8efac64..521440d 100644 --- a/src/hive_config.rs +++ b/src/hive_config.rs @@ -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, + // 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. diff --git a/src/hive_db.rs b/src/hive_db.rs index fdc6b87..70c7f77 100644 --- a/src/hive_db.rs +++ b/src/hive_db.rs @@ -70,10 +70,29 @@ pub struct HiveDb { pub update_on_reboot: bool, } +fn init_db() -> Result { + 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 { - let file_content = fs::read_to_string(DB_PATH)?; - let db: HiveDb = serde_json::from_str(&file_content)?; - Ok(db) + 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 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 { - 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 { - let mut db = read_db()?; - let old_value = db.last_snapshot_time; - db.last_snapshot_time = new_timestamp; - write_db(&db)?; - Ok(old_value) -} diff --git a/src/main.rs b/src/main.rs index e5c55d3..edc8e4b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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()?; }