Fix manifest
This commit is contained in:
parent
2adb3006fe
commit
a347e4726d
|
@ -2381,7 +2381,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "peach-config"
|
name = "peach-config"
|
||||||
version = "0.1.21"
|
version = "0.1.22"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"env_logger 0.6.2",
|
"env_logger 0.6.2",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "peach-config"
|
name = "peach-config"
|
||||||
version = "0.1.21"
|
version = "0.1.22"
|
||||||
authors = ["Andrew Reid <gnomad@cryptolab.net>", "Max Fowler <max@mfowler.info>"]
|
authors = ["Andrew Reid <gnomad@cryptolab.net>", "Max Fowler <max@mfowler.info>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
description = "Command line tool for installing, updating and configuring PeachCloud"
|
description = "Command line tool for installing, updating and configuring PeachCloud"
|
||||||
|
|
|
@ -1,43 +1,38 @@
|
||||||
use regex::Regex;
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use snafu::ResultExt;
|
use snafu::ResultExt;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
use log::debug;
|
||||||
|
|
||||||
use crate::constants::HARDWARE_CONFIG_FILE;
|
use crate::constants::{HARDWARE_CONFIG_FILE, SERVICES};
|
||||||
use crate::error::{FileReadError, FileWriteError, PeachConfigError};
|
use crate::error::{FileReadError, FileWriteError, PeachConfigError};
|
||||||
use crate::utils::get_output;
|
use crate::utils::get_output;
|
||||||
use crate::RtcOption;
|
use crate::RtcOption;
|
||||||
|
|
||||||
|
|
||||||
|
pub fn get_package_version_number(package: &str) -> Result<String, PeachConfigError> {
|
||||||
|
let version = get_output(&["dpkg-query", "--showformat='${Version}'", "--show", package])?;
|
||||||
|
debug!("version: {:?}", version);
|
||||||
|
Ok(version)
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns a HashMap<String, String> of all the peach-packages which are currently installed
|
/// 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" }
|
/// 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>
|
pub fn get_currently_installed_microservices() -> Result<HashMap<String, String>, PeachConfigError>
|
||||||
{
|
{
|
||||||
// gets a list of all packages currently installed with dpkg
|
// gets a list of all packages currently installed with dpkg-query
|
||||||
let packages = get_output(&["dpkg", "-l"])?;
|
let peach_packages_option_vec: Vec<Option<(String, String)>> = SERVICES.iter().map(|service| {
|
||||||
|
let version = get_package_version_number(service);
|
||||||
// this regex matches packages which contain the word peach in them
|
match version {
|
||||||
// and has two match groups
|
Ok(v) => {
|
||||||
// 1. the first match group gets the package name
|
Some((service.to_string(), v.to_string()))
|
||||||
// 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,
|
Err(_) => {
|
||||||
|
None
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
.collect();
|
}).collect();
|
||||||
|
let peach_packages: HashMap<String, String> = peach_packages_option_vec.into_iter().flat_map(|e| e).collect();
|
||||||
|
|
||||||
// finally the hashmap of packages and version numbers is returned
|
// finally the hashmap of packages and version numbers is returned
|
||||||
Ok(peach_packages)
|
Ok(peach_packages)
|
||||||
|
|
Loading…
Reference in New Issue