From c6eb04507403d1269352341fcff189adf0023e6b Mon Sep 17 00:00:00 2001 From: HimbeerserverDE Date: Fri, 5 May 2023 19:16:04 +0200 Subject: add mbr and inactive root update endpoints --- src/main.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 9fe4c90..d0c27dc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -68,6 +68,46 @@ async fn handle_update_boot(data: web::Bytes) -> HttpResponse { } } +async fn handle_update_mbr(data: web::Bytes) -> HttpResponse { + let mbr = match dev() { + Ok(v) => v, + Err(e) => { + return HttpResponse::InternalServerError() + .content_type(ContentType::plaintext()) + .body(format!("can't locate disk device: {}", e)) + } + }; + + match stream_to(mbr, &data).await { + Ok(_) => HttpResponse::Ok() + .content_type(ContentType::plaintext()) + .body("successfully updated mbr"), + Err(e) => HttpResponse::InternalServerError() + .content_type(ContentType::plaintext()) + .body(format!("can't update mbr: {}", e)), + } +} + +async fn handle_update_root(data: web::Bytes) -> HttpResponse { + let root = match inactive_root() { + Ok(v) => v, + Err(e) => { + return HttpResponse::InternalServerError() + .content_type(ContentType::plaintext()) + .body(format!("can't locate inactive root partition: {}", e)) + } + }; + + match stream_to(&root, &data).await { + Ok(_) => HttpResponse::Ok() + .content_type(ContentType::plaintext()) + .body("successfully updated inactive root partition"), + Err(e) => HttpResponse::InternalServerError() + .content_type(ContentType::plaintext()) + .body(format!("can't update inactive root partition: {}", e)), + } +} + #[actix_web::main] async fn main() -> io::Result<()> { match start().await { @@ -93,6 +133,8 @@ async fn start() -> Result<()> { .service(web::resource("/reboot").to(handle_reboot)) .service(web::resource("/shutdown").to(handle_shutdown)) .service(web::resource("/update/boot").to(handle_update_boot)) + .service(web::resource("/update/mbr").to(handle_update_mbr)) + .service(web::resource("/update/root").to(handle_update_root)) }) .bind_rustls("[::]:8443", config)? .run() -- cgit v1.2.3