Some checks failed
Run Check Script / check (pull_request) Failing after 19s
69 lines
2.1 KiB
Rust
69 lines
2.1 KiB
Rust
//! Example: check OPNsense firmware status and list available updates.
|
|
//!
|
|
//! ```text
|
|
//! cargo run --example firmware_check
|
|
//! ```
|
|
|
|
mod common;
|
|
|
|
#[tokio::main]
|
|
async fn main() {
|
|
let client = common::client_from_env();
|
|
|
|
// Trigger a firmware check
|
|
println!("Triggering firmware check...");
|
|
let check_resp: serde_json::Value = client
|
|
.post_typed("core", "firmware", "check", None::<&()>)
|
|
.await
|
|
.expect("check API call failed");
|
|
println!(
|
|
"Check response: {}",
|
|
serde_json::to_string_pretty(&check_resp).unwrap()
|
|
);
|
|
|
|
// Get current firmware status
|
|
println!("\nFirmware status:");
|
|
let status: serde_json::Value = client
|
|
.get_typed("core", "firmware", "status")
|
|
.await
|
|
.expect("status API call failed");
|
|
|
|
if let Some(s) = status.get("status") {
|
|
println!(" status: {s}");
|
|
}
|
|
if let Some(s) = status.get("status_msg") {
|
|
println!(" message: {s}");
|
|
}
|
|
if let Some(pkgs) = status.get("new_packages") {
|
|
println!(" new_packages: {pkgs}");
|
|
}
|
|
if let Some(pkgs) = status.get("reinstall_packages") {
|
|
println!(" reinstall_packages: {pkgs}");
|
|
}
|
|
if let Some(pkgs) = status.get("upgrade_packages") {
|
|
println!(" upgrade_packages: {pkgs}");
|
|
}
|
|
|
|
// List all packages with their install status
|
|
println!("\nPackage list (haproxy/caddy/wireguard):");
|
|
let info: serde_json::Value = client
|
|
.get_typed("core", "firmware", "info")
|
|
.await
|
|
.expect("info API call failed");
|
|
|
|
if let Some(pkgs) = info["package"].as_array() {
|
|
for pkg in pkgs {
|
|
let name = pkg["name"].as_str().unwrap_or("?");
|
|
if name.contains("haproxy") || name.contains("caddy") || name.contains("wireguard") {
|
|
println!(
|
|
" {} v{} installed={} locked={}",
|
|
name,
|
|
pkg["version"].as_str().unwrap_or("?"),
|
|
pkg["installed"].as_str().unwrap_or("?"),
|
|
pkg["locked"].as_str().unwrap_or("?"),
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|