diff --git a/appmgr/Cargo.lock b/appmgr/Cargo.lock index bfb6c2046..3c39239d6 100644 --- a/appmgr/Cargo.lock +++ b/appmgr/Cargo.lock @@ -808,6 +808,7 @@ dependencies = [ "sequence_trie", "serde", "serde_json", + "serde_with", "serde_yaml", "sha2", "simple-logging", @@ -2710,6 +2711,7 @@ checksum = "062b87e45d8f26714eacfaef0ed9a583e2bfd50ebd96bdd3c200733bd5758e2c" dependencies = [ "rustversion", "serde", + "serde_json", "serde_with_macros", ] diff --git a/appmgr/Cargo.toml b/appmgr/Cargo.toml index 0d322563a..dc3f1ef10 100644 --- a/appmgr/Cargo.toml +++ b/appmgr/Cargo.toml @@ -119,3 +119,7 @@ tokio-util = { version = "0.6.8", features = ["io"] } torut = "0.2.0" typed-builder = "0.9.1" url = { version = "2.2.2", features = ["serde"] } + +[dependencies.serde_with] +version = "1.10.0" +features = [ "macros", "json" ] diff --git a/appmgr/src/lib.rs b/appmgr/src/lib.rs index 1bd497110..e6b31c763 100644 --- a/appmgr/src/lib.rs +++ b/appmgr/src/lib.rs @@ -36,6 +36,7 @@ pub mod sound; pub mod ssh; pub mod status; pub mod system; +pub mod update; pub mod util; pub mod version; pub mod volume; diff --git a/appmgr/src/update/latest_information.rs b/appmgr/src/update/latest_information.rs new file mode 100644 index 000000000..0434ae928 --- /dev/null +++ b/appmgr/src/update/latest_information.rs @@ -0,0 +1,22 @@ +use emver::Version; +use serde::{Deserialize, Serialize}; +use serde_with::{serde_as, DisplayFromStr}; +use std::collections::HashMap; + +#[serde_as] +#[derive(Debug, Deserialize, Serialize)] +#[serde(rename_all = "kebab-case")] +pub struct LatestInformation { + release_notes: HashMap, + headline: String, + #[serde_as(as = "DisplayFromStr")] + pub version: Version, +} + +/// Captured from https://beta-registry-0-3.start9labs.com/eos/latest 2021-09-24 +#[test] +fn latest_information_from_server() { + let data_from_server = r#"{"release-notes":{"0.3.0":"This major software release encapsulates the optimal performance, security, and management enhancments to the EmbassyOS experience."},"headline":"Major EmbassyOS release","version":"0.3.0"}"#; + let latest_information: LatestInformation = serde_json::from_str(data_from_server).unwrap(); + assert_eq!(latest_information.version.minor(), 3); +} diff --git a/appmgr/src/update/mod.rs b/appmgr/src/update/mod.rs new file mode 100644 index 000000000..c40be2830 --- /dev/null +++ b/appmgr/src/update/mod.rs @@ -0,0 +1,53 @@ +use clap::ArgMatches; +use rpc_toolkit::command; +use serde_json::Value; + +use crate::context::RpcContext; +use crate::update::latest_information::LatestInformation; +use crate::{Error, ErrorKind, ResultExt}; + +const URL: &str = "https://beta-registry-0-3.start9labs.com/eos/latest"; +mod latest_information; + +pub fn display_properties(response: (), _: &ArgMatches<'_>) { + println!("Test"); +} +#[command(display(display_properties))] +pub async fn update_system(#[context] ctx: RpcContext) -> Result<(), Error> { + if let None = fetch_file(ctx).await? { + return Ok(()); + } + todo!() +} + +pub async fn fetch_file(ctx: RpcContext) -> Result, Error> { + let mut db = ctx.db.handle(); + let latest_version = reqwest::get(URL) + .await + .with_kind(ErrorKind::Network)? + .json::() + .await + .with_kind(ErrorKind::Network)? + .version; + let current_version = crate::db::DatabaseModel::new() + .server_info() + .version() + .get(&mut db, false) + .await?; + if &latest_version > ¤t_version { + todo!("If new pull down only one (Mutex lock this)") + } else { + todo!("Skip the rest") + } +} + +pub async fn check_download(ctx: RpcContext) -> Result { + let hash_from_header = todo!(); + let hash_from_file = todo!(); + todo!("Fail if bad check") +} + +pub async fn swap(ctx: RpcContext) -> Result { + todo!("Do swap"); + todo!("Let system know that we need a reboot or something") +} diff --git a/appmgr/tmp.db b/appmgr/tmp.db new file mode 100644 index 000000000..45387bfa4 Binary files /dev/null and b/appmgr/tmp.db differ diff --git a/system-images/compat/Cargo.lock b/system-images/compat/Cargo.lock index b3ba05e9a..cf6e57685 100644 --- a/system-images/compat/Cargo.lock +++ b/system-images/compat/Cargo.lock @@ -853,6 +853,7 @@ dependencies = [ "sequence_trie", "serde", "serde_json", + "serde_with", "serde_yaml", "sha2", "simple-logging", @@ -2831,6 +2832,7 @@ checksum = "062b87e45d8f26714eacfaef0ed9a583e2bfd50ebd96bdd3c200733bd5758e2c" dependencies = [ "rustversion", "serde", + "serde_json", "serde_with_macros", ]