mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-26 02:11:53 +00:00
Feat: Compare versions for update
This commit is contained in:
committed by
Aiden McClelland
parent
c24d63d65c
commit
4d110eb613
2
appmgr/Cargo.lock
generated
2
appmgr/Cargo.lock
generated
@@ -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",
|
||||
]
|
||||
|
||||
|
||||
@@ -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" ]
|
||||
|
||||
@@ -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;
|
||||
|
||||
22
appmgr/src/update/latest_information.rs
Normal file
22
appmgr/src/update/latest_information.rs
Normal file
@@ -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<String, String>,
|
||||
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);
|
||||
}
|
||||
53
appmgr/src/update/mod.rs
Normal file
53
appmgr/src/update/mod.rs
Normal file
@@ -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<Option<()>, Error> {
|
||||
let mut db = ctx.db.handle();
|
||||
let latest_version = reqwest::get(URL)
|
||||
.await
|
||||
.with_kind(ErrorKind::Network)?
|
||||
.json::<LatestInformation>()
|
||||
.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<Value, Error> {
|
||||
let hash_from_header = todo!();
|
||||
let hash_from_file = todo!();
|
||||
todo!("Fail if bad check")
|
||||
}
|
||||
|
||||
pub async fn swap(ctx: RpcContext) -> Result<Value, Error> {
|
||||
todo!("Do swap");
|
||||
todo!("Let system know that we need a reboot or something")
|
||||
}
|
||||
BIN
appmgr/tmp.db
Normal file
BIN
appmgr/tmp.db
Normal file
Binary file not shown.
2
system-images/compat/Cargo.lock
generated
2
system-images/compat/Cargo.lock
generated
@@ -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",
|
||||
]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user