From ca6a447ab1aa15417c1db6796fbc589e96ee8e42 Mon Sep 17 00:00:00 2001 From: ravenclaw900 <50060110+ravenclaw900@users.noreply.github.com> Date: Sat, 2 Oct 2021 08:10:24 -0500 Subject: [PATCH] feat(management): show installed and upgradable APT packages --- src/backend/src/systemdata.rs | 20 +++++++++++++++++++- src/backend/src/types.rs | 2 ++ src/frontend/src/pages/Management.svelte | 9 +++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/backend/src/systemdata.rs b/src/backend/src/systemdata.rs index d7fa0687..a4adb17e 100644 --- a/src/backend/src/systemdata.rs +++ b/src/backend/src/systemdata.rs @@ -1,6 +1,7 @@ use lazy_static::lazy_static; use psutil::{cpu, disk, host, memory, network, process}; use std::fs; +use std::str::from_utf8; use std::sync::Mutex; use std::{process::Command, thread, time}; @@ -135,7 +136,7 @@ pub fn dpsoftware() -> Vec { .output() .unwrap() .stdout; - let out_list = std::str::from_utf8(out.as_slice()) + let out_list = from_utf8(out.as_slice()) .unwrap() .split('\n') .collect::>(); @@ -210,11 +211,28 @@ pub fn host() -> types::HostData { let uptime = host::uptime().unwrap().as_secs(); let dp_file = fs::read_to_string(&std::path::Path::new("/boot/dietpi/.version")).unwrap(); let dp_version: Vec<&str> = dp_file.split(&['=', '\n'][..]).collect(); + let installed_pkgs = from_utf8( + &Command::new("dpkg") + .args(["--get-selections"]) + .output() + .unwrap() + .stdout, + ) + .unwrap() + .lines() + .count(); + let upgradable_pkgs = fs::read_to_string("/run/dietpi/.apt_updates") + .unwrap_or_else(|_| 0.to_string()) + .trim_end_matches('\n') + .parse::() + .unwrap(); types::HostData { hostname: info.hostname().to_string(), uptime, arch: info.architecture().as_str().to_string(), kernel: info.release().to_string(), version: format!("{}.{}.{}", dp_version[1], dp_version[3], dp_version[5]), + packages: installed_pkgs, + upgrades: upgradable_pkgs, } } diff --git a/src/backend/src/types.rs b/src/backend/src/types.rs index c32865d2..9a1f3360 100644 --- a/src/backend/src/types.rs +++ b/src/backend/src/types.rs @@ -67,4 +67,6 @@ pub struct HostData { pub arch: String, pub kernel: String, pub version: String, + pub packages: usize, + pub upgrades: u32, } diff --git a/src/frontend/src/pages/Management.svelte b/src/frontend/src/pages/Management.svelte index 71cb7bc7..cb38e2cf 100644 --- a/src/frontend/src/pages/Management.svelte +++ b/src/frontend/src/pages/Management.svelte @@ -72,6 +72,15 @@ Version: {socketData.version} + + Installed Packages: + {socketData.packages} + {#if socketData.upgrades !== 0}({socketData.upgrades} upgradable){/if} + +