Merge pull request 'Fix peach-config manifest' (#103) from fix-manifest into main
Reviewed-on: #103
This commit is contained in:
commit
e2ac5de6e4
|
@ -2381,7 +2381,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "peach-config"
|
||||
version = "0.1.21"
|
||||
version = "0.1.23"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"env_logger 0.6.2",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "peach-config"
|
||||
version = "0.1.21"
|
||||
version = "0.1.23"
|
||||
authors = ["Andrew Reid <gnomad@cryptolab.net>", "Max Fowler <max@mfowler.info>"]
|
||||
edition = "2018"
|
||||
description = "Command line tool for installing, updating and configuring PeachCloud"
|
||||
|
|
|
@ -1,40 +1,32 @@
|
|||
use regex::Regex;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use snafu::ResultExt;
|
||||
use std::collections::HashMap;
|
||||
use std::fs;
|
||||
|
||||
use crate::constants::HARDWARE_CONFIG_FILE;
|
||||
use crate::constants::{HARDWARE_CONFIG_FILE, SERVICES};
|
||||
use crate::error::{FileReadError, FileWriteError, PeachConfigError};
|
||||
use crate::utils::get_output;
|
||||
use crate::RtcOption;
|
||||
|
||||
/// Helper function which returns the version of a package currently installed,
|
||||
/// as an Ok(String) if found, and as an Err if not found
|
||||
pub fn get_package_version_number(package: &str) -> Result<String, PeachConfigError> {
|
||||
let version = get_output(&["dpkg-query", "--showformat=${Version}", "--show", package])?;
|
||||
Ok(version)
|
||||
}
|
||||
|
||||
/// Returns a HashMap<String, String> of all the peach-packages which are currently installed
|
||||
/// mapped to their version number e.g. { "peach-probe": "1.2.0", "peach-network": "1.4.0" }
|
||||
pub fn get_currently_installed_microservices() -> Result<HashMap<String, String>, PeachConfigError>
|
||||
{
|
||||
// gets a list of all packages currently installed with dpkg
|
||||
let packages = get_output(&["dpkg", "-l"])?;
|
||||
|
||||
// this regex matches packages which contain the word peach in them
|
||||
// and has two match groups
|
||||
// 1. the first match group gets the package name
|
||||
// 2. the second match group gets the version number of the package
|
||||
let re: Regex = Regex::new(r"\S+\s+(\S*peach\S+)\s+(\S+).*\n").unwrap();
|
||||
|
||||
// the following iterator, iterates through the captures matched via the regex
|
||||
// and for each capture, creates a value in the hash map,
|
||||
// which maps the name of the package, to its version number
|
||||
// e.g. { "peach-probe": "1.2.0", "peach-network": "1.4.0" }
|
||||
let peach_packages: HashMap<String, String> = re
|
||||
.captures_iter(&packages)
|
||||
.filter_map(|cap| {
|
||||
let groups = (cap.get(1), cap.get(2));
|
||||
match groups {
|
||||
(Some(package), Some(version)) => {
|
||||
Some((package.as_str().to_string(), version.as_str().to_string()))
|
||||
}
|
||||
_ => None,
|
||||
// gets a list of all packages currently installed with dpkg-query
|
||||
let peach_packages: HashMap<String, String> = SERVICES
|
||||
.iter()
|
||||
.filter_map(|service| {
|
||||
let version = get_package_version_number(service);
|
||||
match version {
|
||||
Ok(v) => Some((service.to_string(), v)),
|
||||
Err(_) => None,
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
|
Loading…
Reference in New Issue