Skip to content

Commit

Permalink
feat(management): show installed and upgradable APT packages
Browse files Browse the repository at this point in the history
  • Loading branch information
ravenclaw900 committed Oct 2, 2021
1 parent 3aa0a30 commit ca6a447
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/backend/src/systemdata.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down Expand Up @@ -135,7 +136,7 @@ pub fn dpsoftware() -> Vec<types::DPSoftwareData> {
.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::<Vec<&str>>();
Expand Down Expand Up @@ -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::<u32>()
.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,
}
}
2 changes: 2 additions & 0 deletions src/backend/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,6 @@ pub struct HostData {
pub arch: String,
pub kernel: String,
pub version: String,
pub packages: usize,
pub upgrades: u32,
}
9 changes: 9 additions & 0 deletions src/frontend/src/pages/Management.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@
<td class="p-1 font-semibold">Version:</td>
<td class="p-1">{socketData.version}</td>
</tr>
<tr
class="even:bg-white odd:bg-gray-200 dark:even:bg-black dark:odd:bg-gray-800"
>
<td class="p-1 font-semibold">Installed Packages:</td>
<td class="p-1"
>{socketData.packages}
{#if socketData.upgrades !== 0}({socketData.upgrades} upgradable){/if}
</td>
</tr>
</table>
</Card>
<Card header="Management">
Expand Down

0 comments on commit ca6a447

Please sign in to comment.